@Override public Branch cloneBranch(Branch sourceBranch, BranchCloneRequest request) { // Replacement function Function<String, String> replacementFn = replacementFn(request.getReplacements()); // Description of the target branch String targetDescription = replacementFn.apply(sourceBranch.getDescription()); // Creates the branch Branch targetBranch = structureService.newBranch( Branch.of( sourceBranch.getProject(), NameDescription.nd(request.getName(), targetDescription) ) ); // Copies the configuration doCopy(sourceBranch, targetBranch, replacementFn, SyncPolicy.COPY); // OK return targetBranch; }
@Override public Branch update(Branch branch, BranchBulkUpdateRequest request) { // Replacement function Function<String, String> replacementFn = replacementFn(request.getReplacements()); // Description update Branch updatedBranch = branch.withDescription( replacementFn.apply(branch.getDescription()) ); structureService.saveBranch(updatedBranch); // Updating doCopy(branch, updatedBranch, replacementFn, new SyncPolicy( SyncPolicy.TargetPresentPolicy.REPLACE, SyncPolicy.UnknownTargetPolicy.IGNORE )); // Reloads the branch return structureService.getBranch(branch.getId()); }
@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; }
@Override public void saveBranch(Branch branch) { // Update try { getNamedParameterJdbcTemplate().update( "UPDATE BRANCHES SET NAME = :name, DESCRIPTION = :description, DISABLED = :disabled WHERE ID = :id", params("name", branch.getName()) .addValue("description", branch.getDescription()) .addValue("disabled", branch.isDisabled()) .addValue("id", branch.id()) ); } catch (DuplicateKeyException ex) { throw new BranchNameAlreadyDefinedException(branch.getName()); } }
protected Branch updateTemplateInstance(Branch instance, Branch template, TemplateInstanceExecution templateInstanceExecution) { // Description of the branch String description = templateInstanceExecution.replace(template.getDescription()); instance = instance.withDescription(description); structureService.saveBranch(instance); // Copy replacement function copyService.copy( instance, // Target template, // Source templateInstanceExecution.getReplacementFn(), SyncPolicy.SYNC_KEEP // Conservative approach ); // Template instance TemplateInstance templateInstance = new TemplateInstance( template.getId(), templateInstanceExecution.asTemplateParameterValues() ); // Branch as a branch template instance branchTemplateRepository.setTemplateInstance(instance.getId(), templateInstance); // OK - reloads to gets the correct type return structureService.getBranch(instance.getId()); }
@Override public Branch newBranch(Branch branch) { // Creation try { int id = dbCreate( "INSERT INTO BRANCHES(PROJECTID, NAME, DESCRIPTION, DISABLED, CREATION, CREATOR) VALUES (:projectId, :name, :description, :disabled, :creation, :creator)", params("name", branch.getName()) .addValue("description", branch.getDescription()) .addValue("disabled", branch.isDisabled()) .addValue("projectId", branch.getProject().id()) .addValue("creation", dateTimeForDB(branch.getSignature().getTime())) .addValue("creator", branch.getSignature().getUser().getName()) ); // Returns with ID return branch.withId(id(id)); } catch (DuplicateKeyException ex) { throw new BranchNameAlreadyDefinedException(branch.getName()); } }