use of org.apache.olingo.odata2.api.edm.EdmEntityContainer in project camel by apache.
the class Olingo2AppImpl method replaceContentId.
private static String replaceContentId(Edm edm, String entityReference, Map<String, String> contentIdMap) throws EdmException {
final int pathSeparator = entityReference.indexOf('/');
final StringBuilder referencedEntity;
if (pathSeparator == -1) {
referencedEntity = new StringBuilder(contentIdMap.get(entityReference));
} else {
referencedEntity = new StringBuilder(contentIdMap.get(entityReference.substring(0, pathSeparator)));
}
// create a dummy entity location by adding a dummy key predicate
// look for a Container name if available
String referencedEntityName = referencedEntity.toString();
final int containerSeparator = referencedEntityName.lastIndexOf('.');
final EdmEntityContainer entityContainer;
if (containerSeparator != -1) {
final String containerName = referencedEntityName.substring(0, containerSeparator);
referencedEntityName = referencedEntityName.substring(containerSeparator + 1);
entityContainer = edm.getEntityContainer(containerName);
if (entityContainer == null) {
throw new IllegalArgumentException("EDM does not have entity container " + containerName);
}
} else {
entityContainer = edm.getDefaultEntityContainer();
if (entityContainer == null) {
throw new IllegalArgumentException("EDM does not have a default entity container" + ", use a fully qualified entity set name");
}
}
final EdmEntitySet entitySet = entityContainer.getEntitySet(referencedEntityName);
final List<EdmProperty> keyProperties = entitySet.getEntityType().getKeyProperties();
if (keyProperties.size() == 1) {
referencedEntity.append("('dummy')");
} else {
referencedEntity.append("(");
for (EdmProperty keyProperty : keyProperties) {
referencedEntity.append(keyProperty.getName()).append('=').append("'dummy',");
}
referencedEntity.deleteCharAt(referencedEntity.length() - 1);
referencedEntity.append(')');
}
return pathSeparator == -1 ? referencedEntityName : referencedEntity.append(entityReference.substring(pathSeparator)).toString();
}
Aggregations