@Test void toEntityFileValueWithoutFileInRequest() throws ParseException { int entityId = 12345; String fileName = "File name"; String fileAttrName = "fileAttr"; String oldEntityTypeId = "oldEntityTypeId"; EntityType oldEntityType = mock(EntityType.class); Entity oldEntity = mock(Entity.class); FileMeta storedFileMeta = mock(FileMeta.class); Attribute fileAttr = mock(Attribute.class); Attribute idAttr = mock(Attribute.class); when(fileAttr.getName()).thenReturn(fileAttrName); when(fileAttr.getEntity()).thenReturn(oldEntityType); when(fileAttr.getDataType()).thenReturn(FILE); when(oldEntityType.getId()).thenReturn(oldEntityTypeId); when(oldEntityType.getIdAttribute()).thenReturn(idAttr); when(idAttr.getDataType()).thenReturn(INT); when(oldEntity.getEntity(fileAttrName)).thenReturn(storedFileMeta); when(storedFileMeta.get(FileMetaMetadata.FILENAME)).thenReturn(fileName); when(dataService.findOneById(fileAttr.getEntity().getId(), entityId)).thenReturn(oldEntity); Object result = restService.toEntityValue(fileAttr, fileName, entityId); assertEquals(storedFileMeta, result); }
public Object toEntityValue(Attribute attr, Object paramValue, Object id) { if ((paramValue instanceof String) && ((String) paramValue).isEmpty()) { paramValue = null; } Object value; AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: value = convertBool(attr, paramValue); break; case EMAIL: case ENUM: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: value = convertString(attr, paramValue); break; case CATEGORICAL: case XREF: value = convertRef(attr, paramValue); break; case CATEGORICAL_MREF: case MREF: case ONE_TO_MANY: value = convertMref(attr, paramValue); break; case DATE: value = convertDate(attr, paramValue); break; case DATE_TIME: value = convertDateTime(attr, paramValue); break; case DECIMAL: value = convertDecimal(attr, paramValue); break; case FILE: value = convertFile(attr, paramValue, id); break; case INT: value = convertInt(attr, paramValue); break; case LONG: value = convertLong(attr, paramValue); break; case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } return value; }
RestService { public Object toEntityValue(Attribute attr, Object paramValue, Object id) { if ((paramValue instanceof String) && ((String) paramValue).isEmpty()) { paramValue = null; } Object value; AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: value = convertBool(attr, paramValue); break; case EMAIL: case ENUM: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: value = convertString(attr, paramValue); break; case CATEGORICAL: case XREF: value = convertRef(attr, paramValue); break; case CATEGORICAL_MREF: case MREF: case ONE_TO_MANY: value = convertMref(attr, paramValue); break; case DATE: value = convertDate(attr, paramValue); break; case DATE_TIME: value = convertDateTime(attr, paramValue); break; case DECIMAL: value = convertDecimal(attr, paramValue); break; case FILE: value = convertFile(attr, paramValue, id); break; case INT: value = convertInt(attr, paramValue); break; case LONG: value = convertLong(attr, paramValue); break; case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } return value; } }
RestService { public Object toEntityValue(Attribute attr, Object paramValue, Object id) { if ((paramValue instanceof String) && ((String) paramValue).isEmpty()) { paramValue = null; } Object value; AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: value = convertBool(attr, paramValue); break; case EMAIL: case ENUM: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: value = convertString(attr, paramValue); break; case CATEGORICAL: case XREF: value = convertRef(attr, paramValue); break; case CATEGORICAL_MREF: case MREF: case ONE_TO_MANY: value = convertMref(attr, paramValue); break; case DATE: value = convertDate(attr, paramValue); break; case DATE_TIME: value = convertDateTime(attr, paramValue); break; case DECIMAL: value = convertDecimal(attr, paramValue); break; case FILE: value = convertFile(attr, paramValue, id); break; case INT: value = convertInt(attr, paramValue); break; case LONG: value = convertLong(attr, paramValue); break; case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } return value; } RestService(
      DataService dataService,
      IdGenerator idGenerator,
      FileStore fileStore,
      FileMetaFactory fileMetaFactory,
      EntityManager entityManager,
      ServletUriComponentsBuilderFactory servletUriComponentsBuilderFactory); }
RestService { public Object toEntityValue(Attribute attr, Object paramValue, Object id) { if ((paramValue instanceof String) && ((String) paramValue).isEmpty()) { paramValue = null; } Object value; AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: value = convertBool(attr, paramValue); break; case EMAIL: case ENUM: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: value = convertString(attr, paramValue); break; case CATEGORICAL: case XREF: value = convertRef(attr, paramValue); break; case CATEGORICAL_MREF: case MREF: case ONE_TO_MANY: value = convertMref(attr, paramValue); break; case DATE: value = convertDate(attr, paramValue); break; case DATE_TIME: value = convertDateTime(attr, paramValue); break; case DECIMAL: value = convertDecimal(attr, paramValue); break; case FILE: value = convertFile(attr, paramValue, id); break; case INT: value = convertInt(attr, paramValue); break; case LONG: value = convertLong(attr, paramValue); break; case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } return value; } RestService(
      DataService dataService,
      IdGenerator idGenerator,
      FileStore fileStore,
      FileMetaFactory fileMetaFactory,
      EntityManager entityManager,
      ServletUriComponentsBuilderFactory servletUriComponentsBuilderFactory); Entity toEntity(final EntityType meta, final Map<String, Object> request); Object toEntityValue(Attribute attr, Object paramValue, Object id); void updateMappedByEntities(@Nonnull Entity entity); void updateMappedByEntities(
      @Nonnull Entity entity, @Nullable @CheckForNull Entity existingEntity); }
RestService { public Object toEntityValue(Attribute attr, Object paramValue, Object id) { if ((paramValue instanceof String) && ((String) paramValue).isEmpty()) { paramValue = null; } Object value; AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: value = convertBool(attr, paramValue); break; case EMAIL: case ENUM: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: value = convertString(attr, paramValue); break; case CATEGORICAL: case XREF: value = convertRef(attr, paramValue); break; case CATEGORICAL_MREF: case MREF: case ONE_TO_MANY: value = convertMref(attr, paramValue); break; case DATE: value = convertDate(attr, paramValue); break; case DATE_TIME: value = convertDateTime(attr, paramValue); break; case DECIMAL: value = convertDecimal(attr, paramValue); break; case FILE: value = convertFile(attr, paramValue, id); break; case INT: value = convertInt(attr, paramValue); break; case LONG: value = convertLong(attr, paramValue); break; case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } return value; } RestService(
      DataService dataService,
      IdGenerator idGenerator,
      FileStore fileStore,
      FileMetaFactory fileMetaFactory,
      EntityManager entityManager,
      ServletUriComponentsBuilderFactory servletUriComponentsBuilderFactory); Entity toEntity(final EntityType meta, final Map<String, Object> request); Object toEntityValue(Attribute attr, Object paramValue, Object id); void updateMappedByEntities(@Nonnull Entity entity); void updateMappedByEntities(
      @Nonnull Entity entity, @Nullable @CheckForNull Entity existingEntity);  }