private void notifyHandlersOfProjectCreated(ApplicationUser user, Project newProject, CreateProjectValidationResult result) { final ProjectCreatedData.Builder projectCreatedData = new ProjectCreatedData.Builder().withProject(newProject); Optional.ofNullable(result.getProjectCreationData().getProjectTemplateKey()).ifPresent(projectCreatedData::withProjectTemplateKey); result.getExistingProjectId().ifPresent(projectCreatedData::withExistingProjectId); boolean notificationWasSuccessful = projectCreateNotifier.notifyAllHandlers(projectCreatedData.build()); if (!notificationWasSuccessful) { deleteProject(user, new DeleteProjectValidationResult(ErrorCollections.empty(), newProject)); throw new RuntimeException("An error occurred while notifying that a project was created"); } }
@Override public DeleteProjectValidationResult validateDeleteProject(ApplicationUser user, String key) { final I18nHelper i18nBean = getI18nBean(user); if (!globalPermissionManager.hasPermission(GlobalPermissionKey.ADMINISTER, user)) { return new DeleteProjectValidationResult(ErrorCollections.create(i18nBean.getText("admin.projects.service.error.no.admin.permission"), Reason.FORBIDDEN)); } //check if the project exists. If not return with an error. final GetProjectResult oldProjectResult = getProjectByKeyForAction(user, key, ProjectAction.EDIT_PROJECT_CONFIG); if (!oldProjectResult.isValid() || oldProjectResult.getProject() == null) { return new DeleteProjectValidationResult(ErrorCollections.copyOf(oldProjectResult.getErrorCollection())); } return new DeleteProjectValidationResult(ErrorCollections.empty(), oldProjectResult.getProject()); }