@Override public List<Decoration<BranchType>> getDecorations(ProjectEntity entity) { if (entity instanceof Branch) { Branch branch = (Branch) entity; switch (branch.getType()) { case TEMPLATE_DEFINITION: case TEMPLATE_INSTANCE: return Collections.singletonList( Decoration.of( this, branch.getType() ) ); default: // No decoration by default return Collections.emptyList(); } } else { return Collections.emptyList(); } }
@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 List<Decoration<JenkinsJob>> getDecorations(ProjectEntity entity) { // Gets the Jenkins Job property for this entity, if any Property<JenkinsJobProperty> property = propertyService.getProperty(entity, JenkinsJobPropertyType.class.getName()); if (property.isEmpty()) { return Collections.emptyList(); } else { // Template branch? Decoration cannot be computed if (entity instanceof Branch && ((Branch) entity).getType() == BranchType.TEMPLATE_DEFINITION) { return Collections.emptyList(); } // Gets a client // FIXME getJob does not need a full HTTP client JenkinsClient jenkinsClient = jenkinsClientFactory.getClient(property.getValue().getConfiguration()); // Gets the Jenkins job JenkinsJob job = jenkinsClient.getJob(property.getValue().getJob()); // Gets the decoration for the job return Collections.singletonList( getDecoration(job) ); } }
else if (existingBranch.get().getType() == BranchType.CLASSIC) { throw new BranchClassicCannotBeTemplateInstanceException(branchName); else if (existingBranch.get().getType() == BranchType.TEMPLATE_DEFINITION) { throw new BranchTemplateDefinitionCannotBeTemplateInstanceException(branchName); } else {
if (branch.getType() != BranchType.TEMPLATE_DEFINITION && propertyService.hasProperty(branch, SVNBranchConfigurationPropertyType.class)) {
if (branch.getType() == BranchType.TEMPLATE_INSTANCE) { throw new BranchTemplateInstanceException(branch.getName());
@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); }