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);
}
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";
}
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());
}
}
}
Aggregations