Java Code Examples for org.apache.olingo.commons.api.edm.EdmEntityType#getBaseType()

The following examples show how to use org.apache.olingo.commons.api.edm.EdmEntityType#getBaseType() . 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: MetadataDocumentJsonSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void appendKey(final JsonGenerator json, 
    final EdmEntityType entityType) throws SerializerException, IOException {
  List<EdmKeyPropertyRef> keyPropertyRefs = entityType.getKeyPropertyRefs();
  if (keyPropertyRefs != null && !keyPropertyRefs.isEmpty()) {
    // Resolve Base Type key as it is shown in derived type
    EdmEntityType baseType = entityType.getBaseType();
    if (baseType != null && baseType.getKeyPropertyRefs() != null && !(baseType.getKeyPropertyRefs().isEmpty())) {
      return;
    }
    json.writeArrayFieldStart(KEY);
    for (EdmKeyPropertyRef keyRef : keyPropertyRefs) {
      
      if (keyRef.getAlias() != null) {
        json.writeStartObject();
        json.writeStringField(keyRef.getAlias(), keyRef.getName());
        json.writeEndObject();
      } else {
        json.writeString(keyRef.getName());
      }
    }
    json.writeEndArray();
  }
}
 
Example 2
Source File: ODataJsonSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
protected EdmEntityType resolveEntityType(final ServiceMetadata metadata, final EdmEntityType baseType,
    final String derivedTypeName) throws SerializerException {
  if (derivedTypeName == null ||
      baseType.getFullQualifiedName().getFullQualifiedNameAsString().equals(derivedTypeName)) {
    return baseType;
  }
  EdmEntityType derivedType = metadata.getEdm().getEntityType(new FullQualifiedName(derivedTypeName));
  if (derivedType == null) {
    throw new SerializerException("EntityType not found",
        SerializerException.MessageKeys.UNKNOWN_TYPE, derivedTypeName);
  }
  EdmEntityType type = derivedType.getBaseType();
  while (type != null) {
    if (type.getFullQualifiedName().equals(baseType.getFullQualifiedName())) {
      return derivedType;
    }
    type = type.getBaseType();
  }
  throw new SerializerException("Wrong base type",
      SerializerException.MessageKeys.WRONG_BASE_TYPE, derivedTypeName,
          baseType.getFullQualifiedName().getFullQualifiedNameAsString());
}
 
Example 3
Source File: ODataXmlSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
protected EdmEntityType resolveEntityType(final ServiceMetadata metadata, final EdmEntityType baseType,
    final String derivedTypeName) throws SerializerException {
  if (derivedTypeName == null ||
      baseType.getFullQualifiedName().getFullQualifiedNameAsString().equals(derivedTypeName)) {
    return baseType;
  }
  EdmEntityType derivedType = metadata.getEdm().getEntityType(new FullQualifiedName(derivedTypeName));
  if (derivedType == null) {
    throw new SerializerException("EntityType not found",
        SerializerException.MessageKeys.UNKNOWN_TYPE, derivedTypeName);
  }
  EdmEntityType type = derivedType.getBaseType();
  while (type != null) {
    if (type.getFullQualifiedName().getFullQualifiedNameAsString()
        .equals(baseType.getFullQualifiedName().getFullQualifiedNameAsString())) {
      return derivedType;
    }
    type = type.getBaseType();
  }
  throw new SerializerException("Wrong base type",
      SerializerException.MessageKeys.WRONG_BASE_TYPE, derivedTypeName, baseType
          .getFullQualifiedName().getFullQualifiedNameAsString());
}
 
Example 4
Source File: MetadataDocumentXmlSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void appendKey(final XMLStreamWriter writer, final EdmEntityType entityType) throws XMLStreamException {
  List<EdmKeyPropertyRef> keyPropertyRefs = entityType.getKeyPropertyRefs();
  if (keyPropertyRefs != null && !keyPropertyRefs.isEmpty()) {
    // Resolve Base Type key as it is shown in derived type
    EdmEntityType baseType = entityType.getBaseType();
    if (baseType != null && baseType.getKeyPropertyRefs() != null && !(baseType.getKeyPropertyRefs().isEmpty())) {
      return;
    }

    writer.writeStartElement(XML_KEY);
    for (EdmKeyPropertyRef keyRef : keyPropertyRefs) {
      writer.writeEmptyElement(XML_PROPERTY_REF);

      writer.writeAttribute(XML_NAME, keyRef.getName());

      if (keyRef.getAlias() != null) {
        writer.writeAttribute(XML_ALIAS, keyRef.getAlias());
      }
    }
    writer.writeEndElement();
  }
}
 
Example 5
Source File: EdmTypeValidator.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
      }
    }
  }

}
 
Example 6
Source File: MetadataDocumentJsonSerializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
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();
  }
}
 
Example 7
Source File: MetadataDocumentXmlSerializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
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();
  }
}
 
Example 8
Source File: AbstractUtility.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public List<EdmOperation> justInheritedOperationsBoundTo(final EdmEntityType entity) {
  final List<EdmOperation> result = new ArrayList<EdmOperation>();
  if (entity.getBaseType() != null) {
    result.addAll(getFunctionsBoundTo(entity.getBaseType().getName(), false));
    result.addAll(getActionsBoundTo(entity.getBaseType().getName(), false));
    result.addAll(justInheritedOperationsBoundTo(entity.getBaseType()));
  }

  return result;
}
 
