public boolean containsValue(String propertyValue) { return value != null && type.containsValue(value, propertyValue); } }
/** * Parses the JSON representation for a property value and creates the property value directly. * * @see #fromStorage(JsonNode) * @see #of(Object) */ default Property<T> of(JsonNode node) { return of(fromStorage(node)); }
public static <T> PropertyTypeDescriptor of(PropertyType<T> type) { return new PropertyTypeDescriptor( type.getFeature().getFeatureDescription(), type.getClass().getName(), type.getName(), type.getDescription() ); }
protected <T> Form getPropertyEditionForm(ProjectEntity entity, PropertyType<T> propertyType) { // Checks for edition if (!propertyType.canEdit(entity, securityService)) { throw new AccessDeniedException("Property is not opened for edition."); } // Gets the value for this property T value = getPropertyValue(propertyType, entity); // Gets the form return propertyType.getEditionForm(entity, value); } }
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 List<Property<?>> getProperties(ProjectEntity entity) { // With all the existing properties... return getPropertyTypes().stream() // ... filters them by entity .filter(type -> type.getSupportedEntityTypes().contains(entity.getProjectEntityType())) // ... filters them by access right .filter(type -> type.canView(entity, securityService)) // ... loads them from the store .map(type -> getProperty(type, entity)) // .. flags with editionrights .map(prop -> prop.editable(prop.getType().canEdit(entity, securityService))) // ... and returns them .collect(Collectors.toList()); }
@Override public List<GraphQLFieldDefinition> getFields(Class<? extends ProjectEntity> projectEntityClass, ProjectEntityType projectEntityType) { return propertyService.getPropertyTypes().stream() // Gets properties which supports this type of entity .filter(propertyType -> propertyType.getSupportedEntityTypes().contains(projectEntityType)) // Gets as a field definition .map(propertyType -> newFieldDefinition() .name(propertyFieldName(propertyType)) .description(propertyType.getDescription()) .type(property.getTypeRef()) .dataFetcher(projectEntityPropertyDataFetcher(propertyType, projectEntityClass)) .build()) // OK .collect(Collectors.toList()); }
@Override public <T> Event propertyDelete(ProjectEntity entity, PropertyType<T> propertyType) { return Event.of(PROPERTY_DELETE) .withRef(entity) .with("entity", entity.getProjectEntityType().getDisplayName()) .with("property", new NameValue( propertyType.getTypeName(), propertyType.getName() )) .get(); }
@Override @Nullable public <T> ID findBuildByBranchAndSearchkey(ID branchId, Class<? extends PropertyType<T>> propertyType, String searchKey) { // Gets the property type by name PropertyType<T> actualPropertyType = getPropertyTypeByName(propertyType.getName()); // Gets the search arguments PropertySearchArguments searchArguments = actualPropertyType.getSearchArguments(searchKey); if (searchArguments != null) { return propertyRepository.findBuildByBranchAndSearchkey(branchId, propertyType.getName(), searchArguments); } else { return null; } }
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 <T> Collection<ProjectEntity> searchWithPropertyValue( Class<? extends PropertyType<T>> propertyTypeClass, BiFunction<ProjectEntityType, ID, ProjectEntity> entityLoader, Predicate<T> predicate) { // Gets the property type String propertyTypeName = propertyTypeClass.getName(); PropertyType<T> propertyType = getPropertyTypeByName(propertyTypeName); // Search return propertyRepository.searchByProperty( propertyTypeName, entityLoader, t -> predicate.test(propertyType.fromStorage(t.getJson())) ); }
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; } }
protected <T> void doCopyProperty(ProjectEntity sourceEntity, Property<T> property, ProjectEntity targetEntity, Function<String, String> replacementFn) { if (!property.isEmpty() && property.getType().canEdit(targetEntity, securityService)) { // Copy of the property propertyService.copyProperty( sourceEntity, property, targetEntity, replacementFn ); } }
@Override public <T> void copyProperty(ProjectEntity sourceEntity, Property<T> property, ProjectEntity targetEntity, Function<String, String> replacementFn) { // Property copy T data = property.getType().copy(sourceEntity, property.getValue(), targetEntity, replacementFn); // Direct edition editProperty(targetEntity, property.getType(), data); }
@Override public <T> Event propertyChange(ProjectEntity entity, PropertyType<T> propertyType) { return Event.of(PROPERTY_CHANGE) .withRef(entity) .with("entity", entity.getProjectEntityType().getDisplayName()) .with("property", new NameValue( propertyType.getTypeName(), propertyType.getName() )) .get(); }
PropertySearchArguments searchArguments = propertyType.getSearchArguments(propertyValue);
PropertySearchArguments searchArguments = propertyType.getSearchArguments(withPropertyValue);
private <T> boolean matchProperty(ProjectEntity e, PropertyFilter filter) { PropertyType<T> type = propertyService.getPropertyTypeByName(filter.getType()); Property<T> property = propertyService.getProperty(e, filter.getType()); return !property.isEmpty() && ( StringUtils.isBlank(filter.getValue()) || type.containsValue(property.getValue(), filter.getValue()) ); }