private Decoration<JenkinsJob> getDecoration(JenkinsJob job) { return Decoration.of(this, job); }
/** * Basic construction. Only the data is required */ public static <T> Decoration<T> of(Decorator<T> decorator, T data) { Validate.notNull(decorator, "The decorator is required"); Validate.notNull(data, "The decoration data is required"); return new Decoration<>(decorator, data, null); }
/** * Gets the decoration for an entity, and returns an "error" decoration in case of problem. */ protected <T> List<? extends Decoration> getDecorations(ProjectEntity entity, Decorator<T> decorator) { try { return decorator.getDecorations(entity); } catch (Exception ex) { return Collections.singletonList( Decoration.error(decorator, getErrorMessage(ex)) ); } }
private DataFetcher projectEntityDecorationsDataFetcher(Class<? extends ProjectEntity> projectEntityClass) { return environment -> { Object o = environment.getSource(); if (projectEntityClass.isInstance(o)) { // Filters Optional<String> typeFilter = GraphqlUtils.getStringArgument(environment, "type"); // Gets the raw list return decorationService.getDecorations((ProjectEntity) o).stream() // Filter by type .filter(property -> typeFilter .map(typeFilterName -> StringUtils.equals( typeFilterName, property.getDecorationType() )) .orElse(true) ) // OK .collect(Collectors.toList()); } else { return null; } }; } }
@Override public List<Decoration<Boolean>> getDecorations(ProjectEntity entity) { return propertyService.getProperty(entity, AutoPromotionPropertyType.class).option() .map(autoPromotionProperty -> Collections.singletonList(Decoration.of(this, Boolean.TRUE))) .orElse(Collections.emptyList()); } }
/** * Basic construction. With an error */ public static <T> Decoration<T> error(Decorator<T> decorator, String error) { Validate.notNull(decorator, "The decorator is required"); Validate.notBlank(error, "The decoration error is required"); return new Decoration<>(decorator, null, error); }
@Override public List<Decoration<MessageProperty>> getDecorations(ProjectEntity entity) { // Gets the `message` property return propertyService.getProperty(entity, MessagePropertyType.class) .option() .map( messageProperty -> Collections.singletonList( Decoration.of( this, messageProperty ) ) ) .orElse(Collections.<Decoration<MessageProperty>>emptyList()); }
@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 List<Decoration<Long>> getDecorations(ProjectEntity entity) { if (entity instanceof Build) { // Gets the revision for this build OptionalLong revision = svnChangeLogService.getBuildRevision((Build) entity); if (revision.isPresent()) { // If the revision == build name, no need for decoration if (StringUtils.equals( String.valueOf(revision.getAsLong()), ((Build) entity).getName() )) { return Collections.emptyList(); } else { long lRevision = revision.getAsLong(); return Collections.singletonList( Decoration.of( this, lRevision ) ); } } else { return Collections.emptyList(); } } else { throw new IllegalArgumentException("Expecting build"); } }
@Override public List<Decoration<String>> getDecorations(ProjectEntity entity) { // Argument check Validate.isTrue(entity instanceof Build, "Expecting build"); // Gets the `release` property Property<ReleaseProperty> property = propertyService.getProperty(entity, ReleasePropertyType.class); if (property.isEmpty()) { return Collections.emptyList(); } else { return Collections.singletonList( Decoration.of( this, property.getValue().getName() ) ); } }
@Override public List<Decoration<String>> getDecorations(ProjectEntity entity) { Property<SVNProjectConfigurationProperty> property = propertyService.getProperty(entity, SVNProjectConfigurationPropertyType.class); if (!property.isEmpty()) { return Collections.singletonList( Decoration.of( this, property.getValue().getUrl() ) ); } else { return Collections.emptyList(); } }
@Override public List<Decoration<TestDecorationData>> getDecorations(ProjectEntity entity) { return propertyService.getProperty(entity, TestDecoratorPropertyType.class) .option() .map(data -> Collections.singletonList( Decoration.of( TestDecorator.this, data ) )) .orElse(Collections.emptyList()); }
@Override public List<Decoration<String>> getDecorations(ProjectEntity entity) { Property<GitHubProjectConfigurationProperty> property = propertyService.getProperty(entity, GitHubProjectConfigurationPropertyType.class); if (!property.isEmpty()) { return Collections.singletonList( Decoration.of( this, String.format( "%s @ %s", property.getValue().getRepository(), property.getValue().getConfiguration().getName() ) ) ); } else { return Collections.emptyList(); } }
@Override public List<Decoration<String>> getDecorations(ProjectEntity entity) { Property<GitLabProjectConfigurationProperty> property = propertyService.getProperty(entity, GitLabProjectConfigurationPropertyType.class); if (!property.isEmpty()) { return Collections.singletonList( Decoration.of( this, String.format( "%s @ %s", property.getValue().getRepository(), property.getValue().getConfiguration().getName() ) ) ); } else { return Collections.emptyList(); } }
return Collections.singletonList(Decoration.of(this, decoration));
@Override public List<Decoration<String>> getDecorations(ProjectEntity entity) { Property<StashProjectConfigurationProperty> property = propertyService.getProperty(entity, StashProjectConfigurationPropertyType.class); if (!property.isEmpty()) { return Collections.singletonList( Decoration.of( this, String.format( "%s/%s @ %s", property.getValue().getProject(), property.getValue().getRepository(), property.getValue().getConfiguration().getName() ) ) ); } else { return Collections.emptyList(); } }