JdbcProjectImpl implements ProjectLoader { @Override public synchronized Project createNewProject(final String name, final String description, final User creator) throws ProjectManagerException { final ProjectResultHandler handler = new ProjectResultHandler(); try { final List<Project> projects = this.dbOperator .query(ProjectResultHandler.SELECT_ACTIVE_PROJECT_BY_NAME, handler, name); if (!projects.isEmpty()) { throw new ProjectManagerException( "Active project with name " + name + " already exists in db."); } } catch (final SQLException ex) { logger.error(ex); throw new ProjectManagerException("Checking for existing project failed. " + name, ex); } final String INSERT_PROJECT = "INSERT INTO projects ( name, active, modified_time, create_time, version, last_modified_by, description, enc_type, settings_blob) values (?,?,?,?,?,?,?,?,?)"; final SQLTransaction<Integer> insertProject = transOperator -> { final long time = System.currentTimeMillis(); return transOperator .update(INSERT_PROJECT, name, true, time, time, null, creator.getUserId(), description, this.defaultEncodingType.getNumVal(), null); }; try { final int numRowsInserted = this.dbOperator.transaction(insertProject); if (numRowsInserted == 0) { throw new ProjectManagerException("No projects have been inserted."); } } catch (final SQLException ex) { logger.error(INSERT_PROJECT + " failed.", ex); throw new ProjectManagerException("Insert project" + name + " for existing project failed. ", ex); } return fetchProjectByName(name); } @Inject  JdbcProjectImpl(final Props props, final DatabaseOperator databaseOperator); @Override List<Project> fetchAllActiveProjects(); @Override Project fetchProjectById(final int id); @Override Project fetchProjectByName(final String name); @Override synchronized Project createNewProject(final String name, final String description,
      final User creator); @Override void uploadProjectFile(final int projectId, final int version, final File localFile,
      final String uploader, final String uploaderIPAddr); @Override void addProjectVersion(final int projectId, final int version, final File localFile,
      final File startupDependencies, final String uploader, final byte[] md5,
      final String resourceId, final String uploaderIPAddr); @Override ProjectFileHandler fetchProjectMetaData(final int projectId, final int version); @Override ProjectFileHandler getUploadedFile(final int projectId, final int version); @Override void changeProjectVersion(final Project project, final int version, final String user); @Override void updatePermission(final Project project, final String name, final Permission perm,
      final boolean isGroup); @Override void updateProjectSettings(final Project project); @Override void removePermission(final Project project, final String name, final boolean isGroup); @Override void removeProject(final Project project, final String user); @Override boolean postEvent(final Project project, final EventType type, final String user,
      final String message); @Override List<ProjectLogEvent> getProjectEvents(final Project project, final int num,
      final int skip); @Override void updateDescription(final Project project, final String description, final String user); @Override int getLatestProjectVersion(final Project project); @Override void uploadFlows(final Project project, final int version, final Collection<Flow> flows); @Override void uploadFlow(final Project project, final int version, final Flow flow); @Override void updateFlow(final Project project, final int version, final Flow flow); @Override Flow fetchFlow(final Project project, final String flowId); @Override List<Flow> fetchAllProjectFlows(final Project project); @Override Map<Project, List<Flow>> fetchAllFlowsForProjects(final List<Project> projects); @Override void uploadProjectProperties(final Project project, final List<Props> properties); @Override void uploadProjectProperty(final Project project, final Props props); @Override void updateProjectProperty(final Project project, final Props props); @Override Props fetchProjectProperty(final int projectId, final int projectVer,
      final String propsName); @Override Props fetchProjectProperty(final Project project, final String propsName); @Override Map<String, Props> fetchProjectProperties(final int projectId, final int version); @Override void cleanOlderProjectVersion(final int projectId, final int version,
      final List<Integer> excludedVersions); @Override void uploadFlowFile(final int projectId, final int projectVersion, final File flowFile,
      final int flowVersion); @Override File getUploadedFlowFile(final int projectId, final int projectVersion,
      final String flowFileName, final int flowVersion, final File tempDir); @Override int getLatestFlowVersion(final int projectId, final int projectVersion,
      final String flowName); @Override boolean isFlowFileUploaded(final int projectId, final int projectVersion); @Override List<Project> fetchProjectById(final List<Integer> ids);  }
@Test public void testCreateProject() throws Exception { final String projectName = "mytestProject"; final String projectDescription = "This is my new project"; final User user = new User("testUser1"); final Project project = this.loader.createNewProject(projectName, projectDescription, user); Assert.assertEquals(project.getName(), projectName); Assert.assertEquals(project.getDescription(), projectDescription); Assert.assertEquals(project.getLastModifiedUser(), "testUser1"); }
@Test public void testCreateProjectsWithDifferentCases() { final String projectName = "mytestproject"; final String projectDescription = "This is my new project with lower cases."; final User user = new User("testUser1"); this.loader.createNewProject(projectName, projectDescription, user); final String projectName2 = "MYTESTPROJECT"; final String projectDescription2 = "This is my new project with UPPER CASES."; assertThatThrownBy( () -> this.loader.createNewProject(projectName2, projectDescription2, user)) .isInstanceOf(ProjectManagerException.class) .hasMessageContaining( "Active project with name " + projectName2 + " already exists in db."); }