Search in sources :

Example 1 with ModuleUninstall

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);
}
Also used : ModuleUninstall(org.meveo.service.admin.impl.ModuleUninstall) MeveoModuleItem(org.meveo.model.module.MeveoModuleItem) MeveoModuleItemDto(org.meveo.api.dto.module.MeveoModuleItemDto) MeveoModule(org.meveo.model.module.MeveoModule) FileUtils.addToZipFile(org.meveo.commons.utils.FileUtils.addToZipFile) File(java.io.File) DiffEntry(org.eclipse.jgit.diff.DiffEntry) TransactionAttribute(javax.ejb.TransactionAttribute)

Aggregations

File (java.io.File)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 DiffEntry (org.eclipse.jgit.diff.DiffEntry)1 MeveoModuleItemDto (org.meveo.api.dto.module.MeveoModuleItemDto)1 FileUtils.addToZipFile (org.meveo.commons.utils.FileUtils.addToZipFile)1 MeveoModule (org.meveo.model.module.MeveoModule)1 MeveoModuleItem (org.meveo.model.module.MeveoModuleItem)1 ModuleUninstall (org.meveo.service.admin.impl.ModuleUninstall)1