protected URI createId(final Entity entity) { try { // TODO Clarify host-name and port as part of ID see // http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Toc372792702 final StringBuilder uriString = new StringBuilder(setName); uriString.append("("); uriString.append(uriHelper.buildKeyPredicate(edmType, entity)); uriString.append(")"); return new URI(uriString.toString()); } catch (URISyntaxException e) { throw new ODataRuntimeException("Unable to create id for entity: " + edmType.getName(), e); } catch (IllegalArgumentException e) { return null; } catch (SerializerException e) { throw new ODataRuntimeException(e); } }
/** * This method validates Edm Entity types. * Looks for correct namespace aliases and correct base types */ private void validateEdmEntityTypes() { for (Map.Entry<FullQualifiedName, EdmEntityType> entityTypes : edmEntityTypesMap.entrySet()) { if (entityTypes.getValue() != null && entityTypes.getKey() != null) { EdmEntityType entityType = entityTypes.getValue(); if (entityType.getBaseType() != null) { FullQualifiedName baseTypeFQName = entityType.getBaseType().getFullQualifiedName(); EdmEntityType baseEntityType = edmEntityTypesMap.get(baseTypeFQName); if (baseEntityType != null && baseEntityType.getKeyPredicateNames().isEmpty()) { throw new RuntimeException("Missing key for EntityType " + baseEntityType.getName()); } } else if (entityType.getKeyPredicateNames().isEmpty()) { throw new RuntimeException("Missing key for EntityType " + entityType.getName()); } } } }
/** * This method validates Edm Entity types. * Looks for correct namespace aliases and correct base types */ private void validateEdmEntityTypes() { for (Map.Entry<FullQualifiedName, EdmEntityType> entityTypes : edmEntityTypesMap.entrySet()) { if (entityTypes.getValue() != null && entityTypes.getKey() != null) { EdmEntityType entityType = entityTypes.getValue(); if (entityType.getBaseType() != null) { FullQualifiedName baseTypeFQName = entityType.getBaseType().getFullQualifiedName(); EdmEntityType baseEntityType = edmEntityTypesMap.get(baseTypeFQName); if (baseEntityType != null && baseEntityType.getKeyPredicateNames().isEmpty()) { throw new RuntimeException("Missing key for EntityType " + baseEntityType.getName()); } } else if (entityType.getKeyPredicateNames().isEmpty()) { throw new RuntimeException("Missing key for EntityType " + entityType.getName()); } } } }
/** * This method returns entity by retrieving the entity collection according to keys and etag. * * @param entityType EdmEntityType * @param keys keys * @return Entity * @throws ODataApplicationException * @throws ODataServiceFault */ private Entity getEntity(EdmEntityType entityType, List<UriParameter> keys, String baseUrl) throws ODataApplicationException, ODataServiceFault { EntityCollection entityCollection = createEntityCollectionFromDataEntryList(entityType.getName(), dataHandler .readTableWithKeys(entityType.getName(), wrapKeyParamToDataEntry(keys)), baseUrl); return getEntity(entityType, entityCollection, keys); }
static Table findTable(EdmEntityType entityType, MetadataStore store) { FullQualifiedName fqn = entityType.getFullQualifiedName(); // remove the vdb name String withoutVDB = fqn.getNamespace().substring(fqn.getNamespace().lastIndexOf('.')+1); Schema schema = store.getSchema(withoutVDB); return schema.getTable(entityType.getName()); }
private void appendEntityTypes(final XMLStreamWriter writer, final List<EdmEntityType> entityTypes) throws XMLStreamException { for (EdmEntityType entityType : entityTypes) { writer.writeStartElement(XML_ENTITY_TYPE); writer.writeAttribute(XML_NAME, entityType.getName()); if (entityType.hasStream()) { writer.writeAttribute(XML_HAS_STREAM, "" + entityType.hasStream()); } if (entityType.getBaseType() != null) { writer.writeAttribute(XML_BASE_TYPE, getAliasedFullQualifiedName(entityType.getBaseType(), false)); } if (entityType.isAbstract()) { writer.writeAttribute(ABSTRACT, TRUE); } if (entityType.isOpenType()) { writer.writeAttribute(OPEN_TYPE, TRUE); } appendKey(writer, entityType); appendProperties(writer, entityType); appendNavigationProperties(writer, entityType); appendAnnotations(writer, entityType); writer.writeEndElement(); } }
private void appendEntityTypes(final XMLStreamWriter writer, final List<EdmEntityType> entityTypes) throws XMLStreamException { for (EdmEntityType entityType : entityTypes) { writer.writeStartElement(XML_ENTITY_TYPE); writer.writeAttribute(XML_NAME, entityType.getName()); if (entityType.hasStream()) { writer.writeAttribute(XML_HAS_STREAM, "" + entityType.hasStream()); } if (entityType.getBaseType() != null) { writer.writeAttribute(XML_BASE_TYPE, getAliasedFullQualifiedName(entityType.getBaseType(), false)); } if (entityType.isAbstract()) { writer.writeAttribute(ABSTRACT, TRUE); } if (entityType.isOpenType()) { writer.writeAttribute(OPEN_TYPE, TRUE); } appendKey(writer, entityType); appendProperties(writer, entityType); appendNavigationProperties(writer, entityType); appendAnnotations(writer, entityType); writer.writeEndElement(); } }
public JPAExpandLevelWrapper(final JPAServiceDocument sd, final ExpandOption option) throws ODataApplicationException { super(); this.option = option; this.item = option.getExpandItems().get(0); this.levelOptions = determineLevel(item); try { this.jpaEntityType = sd.getEntity(Util.determineTargetEntityType(getUriResourceParts())); } catch (ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_PREPARATION_ENTITY_UNKNOWN, HttpStatusCode.BAD_REQUEST, e, Util.determineTargetEntityType(getUriResourceParts()).getName()); } }
public JPAExpandItemWrapper(final JPAServiceDocument sd, final ExpandItem item) throws ODataApplicationException { super(); this.item = item; try { this.jpaEntityType = sd.getEntity(Util.determineTargetEntityType(getUriResourceParts())); } catch (ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_PREPARATION_ENTITY_UNKNOWN, HttpStatusCode.BAD_REQUEST, e, Util.determineTargetEntityType(getUriResourceParts()).getName()); } }
return entitySet.getEntityContainer().getEntitySet(uriResourceNavigation.getProperty().getType().getName());
private static ExpandOptionImpl constructDraftTreeExpand(EdmEntityType rootEntityType,ExpandOptionImpl eO,Map<String,List<String>> draftTree) { if(eO==null) { eO=new ExpandOptionImpl(); } if(rootEntityType.getNavigationPropertyNames()!=null && !rootEntityType.getNavigationPropertyNames().isEmpty()) { for(String navName:rootEntityType.getNavigationPropertyNames()) { EdmNavigationProperty expandNp=rootEntityType.getNavigationProperty(navName); if(draftTree.get(rootEntityType.getName()).contains(expandNp.getType().getName())) { UriResourceNavigationPropertyImpl adminNaVPropImpl=new UriResourceNavigationPropertyImpl(expandNp); UriInfoImpl uriInfoForExpand = new UriInfoImpl().addResourcePart(adminNaVPropImpl); //Recursively set compositions ExpandOption innerExpandoption=constructDraftTreeExpand(expandNp.getType(),(ExpandOptionImpl) uriInfoForExpand.getExpandOption(),draftTree); if(innerExpandoption!=null) { uriInfoForExpand.setSystemQueryOption(innerExpandoption); ExpandItem eI = new ExpandItemImpl().setResourcePath(uriInfoForExpand).setSystemQueryOption(innerExpandoption); eO.addExpandItem(eI); } } } return eO; } return eO; }
List<Property> properties = new ArrayList<>(); Map<String, EdmProperty> propertyMap = new HashMap<>(); for (NavigationKeys keys : this.dataHandler.getNavigationProperties().get(type.getName()) .getNavigationKeys(linkName)) { Property property = parentEntity.getProperty(keys.getPrimaryKey());
entry.addValue(property, readPrimitiveValueInString(propertyType, updateProperty.getValue())); this.dataHandler.updateEntityInTable(edmEntityType.getName(), entry);
private void appendEntityTypes(JsonGenerator json, List<EdmEntityType> entityTypes) throws SerializerException, IOException { for (EdmEntityType entityType : entityTypes) { json.writeObjectFieldStart(entityType.getName()); json.writeStringField(KIND, Kind.EntityType.name()); if (entityType.hasStream()) { json.writeBooleanField(HAS_STREAM, entityType.hasStream()); } if (entityType.getBaseType() != null) { json.writeStringField(BASE_TYPE, getAliasedFullQualifiedName(entityType.getBaseType())); } if (entityType.isAbstract()) { json.writeBooleanField(ABSTRACT, entityType.isAbstract()); } appendKey(json, entityType); appendProperties(json, entityType); appendNavigationProperties(json, entityType); appendAnnotations(json, entityType, null); json.writeEndObject(); } }
private void appendEntityTypes(JsonGenerator json, List<EdmEntityType> entityTypes) throws SerializerException, IOException { for (EdmEntityType entityType : entityTypes) { json.writeObjectFieldStart(entityType.getName()); json.writeStringField(KIND, Kind.EntityType.name()); if (entityType.hasStream()) { json.writeBooleanField(HAS_STREAM, entityType.hasStream()); } if (entityType.getBaseType() != null) { json.writeStringField(BASE_TYPE, getAliasedFullQualifiedName(entityType.getBaseType())); } if (entityType.isAbstract()) { json.writeBooleanField(ABSTRACT, entityType.isAbstract()); } appendKey(json, entityType); appendProperties(json, entityType); appendNavigationProperties(json, entityType); appendAnnotations(json, entityType, null); json.writeEndObject(); } }
.getEntityType(new FullQualifiedName(this.namespace, tableName)); entity.setId(new URI(ODataUtils.buildLocation(baseURL, entity, entityType.getName(), entityType))); entity.setETag(entry.getValue("ETag")); entity.setType(new FullQualifiedName(this.namespace, tableName).getFullQualifiedNameAsString());
String etySetName = navProp.getType().getName(); cEinfo.setEntityName(etySetName);
public static UriInfoDraftHelperV4 getCreateUriInfoForDraftsOneToOneUsingParent(EdmNavigationProperty navPropParent,Entity parentDraftsEntry,EdmEntityContainer entityContainer) throws ODataApplicationException { Entity childPayload=new Entity(); List<EdmReferentialConstraint> refConstraints = null ; refConstraints = navPropParent.getReferentialConstraints(); if( refConstraints == null || refConstraints.isEmpty() ){ throw new ODataApplicationException ("Unable to create with navigation because the corresponding referential constraint is missing.", HttpStatusCode.INTERNAL_SERVER_ERROR .getStatusCode(),Locale.ENGLISH,"Unable to create with navigation because the corresponding referential constraint is missing"); } refConstraints.forEach(refConstraint->{ // Map of <ChildKey , ParentKey> childPayload.addProperty(new Property(null, refConstraint.getReferencedPropertyName(), ValueType.PRIMITIVE, parentDraftsEntry.getProperty(refConstraint.getPropertyName()).getValue())); }); DeserializerResult deserializerResult=DeserializerResultImpl.with().entity(childPayload).build(); EdmEntitySet entSet=entityContainer.getEntitySet(navPropParent.getType().getName()); UriResourceEntitySet entitySetForCreate = new UriResourceEntitySetImpl(entSet); UriInfo uriInfoForCreate = new UriInfoImpl().addResourcePart(entitySetForCreate); UriInfoDraftHelperV4 _uriT=new UriInfoDraftHelperV4(); _uriT.setUriInfo(uriInfoForCreate); _uriT.setDeserializerResult(deserializerResult); _uriT.setUriFunction(UriFunction.CREATE); return _uriT; }
public Query selectWithEntityKey(EdmEntityType entityType, Entity entity, Map<String, Object> generatedKeys, List<ExpandNode> expand) throws TeiidException { Table table = findTable(entityType.getName(), this.metadata); Object value = generatedKeys.get(c.getName()); if (value == null) { throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16016, entityType.getName()));
@Override public SerializerResult serialize(final ODataRequest request, final EntityCollection result) throws SerializerException { final EdmEntitySet targetEdmEntitySet = Util.determineTargetEntitySet(uriInfo.getUriResourceParts()); final String selectList = uriHelper.buildContextURLSelectList(targetEdmEntitySet.getEntityType(), uriInfo.getExpandOption(), uriInfo.getSelectOption()); final ContextURL contextUrl = ContextURL.with() .entitySet(targetEdmEntitySet) .selectList(selectList) .build(); final String id = request.getRawBaseUri() + "/" + targetEdmEntitySet.getEntityType().getName(); final EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with() .contextURL(contextUrl) .id(id) .count(uriInfo.getCountOption()) .select(uriInfo.getSelectOption()) .expand(uriInfo.getExpandOption()) .build(); return serializer.entityCollection(this.serviceMetadata, targetEdmEntitySet.getEntityType(), result, opts); }