org.springframework.hateoas.Identifiable Java Examples

The following examples show how to use org.springframework.hateoas.Identifiable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IdentifiableToIdConverter.java    From cloudstreetmarket.com with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new ToAttributedValueConverter instance.
 * 
 * @param mapper the mapper in use
 * @param reflectionProvider the reflection provider in use
 * @param lookup the converter lookup in use
 * @param valueFieldName the field defining the tag's value (may be null)
 * @param valueDefinedIn the type defining the field
 */
public IdentifiableToIdConverter(
    final Class<Identifiable<?>> type, final Mapper mapper, final ReflectionProvider reflectionProvider,
    final ConverterLookup lookup, final String valueFieldName, Class<?> valueDefinedIn) {
    this.type = type;

       Field field = null;
       try {
           field = (valueDefinedIn != null ? valueDefinedIn : type.getSuperclass())
               .getDeclaredField("id");
          
           if (!field.isAccessible()) {
               field.setAccessible(true);
           }
       } catch (NoSuchFieldException e) {
           throw new IllegalArgumentException(e.getMessage() + ": " + valueFieldName);
       }
}
 
Example #2
Source File: AbstractTagToken.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
protected boolean checkAssignmentResult(final List<? extends Identifiable<Long>> assignedEntities,
        final Long expectedAssignedEntityId) {
    if (!CollectionUtils.isEmpty(assignedEntities) && expectedAssignedEntityId != null) {
        final List<Long> assignedDsIds = assignedEntities.stream().map(Identifiable::getId)
                .collect(Collectors.toList());
        if (assignedDsIds.contains(expectedAssignedEntityId)) {
            return true;
        }
    }
    return false;
}
 
Example #3
Source File: IdentifiableToIdConverter.java    From cloudstreetmarket.com with GNU General Public License v3.0 4 votes vote down vote up
public void marshal(final Object source, final HierarchicalStreamWriter writer,
    final MarshallingContext context) {
    if(source instanceof Identifiable){
    	writer.setValue(((Identifiable<?>)source).getId().toString());
    }
}
 
Example #4
Source File: IdentifiableSerializer.java    From cloudstreetmarket.com with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void serialize(Identifiable<?> value, JsonGenerator jgen, SerializerProvider provider) 
  throws IOException, JsonProcessingException {
	provider.defaultSerializeValue(value.getId(), jgen);
}
 
Example #5
Source File: AbstractTagToken.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
protected boolean checkUnassignmentResult(final Identifiable<Long> unAssignedEntity,
        final Long expectedUnAssignedEntityId) {
    return unAssignedEntity != null && expectedUnAssignedEntityId != null
            && unAssignedEntity.getId().equals(expectedUnAssignedEntityId);
}
 
Example #6
Source File: IdentifiableToIdConverter.java    From cloudstreetmarket.com with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a new ToAttributedValueConverter instance.
 * 
 * @param mapper the mapper in use
 * @param reflectionProvider the reflection provider in use
 * @param lookup the converter lookup in use
 * @param valueFieldName the field defining the tag's value (may be null)
 */
public IdentifiableToIdConverter(
    final Class<Identifiable<?>> type, final Mapper mapper, final ReflectionProvider reflectionProvider,
    final ConverterLookup lookup, final String valueFieldName) {
    this(type, mapper, reflectionProvider, lookup, valueFieldName, null);
}