@Override public UriHelper createUriHelper() { return new UriHelperImpl(); }
@Override public String buildCanonicalURL(final EdmEntitySet edmEntitySet, final Entity entity) throws SerializerException { return edmEntitySet.getName() + '(' + buildKeyPredicate(edmEntitySet.getEntityType(), entity) + ')'; }
private Object findPropertyRefValue(Entity entity, EdmKeyPropertyRef refType) throws SerializerException { final int INDEX_ERROR_CODE = -1; final String propertyPath = refType.getName(); String tmpPropertyName; int lastIndex; int index = propertyPath.indexOf('/'); if (index == INDEX_ERROR_CODE) { index = propertyPath.length(); } tmpPropertyName = propertyPath.substring(0, index); //get first property Property prop = entity.getProperty(tmpPropertyName); //get following properties while (index < propertyPath.length()) { lastIndex = ++index; index = propertyPath.indexOf('/', index+1); if (index == INDEX_ERROR_CODE) { index = propertyPath.length(); } tmpPropertyName = propertyPath.substring(lastIndex, index); prop = findProperty(tmpPropertyName, prop.asComplex().getValue()); } if (prop == null) { throw new SerializerException("Key Value Cannot be null for property: " + propertyPath, SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, propertyPath); } return prop.getValue(); }
final Object propertyValue = findPropertyRefValue(entity, refType); try { final String value = type.toUriLiteral(
private Object findPropertyRefValue(Entity entity, EdmKeyPropertyRef refType) throws SerializerException { final int INDEX_ERROR_CODE = -1; final String propertyPath = refType.getName(); String tmpPropertyName; int lastIndex; int index = propertyPath.indexOf('/'); if (index == INDEX_ERROR_CODE) { index = propertyPath.length(); } tmpPropertyName = propertyPath.substring(0, index); //get first property Property prop = entity.getProperty(tmpPropertyName); //get following properties while (index < propertyPath.length()) { lastIndex = ++index; index = propertyPath.indexOf('/', index+1); if (index == INDEX_ERROR_CODE) { index = propertyPath.length(); } tmpPropertyName = propertyPath.substring(lastIndex, index); prop = findProperty(tmpPropertyName, prop.asComplex().getValue()); } if (prop == null) { throw new SerializerException("Key Value Cannot be null for property: " + propertyPath, SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, propertyPath); } return prop.getValue(); }
final Object propertyValue = findPropertyRefValue(entity, refType); try { final String value = type.toUriLiteral(
@Override public UriHelper createUriHelper() { return new UriHelperImpl(); }
@Override public String buildCanonicalURL(final EdmEntitySet edmEntitySet, final Entity entity) throws SerializerException { return edmEntitySet.getName() + '(' + buildKeyPredicate(edmEntitySet.getEntityType(), entity) + ')'; }
/** * Get the ascii representation of the entity id * or thrown an {@link SerializerException} if id is <code>null</code>. * * @param entity the entity * @param entityType * @param name * @return ascii representation of the entity id */ private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException { if(entity != null && entity.getId() == null) { if(entityType == null || entityType.getKeyPredicateNames() == null || name == null) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); }else{ final UriHelper uriHelper = new UriHelperImpl(); entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')')); } } return entity.getId().toASCIIString(); }
/** * Get the ascii representation of the entity id * or thrown an {@link SerializerException} if id is <code>null</code>. * * @param entity the entity * @param entityType the entity Type * @param name the entity name * @return ascii representation of the entity id */ private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException { if(entity.getId() == null) { if((entity == null || entityType == null || entityType.getKeyPredicateNames() == null || name == null)) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); }else{ final UriHelper uriHelper = new UriHelperImpl(); entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')')); } } return entity.getId().toASCIIString(); }
/** * Get the ascii representation of the entity id * or thrown an {@link SerializerException} if id is <code>null</code>. * * @param entity the entity * @param entityType * @param name * @return ascii representation of the entity id */ private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException { if(entity != null && entity.getId() == null) { if(entityType == null || entityType.getKeyPredicateNames() == null || name == null) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); }else{ final UriHelper uriHelper = new UriHelperImpl(); entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')')); } } return entity.getId().toASCIIString(); }
/** * Get the ascii representation of the entity id * or thrown an {@link SerializerException} if id is <code>null</code>. * * @param entity the entity * @param entityType the entity Type * @param name the entity name * @return ascii representation of the entity id */ private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException { if(entity.getId() == null) { if((entity == null || entityType == null || entityType.getKeyPredicateNames() == null || name == null)) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); }else{ final UriHelper uriHelper = new UriHelperImpl(); entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')')); } } return entity.getId().toASCIIString(); }
@Override public SerializerResult reference(final ServiceMetadata metadata, final EdmEntitySet edmEntitySet, final Entity entity, final ReferenceSerializerOptions options) throws SerializerException { OutputStream outputStream = null; SerializerException cachedException = null; try { final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL()); CircleStreamBuffer buffer = new CircleStreamBuffer(); final UriHelper uriHelper = new UriHelperImpl(); outputStream = buffer.getOutputStream(); final JsonGenerator json = new JsonFactory().createGenerator(outputStream); json.writeStartObject(); writeContextURL(contextURL, json); json.writeStringField(constants.getId(), uriHelper.buildCanonicalURL(edmEntitySet, entity)); json.writeEndObject(); json.close(); outputStream.close(); return SerializerResultImpl.with().content(buffer.getInputStream()).build(); } catch (final IOException e) { cachedException = new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION); throw cachedException; } finally { closeCircleStreamBufferOutput(outputStream, cachedException); } }
@Override public SerializerResult reference(final ServiceMetadata metadata, final EdmEntitySet edmEntitySet, final Entity entity, final ReferenceSerializerOptions options) throws SerializerException { OutputStream outputStream = null; SerializerException cachedException = null; try { final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL()); CircleStreamBuffer buffer = new CircleStreamBuffer(); final UriHelper uriHelper = new UriHelperImpl(); outputStream = buffer.getOutputStream(); final JsonGenerator json = new JsonFactory().createGenerator(outputStream); json.writeStartObject(); writeContextURL(contextURL, json); json.writeStringField(constants.getId(), uriHelper.buildCanonicalURL(edmEntitySet, entity)); json.writeEndObject(); json.close(); outputStream.close(); return SerializerResultImpl.with().content(buffer.getInputStream()).build(); } catch (final IOException e) { cachedException = new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION); throw cachedException; } finally { closeCircleStreamBufferOutput(outputStream, cachedException); } }
/** * Get the ascii representation of the entity id * or thrown an {@link SerializerException} if id is <code>null</code>. * * @param entity the entity * @return ascii representation of the entity id */ private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException { try { if (entity != null) { if (entity.getId() == null) { if (entityType == null || entityType.getKeyPredicateNames() == null || name == null) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); } else { final UriHelper uriHelper = new UriHelperImpl(); entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')')); return entity.getId().toASCIIString(); } } else { return entity.getId().toASCIIString(); } } return null; } catch (Exception e) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); } }
/** * Get the ascii representation of the entity id * or thrown an {@link SerializerException} if id is <code>null</code>. * * @param entity the entity * @return ascii representation of the entity id */ private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException { try { if (entity != null) { if (entity.getId() == null) { if (entityType == null || entityType.getKeyPredicateNames() == null || name == null) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); } else { final UriHelper uriHelper = new UriHelperImpl(); entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')')); return entity.getId().toASCIIString(); } } else { return entity.getId().toASCIIString(); } } return null; } catch (Exception e) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); } }
/** * Get the ascii representation of the entity id * or thrown an {@link SerializerException} if id is <code>null</code>. * * @param entity the entity * @return ascii representation of the entity id */ private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException { try { if (entity != null) { if (entity.getId() == null) { if (entityType == null || entityType.getKeyPredicateNames() == null || name == null) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); } else { final UriHelper uriHelper = new UriHelperImpl(); entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')')); return entity.getId().toASCIIString(); } } else { return entity.getId().toASCIIString(); } } return null; } catch (Exception e) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); } }
/** * Get the ascii representation of the entity id * or thrown an {@link SerializerException} if id is <code>null</code>. * * @param entity the entity * @return ascii representation of the entity id */ private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException { try { if (entity != null) { if (entity.getId() == null) { if (entityType == null || entityType.getKeyPredicateNames() == null || name == null) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); } else { final UriHelper uriHelper = new UriHelperImpl(); entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')')); return entity.getId().toASCIIString(); } } else { return entity.getId().toASCIIString(); } } return null; } catch (Exception e) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); } }
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL()); CircleStreamBuffer buffer = new CircleStreamBuffer(); final UriHelper uriHelper = new UriHelperImpl(); outputStream = buffer.getOutputStream(); final JsonGenerator json = new JsonFactory().createGenerator(outputStream);
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL()); CircleStreamBuffer buffer = new CircleStreamBuffer(); final UriHelper uriHelper = new UriHelperImpl(); outputStream = buffer.getOutputStream(); final JsonGenerator json = new JsonFactory().createGenerator(outputStream);