@Override public boolean canEdit(ProjectEntity entity, SecurityService securityService) { return securityService.isProjectFunctionGranted(entity.projectId(), ProjectConfig.class); }
@Override public URI getEntityURI(ProjectEntity entity) { return URI.create( format( "urn:test:entity:%s:%d", entity.getProjectEntityType().name(), entity.id() ) ); }
/** * One can edit the SVN configuration of a branch only if he can configurure a project and if the project * is itself configured with SVN. */ @Override public boolean canEdit(ProjectEntity entity, SecurityService securityService) { return securityService.isProjectFunctionGranted(entity.projectId(), ProjectConfig.class) && propertyService.hasProperty( entity.getProject(), SVNProjectConfigurationPropertyType.class); }
public EventBuilder withRef(ProjectEntity entity) { this.ref = entity.getProjectEntityType(); return withProject(entity.getProject()).with(entity); }
public EventCannotRenderEntityException(String template, ProjectEntity projectEntity) { super("Cannot render entity %s for event: %s", projectEntity.getProjectEntityType(), template); } }
protected <T> T getPropertyValue(PropertyType<T> type, ProjectEntity entity) { // Supported entity? if (!type.getSupportedEntityTypes().contains(entity.getProjectEntityType())) { throw new PropertyUnsupportedEntityTypeException(type.getClass().getName(), entity.getProjectEntityType()); } // Checks for viewing if (!type.canView(entity, securityService)) { throw new AccessDeniedException("Property is not opened for viewing."); } // Gets the raw information from the repository TProperty t = propertyRepository.loadProperty( type.getClass().getName(), entity.getProjectEntityType(), entity.getId()); // If null, returns null if (t == null) { return null; } // Converts the stored value into an actual value return type.fromStorage(t.getJson()); }
@Override public Optional<Action> getAction(ProjectEntity entity) { if (entity instanceof Branch && propertyService.hasProperty(entity, SVNBranchConfigurationPropertyType.class) && securityService.isProjectFunctionGranted(entity, BuildCreate.class)) { return Optional.of(Action.of( "svn-sync", "SVN <-> Build sync", String.format("sync/%d", entity.id()) )); } else { return Optional.empty(); } }
/** * 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(); }
List<ValidationRun> runs = structureService.getValidationRunsForValidationStamp(entity.getId(), 0, 5);
public EventBuilder with(ProjectEntity entity) { entities.put(entity.getProjectEntityType(), entity); return this; }
private <T> Ack editProperty(ProjectEntity entity, PropertyType<T> propertyType, T value) { // Checks for edition if (!propertyType.canEdit(entity, securityService)) { throw new AccessDeniedException("Property is not opened for edition."); } // Gets the JSON for the storage JsonNode storage = propertyType.forStorage(value); // Stores the property propertyRepository.saveProperty( propertyType.getClass().getName(), entity.getProjectEntityType(), entity.getId(), storage ); // Property change event eventPostService.post(eventFactory.propertyChange(entity, propertyType)); // Listener propertyType.onPropertyChanged(entity, value); // OK return Ack.OK; }
@Override public void post(Event event) { StringBuilder sql = new StringBuilder("INSERT INTO EVENTS(EVENT_VALUES, EVENT_TIME, EVENT_USER, EVENT_TYPE, REF"); MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("eventValues", writeJson(event.getValues())); params.addValue("eventTime", dateTimeForDB(event.getSignature().getTime())); params.addValue("eventUser", event.getSignature().getUser().getName()); params.addValue("eventType", event.getEventType().getId()); params.addValue("ref", event.getRef() != null ? event.getRef().name() : null); for (ProjectEntityType type : event.getEntities().keySet()) { sql.append(", ").append(type.name()); } sql.append(") VALUES (:eventValues, :eventTime, :eventUser, :eventType, :ref"); for (Map.Entry<ProjectEntityType, ProjectEntity> entry : event.getEntities().entrySet()) { ProjectEntityType type = entry.getKey(); ProjectEntity entity = entry.getValue(); String typeEntry = type.name().toLowerCase(); sql.append(", :").append(typeEntry); params.addValue(typeEntry, entity.id()); } sql.append(")"); getNamedParameterJdbcTemplate().update( sql.toString(), params ); }
default LinksBuilder link(String name, Object methodInvocation, Class<? extends ProjectFunction> fn, ProjectEntity projectEntity) { return link(name, methodInvocation, fn, projectEntity.projectId()); }
@Override public URI getEntityPage(ProjectEntity entity) { return page("entity:%s:%d", entity.getProjectEntityType().name(), entity.id()); }
/** * Depends on the nature of the entity. Allowed to the ones who can create the associated entity. */ @Override public boolean canEdit(ProjectEntity entity, SecurityService securityService) { switch (entity.getProjectEntityType()) { case BUILD: return securityService.isProjectFunctionGranted(entity, BuildCreate.class); case PROMOTION_RUN: return securityService.isProjectFunctionGranted(entity, PromotionRunCreate.class); case VALIDATION_RUN: return securityService.isProjectFunctionGranted(entity, ValidationRunCreate.class); default: throw new PropertyUnsupportedEntityTypeException(getClass().getName(), entity.getProjectEntityType()); } }
private <T> Ack deleteProperty(ProjectEntity entity, PropertyType<T> propertyType) { // Checks for edition if (!propertyType.canEdit(entity, securityService)) { throw new AccessDeniedException("Property is not opened for viewing."); } // Gets the existing value T value = getPropertyValue(propertyType, entity); // If existing, deletes it if (value != null) { Ack ack = propertyRepository.deleteProperty(propertyType.getClass().getName(), entity.getProjectEntityType(), entity.getId()); if (ack.isSuccess()) { // Property deletion event eventPostService.post(eventFactory.propertyDelete(entity, propertyType)); // Listener propertyType.onPropertyDeleted(entity, value); } // OK return ack; } else { return Ack.NOK; } }
@Override public boolean canView(ProjectEntity entity, SecurityService securityService) { return securityService.isProjectFunctionGranted(entity.projectId(), ProjectConfig.class); }
@Override public int getCountByCategory(ProjectEntity entity, String category) { return getNamedParameterJdbcTemplate().queryForObject( String.format( "SELECT COUNT(*) FROM ENTITY_DATA_STORE " + "WHERE %s = :entityId " + "AND CATEGORY = :category ", entity.getProjectEntityType().name() ), params("entityId", entity.id()) .addValue("category", category), Integer.class ); }
@Override public List<Decoration<?>> getDecorations(ProjectEntity entity) { // Downloading a decoration with the current security context Function<Decorator, Stream<Decoration<?>>> securedDecoratorFunction = securityService.runner( decorator -> getDecorations(entity, decorator).stream() ); // OK return extensionManager.getExtensions(DecorationExtension.class) .stream() // ... and filters per entity .filter(decorator -> decorator.getScope().contains(entity.getProjectEntityType())) // ... and gets the decoration .flatMap(securedDecoratorFunction) // OK .collect(Collectors.toList()); }
/** * Checks if the <code>fn</code> function is granted for the current user * for the <code>projectEntity</code>'s project. */ default boolean isProjectFunctionGranted(ProjectEntity projectEntity, Class<? extends ProjectFunction> fn) { return isProjectFunctionGranted(projectEntity.projectId(), fn); }