@Override public void saveProject(Project project) { getNamedParameterJdbcTemplate().update( "UPDATE PROJECTS SET NAME = :name, DESCRIPTION = :description, DISABLED = :disabled WHERE ID = :id", params("name", project.getName()) .addValue("description", project.getDescription()) .addValue("disabled", project.isDisabled()) .addValue("id", project.getId().getValue()) ); }
protected Project toProject(ResultSet rs) throws SQLException { return Project.of(new NameDescription( rs.getString("name"), rs.getString("description") )) .withId(id(rs.getInt("id"))) .withSignature(readSignature(rs)) .withDisabled(rs.getBoolean("disabled")); }
@Override public boolean isProjectFavourite(Project project) { return securityService.isProjectFunctionGranted(project, ProjectView.class) && securityService.getAccount().filter(account -> account.getId().isSet()) .map(account -> repository.isProjectFavourite( account.id(), project.id() )).orElse(false); }
public Project update(NameDescriptionState form) { return of(form).withId(id).withDisabled(form.isDisabled()); }
@Override public String getEntityDisplayName() { return String.format("Branch %s/%s", project.getName(), name); }
/** * Returns the ID of the project that contains this entity. This method won't return <code>null</code> * but the ID could be {@linkplain ID#NONE undefined}. */ @JsonIgnore default ID getProjectId() { return getProject().getId(); }
@Override public Project newProject(Project project) { // Creation try { int id = dbCreate( "INSERT INTO PROJECTS(NAME, DESCRIPTION, DISABLED, CREATION, CREATOR) VALUES (:name, :description, :disabled, :creation, :creator)", params("name", project.getName()) .addValue("description", project.getDescription()) .addValue("disabled", project.isDisabled()) .addValue("creation", dateTimeForDB(project.getSignature().getTime())) .addValue("creator", project.getSignature().getUser().getName()) ); // Returns with ID return project.withId(id(id)); } catch (DuplicateKeyException ex) { throw new ProjectNameAlreadyDefinedException(project.getName()); } }
@Override public Project cloneProject(Project sourceProject, ProjectCloneRequest request) { // Replacement function Function<String, String> replacementFn = replacementFn(request.getReplacements()); // Description of the target project String targetProjectDescription = replacementFn.apply(sourceProject.getDescription()); // Creates the project Project targetProject = structureService.newProject( Project.of( NameDescription.nd(request.getName(), targetProjectDescription) ) ); // Copies the properties for the project doCopyProperties(sourceProject, targetProject, replacementFn, SyncPolicy.COPY); // Creates a copy of the branch Branch sourceBranch = structureService.getBranch(request.getSourceBranchId()); String targetBranchName = replacementFn.apply(sourceBranch.getName()); String targetBranchDescription = replacementFn.apply(sourceBranch.getDescription()); Branch targetBranch = structureService.newBranch( Branch.of( targetProject, NameDescription.nd(targetBranchName, targetBranchDescription) ) ); // Configuration of the new branch doCopy(sourceBranch, targetBranch, replacementFn, SyncPolicy.COPY); // OK return targetProject; }
protected Project doCreateProject(NameDescription nameDescription) throws Exception { return asUser().with(ProjectCreation.class).call(() -> structureService.newProject( Project.of(nameDescription) )); }
@Override public boolean isDisabled() { return branch.isDisabled() || branch.getProject().isDisabled(); }
@NotNull @Override @JsonIgnore public Map<String, String> getRunMetricTags() { return ImmutableMap.of( "project", branch.getProject().getName(), "branch", branch.getName() ); }
/** * Gets the list of all branches, for all projects, which are properly configured for SVN. */ protected Stream<Branch> getSVNConfiguredBranches() { return structureService.getProjectList() .stream() // ...which have a SVN configuration .filter(project -> propertyService.hasProperty(project, SVNProjectConfigurationPropertyType.class)) // ...gets all their branches .flatMap(project -> structureService.getBranchesForProject(project.getId()).stream()) // ...which have a SVN configuration .filter(branch -> propertyService.hasProperty(branch, SVNBranchConfigurationPropertyType.class)); } }
@Override public String getDescription() { return format( "Template sync. from %s/%s", branch.getProject().getName(), branch.getName() ); }
@Override public Stream<JobRegistration> collectJobRegistrations() { if (artifactoryConfProperties.isBuildSyncDisabled()) { return Stream.empty(); } else { return securityService.asAdmin(() -> // For all projects... structureService.getProjectList().stream() // ... and their branches .flatMap(project -> structureService.getBranchesForProject(project.getId()).stream()) // ... only if not a template .filter(branch -> branch.getType() != BranchType.TEMPLATE_DEFINITION) // ... gets those with the sync. property .filter(branch -> propertyService.hasProperty(branch, ArtifactoryPromotionSyncPropertyType.class)) // ... creates the job .map(this::scheduleArtifactoryBuildSync) ); } }
@Override public void setProjectFavourite(Project project, boolean favourite) { if (securityService.isProjectFunctionGranted(project, ProjectView.class)) { securityService.getAccount().ifPresent(account -> repository.setProjectFavourite(account.id(), project.id(), favourite) ); } } }
@Override public String getDescription() { return String.format( "Synchronisation of builds with SVN for branch %s/%s", branch.getProject().getName(), branch.getName() ); }
@Override public void forEachConfiguredBranch( Predicate<SVNProjectConfigurationProperty> projectConfigurationPredicate, BiConsumer<Branch, SVNBranchConfigurationProperty> branchConsumer) { // Loops over all authorised branches for (Project project : structureService.getProjectList()) { // Filter on SVN configuration: must be present and equal to the one the revision info is looked into Property<SVNProjectConfigurationProperty> projectSvnConfig = propertyService.getProperty(project, SVNProjectConfigurationPropertyType.class); if (!projectSvnConfig.isEmpty() && projectConfigurationPredicate.test(projectSvnConfig.getValue())) { structureService.getBranchesForProject(project.getId()).stream() .filter(branch -> propertyService.hasProperty(branch, SVNBranchConfigurationPropertyType.class)) .forEach(branch -> { // Branch configuration SVNBranchConfigurationProperty branchConfiguration = propertyService.getProperty(branch, SVNBranchConfigurationPropertyType.class).getValue(); // OK branchConsumer.accept(branch, branchConfiguration); }); } } }
@Override public Collection<LoadedBranchTemplateDefinition> getTemplateDefinitions(Project project) { return branchTemplateRepository.getTemplateDefinitions().stream() .map(btd -> new LoadedBranchTemplateDefinition( structureService.getBranch(btd.getBranchId()), btd.getTemplateDefinition() )) .filter(lbtd -> (lbtd.getBranch().projectId() == project.id())) .collect(Collectors.toList()); }
@Override public String getEntityDisplayName() { return String.format("Promotion level %s/%s/%s", branch.getProject().getName(), branch.getName(), name); }