JdbcProjectImpl implements ProjectLoader { @Override public void updatePermission(final Project project, final String name, final Permission perm, final boolean isGroup) throws ProjectManagerException { final long updateTime = System.currentTimeMillis(); try { if (this.dbOperator.getDataSource().allowsOnDuplicateKey()) { final String INSERT_PROJECT_PERMISSION = "INSERT INTO project_permissions (project_id, modified_time, name, permissions, isGroup) values (?,?,?,?,?)" + "ON DUPLICATE KEY UPDATE modified_time = VALUES(modified_time), permissions = VALUES(permissions)"; this.dbOperator .update(INSERT_PROJECT_PERMISSION, project.getId(), updateTime, name, perm.toFlags(), isGroup); } else { final String MERGE_PROJECT_PERMISSION = "MERGE INTO project_permissions (project_id, modified_time, name, permissions, isGroup) KEY (project_id, name) values (?,?,?,?,?)"; this.dbOperator .update(MERGE_PROJECT_PERMISSION, project.getId(), updateTime, name, perm.toFlags(), isGroup); } } catch (final SQLException ex) { logger.error("Error updating project permission", ex); throw new ProjectManagerException( "Error updating project " + project.getName() + " permissions for " + name, ex); } if (isGroup) { project.setGroupPermission(name, perm); } else { project.setUserPermission(name, perm); } } @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 testUpdatePermission() throws Exception { createThreeProjects(); final Project project = this.loader.fetchProjectByName("mytestProject"); this.loader.updatePermission(project, project.getLastModifiedUser(), new Permission(Permission.Type.ADMIN), false); final Project sameProject = this.loader.fetchProjectByName("mytestProject"); Assert.assertEquals(sameProject.getUserPermissions().size(), 1); Assert.assertEquals(sameProject.getUserPermissions().get(0).getFirst(), "testUser1"); Assert.assertEquals(sameProject.getUserPermissions().get(0).getSecond().toString(), "ADMIN"); }