Example 9
Source File: AbstractUtility.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Map<String, String> getEntityKeyType(final EdmEntityType entityType) {
  EdmEntityType baseType = entityType;
  while (CollectionUtils.isEmpty(baseType.getKeyPredicateNames()) && baseType.getBaseType() != null) {
    baseType = getEdmTypeInfo(baseType.getBaseType().getFullQualifiedName().toString()).getEntityType();
  }

  final Map<String, String> res = new LinkedHashMap<String, String>();
  for (EdmKeyPropertyRef pref : baseType.getKeyPropertyRefs()) {
    res.put(pref.getName(),
            getJavaType(pref.getProperty().getType().getFullQualifiedName().toString()));
  }

  return res;
}
 
Example 10
Source File: AbstractUtility.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void populateDescendants(final EdmTypeInfo base, final List<String> descendants) {
  for (Map.Entry<String, List<EdmEntityType>> entry : allEntityTypes.entrySet()) {
    for (EdmEntityType type : entry.getValue()) {
      if (type.getBaseType() != null
              && base.getFullQualifiedName().equals(type.getBaseType().getFullQualifiedName())) {

        final EdmTypeInfo entityTypeInfo = getEdmTypeInfo(type.getFullQualifiedName().toString());

        descendants.add(entityTypeInfo.getFullQualifiedName().toString());
        populateDescendants(entityTypeInfo, descendants);
      }
    }
  }
}
 
Example 11
Source File: OperationInvocationHandler.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private Map.Entry<URI, EdmOperation> getBoundOperation(final Operation operation, final List<String> parameterNames) {
  final ClientEntity entity = EntityInvocationHandler.class.cast(target).getEntity();
  final URI entityURI = EntityInvocationHandler.class.cast(target).getEntityURI();

  ClientOperation boundOp = entity.getOperation(operation.name());
  if (boundOp == null) {
    boundOp = entity.getOperation(new FullQualifiedName(targetFQN.getNamespace(), operation.name()).toString());
  }

  final boolean useOperationFQN = this.getClient().getConfiguration().isUseUrlOperationFQN();

  EdmEntityType entityType = getClient().getCachedEdm().getEntityType(entity.getTypeName());
  EdmEntityType baseType = entityType;
  while (boundOp == null && baseType != null) {
    // json minimal/none metadata doesn't return operations for entity, so here try creating it from Edm: 
    final EdmAction action = this.getClient().getCachedEdm().getBoundAction(
            new FullQualifiedName(targetFQN.getNamespace(), operation.name()),
            baseType.getFullQualifiedName(),
            false);

    if (action == null) {
      baseType = baseType.getBaseType();
    } else {
      boundOp = new ClientOperation();
      boundOp.setMetadataAnchor(action.getFullQualifiedName().toString());
      boundOp.setTitle(boundOp.getMetadataAnchor());
      boundOp.setTarget(URI.create(entityURI.toASCIIString() + "/"
              + (useOperationFQN ? action.getFullQualifiedName().toString() : operation.name())));
    }
  }

  baseType = entityType;
  while (boundOp == null && baseType != null) {
    // json minimal/none metadata doesn't return operations for entity, so here try creating it from Edm: 
    final EdmFunction func = this.getClient().getCachedEdm().getBoundFunction(
            new FullQualifiedName(targetFQN.getNamespace(), operation.name()), baseType.getFullQualifiedName(),
            false, parameterNames);

    if (func == null) {
      baseType = baseType.getBaseType();
    } else {
      boundOp = new ClientOperation();
      boundOp.setMetadataAnchor(func.getFullQualifiedName().toString());
      boundOp.setTitle(boundOp.getMetadataAnchor());
      boundOp.setTarget(URI.create(entityURI.toASCIIString() + "/"
              + (useOperationFQN ? func.getFullQualifiedName().toString() : operation.name())));
    }
  }
  if (boundOp == null) {
    throw new IllegalArgumentException(String.format("Could not find any matching operation '%s' bound to %s",
            operation.name(), entity.getTypeName()));
  }

  final FullQualifiedName operationFQN = boundOp.getTitle().indexOf('.') == -1
          ? new FullQualifiedName(targetFQN.getNamespace(), boundOp.getTitle())
          : new FullQualifiedName(boundOp.getTitle());

  EdmOperation edmOperation = null;
  while (edmOperation == null && entityType != null) {
    edmOperation = operation.type() == OperationType.FUNCTION
            ? getClient().getCachedEdm().getBoundFunction(
                    operationFQN, entityType.getFullQualifiedName(), false, parameterNames)
            : getClient().getCachedEdm().getBoundAction(
                    operationFQN, entityType.getFullQualifiedName(), false);
    if (entityType.getBaseType() != null) {
      entityType = entityType.getBaseType();
    }
  }

  if (edmOperation == null) {
    throw new IllegalArgumentException(String.format("Could not find any matching operation '%s' bound to %s",
            operation.name(), entity.getTypeName()));
  }

  return new AbstractMap.SimpleEntry<URI, EdmOperation>(boundOp.getTarget(), edmOperation);
}