Search in sources :

Example 1 with EntityAlreadyExistsException

use of org.meveo.exceptions.EntityAlreadyExistsException in project meveo by meveo-org.

the class WorkflowService method create.

@Override
public void create(Workflow entity) throws BusinessException {
    Workflow workflow = findByCetCodeAndWFType(entity.getCetCode(), entity.getWfType());
    if (workflow != null) {
        throw new EntityAlreadyExistsException("Custom entity and workflow type already exists");
    }
    super.create(entity);
}
Also used : EntityAlreadyExistsException(org.meveo.exceptions.EntityAlreadyExistsException) Workflow(org.meveo.model.wf.Workflow)

Example 2 with EntityAlreadyExistsException

use of org.meveo.exceptions.EntityAlreadyExistsException in project meveo by meveo-org.

the class WorkflowBean method saveOrUpdate.

@Override
@ActionMethod
public String saveOrUpdate(boolean killConversation) throws BusinessException, ELException {
    if ((oldCetCode != null && !entity.getCetCode().equals(oldCetCode)) || (oldWFType != null && !entity.getWfType().equals(oldWFType))) {
        Workflow workflow = workflowService.findByCetCodeAndWFType(entity.getCetCode(), entity.getWfType());
        if (workflow != null) {
            messages.error(new BundleKey("messages", "workflow.uniqueField.error"));
            return null;
        }
        List<WFTransition> wfTransitions = entity.getTransitions();
        if (CollectionUtils.isNotEmpty(wfTransitions)) {
            for (WFTransition wfTransition : wfTransitions) {
                if (wfTransition != null) {
                    wfTransition = wFTransitionService.findById(wfTransition.getId(), Arrays.asList("wfDecisionRules", "wfActions"));
                    if (CollectionUtils.isNotEmpty(wfTransition.getWfActions())) {
                        for (WFAction wfAction : wfTransition.getWfActions()) {
                            wfActionService.remove(wfAction);
                        }
                    }
                }
            }
            for (WFTransition wfTransition : wfTransitions) {
                wFTransitionService.remove(wfTransition);
            }
        }
        entity.setTransitions(new ArrayList<>());
    }
    try {
        String message = entity.isTransient() ? "save.successful" : "update.successful";
        saveOrUpdate(entity);
        messages.info(new BundleKey("messages", message));
        if (killConversation) {
            endConversation();
        }
    } catch (EntityAlreadyExistsException e) {
        messages.error(new BundleKey("messages", "workflow.uniqueField.error"));
        return null;
    }
    return "workflowDetail";
}
Also used : WFTransition(org.meveo.model.wf.WFTransition) EntityAlreadyExistsException(org.meveo.exceptions.EntityAlreadyExistsException) Workflow(org.meveo.model.wf.Workflow) WFAction(org.meveo.model.wf.WFAction) BundleKey(org.jboss.seam.international.status.builder.BundleKey) ActionMethod(org.meveo.admin.web.interceptor.ActionMethod)

Example 3 with EntityAlreadyExistsException

use of org.meveo.exceptions.EntityAlreadyExistsException in project meveo by meveo-org.

the class GitClient method create.

/**
 * Create and initiate the git repository in the file system
 *
 * @param gitRepository Repository to create
 * @param failIfExist   Whether to fail if directory already exists
 * @param username      Optional - Username to connect remote repository if any
 * @param password      Optional - Password to connect remote repository if any
 * @throws BusinessException          if repository cannot be cloned or initiated
 * @throws UserNotAuthorizedException if user does not have write access to the repository
 */
public void create(GitRepository gitRepository, boolean failIfExist, String username, String password) throws BusinessException {
    MeveoUser user = currentUser.get();
    final File repoDir = GitHelper.getRepositoryDir(user, gitRepository.getCode());
    if (repoDir.exists() && failIfExist) {
        throw new EntityAlreadyExistsException(GitRepository.class, gitRepository.getCode());
    } else if (repoDir.exists() && new File(repoDir, ".git").exists()) {
        return;
    }
    repoDir.mkdirs();
    if (gitRepository.isRemote()) {
        keyLock.lock(gitRepository.getCode());
        try {
            final CloneCommand cloneCommand = Git.cloneRepository().setURI(gitRepository.getRemoteOrigin()).setDirectory(repoDir);
            if (gitRepository.getDefaultBranch() != null)
                cloneCommand.setBranch(gitRepository.getDefaultBranch());
            cloneCommand.setCloneSubmodules(true);
            if (gitRepository.getRemoteOrigin().startsWith("http")) {
                CredentialsProvider usernamePasswordCredentialsProvider = GitHelper.getCredentialsProvider(gitRepository, username, password, user);
                cloneCommand.setCredentialsProvider(usernamePasswordCredentialsProvider).call().close();
            } else {
                SshTransportConfigCallback sshTransportConfigCallback = new SshTransportConfigCallback(user.getSshPrivateKey(), user.getSshPublicKey(), password);
                cloneCommand.setTransportConfigCallback(sshTransportConfigCallback).call().close();
            }
        } catch (GitAPIException e) {
            repoDir.delete();
            throw new BusinessException("Error cloning repository " + gitRepository.getRemoteOrigin(), e);
        } finally {
            keyLock.unlock(gitRepository.getCode());
        }
    } else {
        keyLock.lock(gitRepository.getCode());
        try (Git git = Git.init().setDirectory(repoDir).call()) {
            // Init repo with a dummy commit
            new File(repoDir, "README.md").createNewFile();
            git.add().addFilepattern(".").call();
            git.commit().setMessage("First commit").setAuthor(user.getUserName(), user.getMail()).setCommitter(user.getUserName(), user.getMail()).call();
        } catch (GitAPIException | IOException e) {
            repoDir.delete();
            throw new BusinessException("Error initating repository " + gitRepository.getCode(), e);
        } finally {
            keyLock.unlock(gitRepository.getCode());
        }
    }
}
Also used : CloneCommand(org.eclipse.jgit.api.CloneCommand) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) BusinessException(org.meveo.admin.exception.BusinessException) Git(org.eclipse.jgit.api.Git) EntityAlreadyExistsException(org.meveo.exceptions.EntityAlreadyExistsException) MeveoUser(org.meveo.security.MeveoUser) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) IOException(java.io.IOException) File(java.io.File)

Aggregations

EntityAlreadyExistsException (org.meveo.exceptions.EntityAlreadyExistsException)3 Workflow (org.meveo.model.wf.Workflow)2 File (java.io.File)1 IOException (java.io.IOException)1 CloneCommand (org.eclipse.jgit.api.CloneCommand)1 Git (org.eclipse.jgit.api.Git)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)1 BundleKey (org.jboss.seam.international.status.builder.BundleKey)1 BusinessException (org.meveo.admin.exception.BusinessException)1 ActionMethod (org.meveo.admin.web.interceptor.ActionMethod)1 WFAction (org.meveo.model.wf.WFAction)1 WFTransition (org.meveo.model.wf.WFTransition)1 MeveoUser (org.meveo.security.MeveoUser)1