use of org.meveo.service.admin.impl.ModuleUninstall in project meveo by meveo-org.
the class MeveoModuleApi method updateModuleOnCommitReceived.
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateModuleOnCommitReceived(@Observes @CommitReceived CommitEvent event) throws IllegalArgumentException, MeveoApiException, BusinessException, Exception {
// Make sure the git repo is linked to a module
MeveoModule module = this.meveoModuleService.findByCode(event.getGitRepository().getCode());
if (module == null) {
return;
}
File directory = GitHelper.getRepositoryDir(null, module.getCode());
MeveoModuleItemDto itemDto;
MeveoModuleItem item;
ModuleUninstall options = ModuleUninstall.builder().module(module).removeData(true).removeItems(true).removeFiles(true).build();
for (DiffEntry diff : event.getDiffs()) {
switch(diff.getChangeType()) {
case ADD:
itemDto = getItemDtoFromFile(directory, diff.getNewPath());
if (itemDto != null) {
meveoModuleItemInstaller.unpackAndInstallModuleItem(module, itemDto, OnDuplicate.FAIL);
}
break;
case COPY:
// NOOP
break;
case DELETE:
item = getExistingItemFromFile(directory, diff.getOldPath());
if (item != null) {
module.removeItem(item);
meveoModuleItemInstaller.uninstallItem(options, null, item);
}
break;
case MODIFY:
itemDto = getItemDtoFromFile(directory, diff.getNewPath());
if (itemDto != null) {
meveoModuleItemInstaller.unpackAndInstallModuleItem(module, itemDto, OnDuplicate.OVERWRITE);
}
break;
case RENAME:
// Remove
item = getExistingItemFromFile(directory, diff.getOldPath());
if (item != null) {
module.removeItem(item);
meveoModuleItemInstaller.uninstallItem(options, null, item);
}
// Add
itemDto = getItemDtoFromFile(directory, diff.getNewPath());
if (itemDto != null) {
meveoModuleItemInstaller.unpackAndInstallModuleItem(module, itemDto, OnDuplicate.FAIL);
}
break;
default:
break;
}
}
meveoModuleService.update(module);
}
Aggregations