/** * Download a path for a branch * * @param branchId ID to download a document from */ @RequestMapping(value = "download/{branchId}") public ResponseEntity<String> download(@PathVariable ID branchId, String path) { return svnService.download(structureService.getBranch(branchId), path) .map(ResponseEntity::ok) .orElseThrow( () -> new SCMDocumentNotFoundException(path) ); }
@Override public Branch disconnectTemplateInstance(ID branchId) { // Gets the template instance and disconnects it when available getTemplateInstance(branchId).ifPresent(instance -> branchTemplateRepository.disconnectTemplateInstance(branchId)); // Reloads the branch return structureService.getBranch(branchId); }
protected Job createTemplateDefinitionSyncJob(BranchTemplateDefinition btd) { // Loading the branch Branch branch = structureService.getBranch(btd.getBranchId()); // Creating the job return new AbstractBranchJob(structureService, branch) { @Override public JobKey getKey() { return getTemplateDefinitionSyncJobKey(btd); } @Override public JobRun getTask() { return runListener -> syncTemplateDefinition(branch.getId(), runListener); } @Override public String getDescription() { return format( "Template sync. from %s/%s", branch.getProject().getName(), branch.getName() ); } @Override public boolean isValid() { return super.isValid() && getTemplateDefinition(branch.getId()).isPresent(); } }; }
@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 SVNSyncInfo getSyncInfo(ID branchId) { Branch branch = structureService.getBranch(branchId); return new SVNSyncInfo( branch, propertyService.getProperty(branch, SVNSyncPropertyType.class).getValue() ); }
protected BranchTemplateSyncResults syncTemplateDefinition(ID branchId, JobRunListener listener) { // Gets the branch Branch branch = structureService.getBranch(branchId); // Gets the rights on the project if (securityService.isProjectFunctionGranted(branch, BranchTemplateMgt.class) || securityService.isProjectFunctionGranted(branch, BranchTemplateSync.class)) { // Now, we have to "run as" admin since the permission to sync was granted // but might not be enough to create branches and such. return securityService.runAsAdmin(() -> doSyncTemplateDefinition(branchId, listener)).get(); } else { throw new AccessDeniedException("Cannot synchronise branches."); } }
@Override public Branch copy(Branch targetBranch, BranchCopyRequest request) { // Replacement function Function<String, String> replacementFn = replacementFn(request.getReplacements()); // Gets the source branch Branch sourceBranch = structureService.getBranch(request.getSourceBranchId()); // Actual copy return copy(targetBranch, sourceBranch, replacementFn, SyncPolicy.COPY); }
@Override public Collection<ExportFormat> changeLogExportFormats(ID branchId) { // Gets the branch Branch branch = structureService.getBranch(branchId); // Gets the SVN repository SVNRepository svnRepository = getSVNRepository(branch); ConfiguredIssueService configuredIssueService = svnRepository.getConfiguredIssueService(); if (configuredIssueService != null) { return configuredIssueService.getIssueServiceExtension().exportFormats( configuredIssueService.getIssueServiceConfiguration() ); } else { return Collections.emptyList(); } }
@Override public Branch createTemplateInstance(ID branchId, BranchTemplateInstanceSingleRequest request) { // Loads the branch template definition Branch branch = structureService.getBranch(branchId); // Gets the template definition TemplateDefinition templateDefinition = branchTemplateRepository.getTemplateDefinition(branchId) .orElseThrow(() -> new BranchNotTemplateDefinitionException(branchId)); // Gets the rights on the project if (securityService.isProjectFunctionGranted(branch, BranchTemplateMgt.class) || securityService.isProjectFunctionGranted(branch, BranchTemplateSync.class)) { // Now, we have to "run as" admin since the permission to sync was granted // but might not be enough to create branches and such. return securityService.runAsAdmin(() -> doCreateTemplateInstance(request, branch, templateDefinition)).get(); } else { throw new AccessDeniedException("Cannot synchronise branches."); } }
.map(id -> structureService.getBranch(id.getBranchId()).getName()) .collect(Collectors.toList());
@Override public Branch connectTemplateInstance(ID branchId, BranchTemplateInstanceConnectRequest request) { // Gets the branch Branch branch = structureService.getBranch(branchId); // Checks it is not connected yet if (branch.getType() != BranchType.CLASSIC) { throw new BranchCannotConnectToTemplateException(branch.getName()); } // Checks the rights securityService.checkProjectFunction(branch, BranchTemplateMgt.class); // Gets the template definition ID templateId = ID.of(request.getTemplateId()); TemplateDefinition templateDefinition = getTemplateDefinition(templateId) .orElseThrow(() -> new BranchNotTemplateDefinitionException(templateId)); // Loads the branch template Branch template = structureService.getBranch(templateId); // Update request BranchTemplateInstanceSingleRequest instanceSingleRequest = new BranchTemplateInstanceSingleRequest( branch.getName(), request.isManual(), request.getParameters() ); // Updates the instance updateTemplateInstance(branch.getName(), branch, template, instanceSingleRequest, templateDefinition); // OK return structureService.getBranch(branchId); }
@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()); }
protected <T> BranchTemplateSyncResults syncTemplateDefinition( ID branchId, TemplateDefinition templateDefinition, TemplateSynchronisationSource<T> templateSynchronisationSource, JobRunListener listener) { // Parsing of the configuration data T config = templateSynchronisationSource.parseConfig(templateDefinition.getSynchronisationSourceConfig().getData()); // Loads the branch Branch templateBranch = structureService.getBranch(branchId); // Logging listener.message("Getting template sync. sources from %s", templateSynchronisationSource.getName()); // Getting the list of names List<String> sourceNames = templateSynchronisationSource.getBranchNames(templateBranch, config); // Sync on those names return syncTemplateDefinition(templateBranch, templateDefinition, sourceNames, listener); }
@Override public Ack syncInstance(ID branchId) { Branch instance = structureService.getBranch(branchId); if (securityService.isProjectFunctionGranted(instance, BranchTemplateMgt.class) || securityService.isProjectFunctionGranted(instance, BranchTemplateSync.class)) { ); Branch template = structureService.getBranch(templateInstance.getTemplateDefinitionId());
@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; }
branchName, sourceName, structureService.getBranch(existingTemplateInstance.get().getTemplateDefinitionId()).getName() ); } else {
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 SVNSyncInfoStatus launchSync(ID branchId) { Branch branch = structureService.getBranch(branchId);