|
| 1 | +/* |
| 2 | + * Copyright (C) 2020-2026 Linagora |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General |
| 5 | + * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) |
| 6 | + * any later version, provided you comply with the Additional Terms applicable for LinID Identity Manager software by |
| 7 | + * LINAGORA pursuant to Section 7 of the GNU Affero General Public License, subsections (b), (c), and (e), pursuant to |
| 8 | + * which these Appropriate Legal Notices must notably (i) retain the display of the "LinID™" trademark/logo at the top |
| 9 | + * of the interface window, the display of the “You are using the Open Source and free version of LinID™, powered by |
| 10 | + * Linagora © 2009–2013. Contribute to LinID R&D by subscribing to an Enterprise offer!” infobox and in the e-mails |
| 11 | + * sent with the Program, notice appended to any type of outbound messages (e.g. e-mail and meeting requests) as well |
| 12 | + * as in the LinID Identity Manager user interface, (ii) retain all hypertext links between LinID Identity Manager |
| 13 | + * and https://linid.org/, as well as between LINAGORA and LINAGORA.com, and (iii) refrain from infringing LINAGORA |
| 14 | + * intellectual property rights over its trademarks and commercial brands. Other Additional Terms apply, see |
| 15 | + * <http://www.linagora.com/licenses/> for more details. |
| 16 | + * |
| 17 | + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 18 | + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
| 19 | + * details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Affero General Public License and its applicable Additional Terms for |
| 22 | + * LinID Identity Manager along with this program. If not, see <http://www.gnu.org/licenses/> for the GNU Affero |
| 23 | + * General Public License version 3 and <http://www.linagora.com/licenses/> for the Additional Terms applicable to the |
| 24 | + * LinID Identity Manager software. |
| 25 | + */ |
| 26 | + |
| 27 | +package io.github.linagora.linid.im.dpb; |
| 28 | + |
| 29 | +import io.github.linagora.linid.im.corelib.plugin.config.dto.ProviderConfiguration; |
| 30 | +import io.github.linagora.linid.im.corelib.plugin.entity.DynamicEntity; |
| 31 | +import io.github.linagora.linid.im.corelib.plugin.provider.ProviderPlugin; |
| 32 | +import io.github.linagora.linid.im.corelib.plugin.task.TaskEngine; |
| 33 | +import io.github.linagora.linid.im.corelib.plugin.task.TaskExecutionContext; |
| 34 | +import io.github.linagora.linid.im.dpb.service.CrudService; |
| 35 | +import org.springframework.beans.factory.annotation.Autowired; |
| 36 | +import org.springframework.data.domain.Page; |
| 37 | +import org.springframework.data.domain.Pageable; |
| 38 | +import org.springframework.stereotype.Component; |
| 39 | +import org.springframework.util.MultiValueMap; |
| 40 | + |
| 41 | +/** |
| 42 | + * Database Provider Plugin implementation. |
| 43 | + */ |
| 44 | +@Component |
| 45 | +public class DatabaseProviderPlugin implements ProviderPlugin { |
| 46 | + |
| 47 | + private final CrudService crudService; |
| 48 | + private final TaskEngine taskEngine; |
| 49 | + |
| 50 | + @Autowired |
| 51 | + public DatabaseProviderPlugin(final CrudService crudService, final TaskEngine taskEngine) { |
| 52 | + this.crudService = crudService; |
| 53 | + this.taskEngine = taskEngine; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public DynamicEntity create(TaskExecutionContext context, ProviderConfiguration config, |
| 58 | + DynamicEntity dynamicEntity) { |
| 59 | + taskEngine.execute(dynamicEntity, context, "beforeCreate"); |
| 60 | + crudService.insert(config, dynamicEntity); |
| 61 | + taskEngine.execute(dynamicEntity, context, "afterCreate"); |
| 62 | + |
| 63 | + return dynamicEntity; |
| 64 | + } |
| 65 | + |
| 66 | + public boolean delete(TaskExecutionContext context, ProviderConfiguration config, String id, |
| 67 | + DynamicEntity dynamicEntity) { |
| 68 | + taskEngine.execute(dynamicEntity, context, "beforeDelete"); |
| 69 | + crudService.delete(config, id, dynamicEntity); |
| 70 | + taskEngine.execute(dynamicEntity, context, "afterDelete"); |
| 71 | + |
| 72 | + return true; |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public boolean supports(String type) { |
| 77 | + return "database".equals(type); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public DynamicEntity patch(TaskExecutionContext context, ProviderConfiguration config, String id, |
| 82 | + DynamicEntity dynamicEntity) { |
| 83 | + return dynamicEntity; |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public DynamicEntity findById(TaskExecutionContext context, ProviderConfiguration config, String id, |
| 88 | + DynamicEntity dynamicEntity) { |
| 89 | + return null; |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public Page<DynamicEntity> findAll(TaskExecutionContext context, ProviderConfiguration config, |
| 94 | + MultiValueMap<String, String> filters, Pageable pageable, DynamicEntity dynamicEntity) { |
| 95 | + |
| 96 | + taskEngine.execute(dynamicEntity, context, "beforeFindAll"); |
| 97 | + Page<DynamicEntity> result = crudService.select(config, dynamicEntity); |
| 98 | + taskEngine.execute(dynamicEntity, context, "afterFindAll"); |
| 99 | + |
| 100 | + return result; |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public DynamicEntity update(TaskExecutionContext context, ProviderConfiguration config, String id, |
| 105 | + DynamicEntity dynamicEntity) { |
| 106 | + taskEngine.execute(dynamicEntity, context, "beforeUpdate"); |
| 107 | + crudService.update(config, id, dynamicEntity); |
| 108 | + taskEngine.execute(dynamicEntity, context, "afterUpdate"); |
| 109 | + |
| 110 | + return dynamicEntity; |
| 111 | + } |
| 112 | +} |
0 commit comments