repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAUpdateResult.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAUpdateResult.java
package com.sap.olingo.jpa.processor.core.modify; public final record JPAUpdateResult(boolean wasCreate, Object modifiedEntity) {}
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAEntityBasedResult.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAEntityBasedResult.java
package com.sap.olingo.jpa.processor.core.modify; import java.util.List; import java.util.Map; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; public abstract class JPAEntityBasedResult extends JPATupleBasedResult { protected JPAEntityBasedResult(final JPAEntityType et, final Map<String, List<String>> requestHeaders) throws ODataJPAModelException { super(et, requestHeaders); } @Override protected String determineLocale(final Map<String, Object> descGetterMap, final JPAPath localeAttribute, final int index) throws ODataJPAProcessorException { final Object value = descGetterMap.get(localeAttribute.getPath().get(index).getInternalName()); if (localeAttribute.getPath().size() == index + 1 || value == null) { return (String) value; } else { final Map<String, Object> embeddedGetterMap = helper.buildGetterMap(value); return determineLocale(embeddedGetterMap, localeAttribute, index + 1); } } @Override protected Map<String, Object> entryAsMap(final Object entry) throws ODataJPAProcessorException { return helper.buildGetterMap(entry); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAMapBaseResult.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAMapBaseResult.java
package com.sap.olingo.jpa.processor.core.modify; import java.util.List; import java.util.Map; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; public abstract class JPAMapBaseResult extends JPATupleBasedResult { protected Map<String, Object> valuePairedResult; protected JPAMapBaseResult(final JPAEntityType et, final Map<String, List<String>> requestHeaders) throws ODataJPAModelException { super(et, requestHeaders); } @Override @SuppressWarnings("unchecked") protected String determineLocale(final Map<String, Object> descGetterMap, final JPAPath localeAttribute, final int index) throws ODataJPAProcessorException { final Object value = descGetterMap.get(localeAttribute.getPath().get(index).getInternalName()); if (localeAttribute.getPath().size() == index + 1 || value == null) { return (String) value; } else { return determineLocale((Map<String, Object>) value, localeAttribute, index + 1); } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAMapResult.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAMapResult.java
package com.sap.olingo.jpa.processor.core.modify; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import jakarta.persistence.Tuple; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPACollectionAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAElement; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.converter.JPAExpandResult; import com.sap.olingo.jpa.processor.core.converter.JPAResultConverter; import com.sap.olingo.jpa.processor.core.converter.JPATuple; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; import com.sap.olingo.jpa.processor.core.processor.JPARequestEntity; final class JPAMapResult extends JPAMapBaseResult { JPAMapResult(final JPAEntityType et, final Map<String, Object> jpaEntity, final Map<String, List<String>> requestHeaders, final JPAResultConverter converter) throws ODataJPAModelException, ODataApplicationException { super(et, requestHeaders); this.valuePairedResult = jpaEntity; this.result = createResult(); createChildren(converter); } @SuppressWarnings("unchecked") private void createChildren(final JPAResultConverter converter) throws ODataJPAModelException, ODataApplicationException { for (final JPAAssociationPath path : et.getAssociationPathList()) { final String pathPropertyName = path.getPath().get(0).getInternalName(); if (valuePairedResult.get(pathPropertyName) instanceof List) { children.put(path, new JPAMapNavigationLinkResult((JPAEntityType) path.getTargetType(), (List<JPARequestEntity>) valuePairedResult.get( pathPropertyName), requestHeaders, converter, getForeignKeyColumns(path))); } } for (final JPAPath path : et.getCollectionAttributesPath()) { Map<String, Object> attributes = valuePairedResult; for (final JPAElement element : path.getPath()) { final Object value = attributes.get(element.getInternalName()); if (element instanceof final JPAAttribute attribute && attribute.isComplex() && !(attribute.isCollection()) && value != null) { attributes = (Map<String, Object>) value; continue; } if (element instanceof final JPACollectionAttribute attribute && value != null) { final JPAAssociationPath assPath = attribute.asAssociation(); final JPAExpandResult child = new JPAMapCollectionResult(et, (Collection<?>) value, requestHeaders, attribute); child.convert(converter); children.put(assPath, child); } } } } private List<Tuple> createResult() throws ODataJPAProcessorException { final JPATuple tuple = new JPATuple(); final List<Tuple> tupleResult = new ArrayList<>(); for (final JPAPath path : pathList) { if (notContainsCollection(path)) convertPathToTuple(tuple, valuePairedResult, path, 0); } tupleResult.add(tuple); return tupleResult; } private List<JPAPath> getForeignKeyColumns(final JPAAssociationPath association) throws ODataJPAProcessorException { try { return association.getForeignKeyColumns(); } catch (final ODataJPAModelException e) { throw new ODataJPAProcessorException(ODataJPAProcessorException.MessageKeys.ATTRIBUTE_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR, e); } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAEntityCollectionResult.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAEntityCollectionResult.java
package com.sap.olingo.jpa.processor.core.modify; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; import jakarta.persistence.Tuple; import org.apache.olingo.server.api.ODataApplicationException; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPACollectionAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.converter.JPACollectionResult; import com.sap.olingo.jpa.processor.core.converter.JPAResultConverter; import com.sap.olingo.jpa.processor.core.converter.JPATuple; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; final class JPAEntityCollectionResult extends JPAEntityBasedResult implements JPACollectionResult { // JPACollectionQueryResult private Map<String, List<Object>> converted; private final JPAAssociationPath path; JPAEntityCollectionResult(final JPAEntityType et, final Collection<?> values, final Map<String, List<String>> requestHeaders, final JPACollectionAttribute attribute) throws ODataJPAModelException, ODataJPAProcessorException { super(et, requestHeaders); this.path = attribute.asAssociation(); result = convertToTuple(et, values, attribute); } private List<Tuple> convertToTuple(final JPAEntityType et, final Collection<?> values, final JPACollectionAttribute attribute) throws ODataJPAProcessorException, ODataJPAModelException { final List<Tuple> tupleList = new ArrayList<>(); for (final Object value : values) { final JPATuple tuple = new JPATuple(); if (attribute.isComplex()) { final Map<String, Object> embeddedGetterMap = helper.buildGetterMap(value); for (final JPAPath p : attribute.getStructuredType().getPathList()) convertPathToTuple(tuple, embeddedGetterMap, et.getPath(this.path.getAlias() + JPAPath.PATH_SEPARATOR + p.getAlias()), 1); } else { tuple.addElement(path.getAlias(), attribute.getType(), value); } tupleList.add(tuple); } return tupleList; } @Override public void convert(final JPAResultConverter converter) throws ODataApplicationException { converted = converter.getCollectionResult(this, Collections.emptySet()); } @Override public List<Object> getPropertyCollection(final String key) { return converted.get(ROOT_RESULT_KEY); } @Override public JPAAssociationPath getAssociation() { return path; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPACreateResultFactory.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPACreateResultFactory.java
package com.sap.olingo.jpa.processor.core.modify; import java.util.List; import java.util.Map; import org.apache.olingo.server.api.ODataApplicationException; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.converter.JPAExpandResult; import com.sap.olingo.jpa.processor.core.converter.JPAResultConverter; public final class JPACreateResultFactory { private final JPAResultConverter converter; public JPACreateResultFactory(final JPAResultConverter converter) { this.converter = converter; } @SuppressWarnings("unchecked") public JPAExpandResult getJPACreateResult(final JPAEntityType et, final Object result, final Map<String, List<String>> requestHeaders) throws ODataJPAModelException, ODataApplicationException { if (result instanceof Map<?, ?>) return new JPAMapResult(et, (Map<String, Object>) result, requestHeaders, converter); else return new JPAEntityResult(et, result, requestHeaders, converter); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAEntityResult.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAEntityResult.java
package com.sap.olingo.jpa.processor.core.modify; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import jakarta.persistence.Tuple; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPACollectionAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAElement; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.converter.JPAExpandResult; import com.sap.olingo.jpa.processor.core.converter.JPAResultConverter; import com.sap.olingo.jpa.processor.core.converter.JPATuple; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; /** * Provides an entity as tuple result. This is primarily done to reuse the existing tuple converter. * * @author Oliver Grande * */ final class JPAEntityResult extends JPAEntityBasedResult { private final Map<String, Object> valuePairedResult; JPAEntityResult(final JPAEntityType et, final Object jpaEntity, final Map<String, List<String>> requestHeaders, final JPAResultConverter converter) throws ODataJPAModelException, ODataApplicationException { super(et, requestHeaders); this.valuePairedResult = helper.buildGetterMap(jpaEntity); this.result = createResult(); createChildren(converter); } private void createChildren(final JPAResultConverter converter) throws ODataJPAModelException, ODataApplicationException { for (final JPAAssociationPath path : et.getAssociationPathList()) { final String pathPropertyName = path.getPath().get(0).getInternalName(); final Object value = valuePairedResult.get(pathPropertyName); if (value instanceof Collection && !((Collection<?>) value).isEmpty()) { children.put(path, new JPAEntityNavigationLinkResult((JPAEntityType) path.getTargetType(), (Collection<?>) value, requestHeaders, converter, getForeignKeyColumns(path))); } } for (final JPAPath path : et.getCollectionAttributesPath()) { Map<String, Object> embeddedGetterMap = valuePairedResult; for (final JPAElement element : path.getPath()) { final Object value = embeddedGetterMap.get(element.getInternalName()); if (element instanceof final JPAAttribute attribute && attribute.isComplex() && !(attribute.isCollection()) && value != null) { embeddedGetterMap = helper.buildGetterMap(value); continue; } if (element instanceof final JPACollectionAttribute attribute && value != null) { final JPAAssociationPath assPath = attribute.asAssociation(); final JPAExpandResult child = new JPAEntityCollectionResult(et, (Collection<?>) value, requestHeaders, attribute); child.convert(converter); children.put(assPath, child); } } } } private List<Tuple> createResult() throws ODataJPAProcessorException { final JPATuple tuple = new JPATuple(); final List<Tuple> tupleResult = new ArrayList<>(); for (final JPAPath path : pathList) { if (notContainsCollection(path)) convertPathToTuple(tuple, valuePairedResult, path, 0); } tupleResult.add(tuple); return tupleResult; } private List<JPAPath> getForeignKeyColumns(final JPAAssociationPath association) throws ODataJPAProcessorException { try { return association.getForeignKeyColumns(); } catch (final ODataJPAModelException e) { throw new ODataJPAProcessorException(ODataJPAProcessorException.MessageKeys.ATTRIBUTE_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR, e); } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPACreateResult.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPACreateResult.java
package com.sap.olingo.jpa.processor.core.modify; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import javax.annotation.Nonnull; import org.apache.olingo.server.api.ODataApplicationException; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPADescriptionAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAElement; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.api.JPAODataPageExpandInfo; import com.sap.olingo.jpa.processor.core.converter.JPAExpandResult; import com.sap.olingo.jpa.processor.core.converter.JPAResultConverter; import com.sap.olingo.jpa.processor.core.converter.JPATuple; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; import com.sap.olingo.jpa.processor.core.query.ExpressionUtility; abstract class JPACreateResult implements JPAExpandResult { protected final JPAEntityType et; protected final Map<JPAAssociationPath, JPAExpandResult> children; protected final List<JPAPath> pathList; protected final Locale locale; protected final JPAConversionHelper helper; protected final Map<String, List<String>> requestHeaders; JPACreateResult(final JPAEntityType et, final Map<String, List<String>> requestHeaders) throws ODataJPAModelException { this.et = et; this.helper = new JPAConversionHelper(); this.children = new HashMap<>(0); this.pathList = et.getPathList(); this.locale = ExpressionUtility.determineFallbackLocale(requestHeaders); this.requestHeaders = requestHeaders; } @Override public void convert(final JPAResultConverter converter) throws ODataApplicationException { // No implementation required for CUD operations } @Override public JPAExpandResult getChild(final JPAAssociationPath associationPath) { return children.get(associationPath); } @Override public Map<JPAAssociationPath, JPAExpandResult> getChildren() { return children; } @Override public Long getCount(final String key) { return null; } @Override public JPAEntityType getEntityType() { return et; } @Override public boolean hasCount() { return false; } @Override public String getSkipToken(@Nonnull final List<JPAODataPageExpandInfo> expandInfo) { // No paging for modifying requests return null; } @Override public Collection<JPAPath> getRequestedSelection() { return List.of(); } protected void addValueToTuple(final JPATuple tuple, final JPAPath path, final int index, final Object value) throws ODataJPAProcessorException { if (path.getPath().get(index) instanceof final JPADescriptionAttribute descriptionAttribute) { @SuppressWarnings("unchecked") final Collection<Object> values = (Collection<Object>) value; if (values != null) { for (final Object entry : values) { final Map<String, Object> descriptionGetterMap = entryAsMap(entry); final String providedLocale = determineLocale(descriptionGetterMap, descriptionAttribute); if (locale.getLanguage().equals(providedLocale) || locale.toString().equals(providedLocale)) { final Object description = descriptionGetterMap.get(descriptionAttribute.getDescriptionAttribute() .getInternalName()); tuple.addElement(path.getAlias(), path.getLeaf().getType(), description); break; } } } else { tuple.addElement(path.getAlias(), path.getLeaf().getType(), null); } } else { tuple.addElement(path.getAlias(), path.getLeaf().getType(), value); } } protected void convertPathToTuple(final JPATuple tuple, final Map<String, Object> jpaEntity, final JPAPath path, final int index) throws ODataJPAProcessorException { final Object value = jpaEntity.get(path.getPath().get(index).getInternalName()); if (path.getPath().size() == index + 1 || value == null) { addValueToTuple(tuple, path, index, value); } else { final Map<String, Object> embeddedGetterMap = entryAsMap(value); convertPathToTuple(tuple, embeddedGetterMap, path, index + 1); } } protected abstract String determineLocale(final Map<String, Object> descriptionGetterMap, JPAPath localeAttribute, final int index) throws ODataJPAProcessorException; @SuppressWarnings("unchecked") protected Map<String, Object> entryAsMap(final Object entry) throws ODataJPAProcessorException { // NOSONAR return (Map<String, Object>) entry; } protected boolean notContainsCollection(final JPAPath path) { for (final JPAElement element : path.getPath()) if (element instanceof final JPAAttribute attribute && attribute.isCollection()) return false; return true; } private String determineLocale(final Map<String, Object> descriptionGetterMap, final JPADescriptionAttribute descriptionAttribute) throws ODataJPAProcessorException { return determineLocale(descriptionGetterMap, descriptionAttribute.getLocaleFieldName(), 0); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAMapNavigationLinkResult.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAMapNavigationLinkResult.java
package com.sap.olingo.jpa.processor.core.modify; import static java.util.stream.Collectors.joining; import java.util.ArrayList; import java.util.List; import java.util.Map; import jakarta.persistence.Tuple; import org.apache.olingo.server.api.ODataApplicationException; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.converter.JPAResultConverter; import com.sap.olingo.jpa.processor.core.processor.JPARequestEntity; final class JPAMapNavigationLinkResult extends JPANavigationLinkResult { public JPAMapNavigationLinkResult(final JPAEntityType targetType, final List<JPARequestEntity> entities, final Map<String, List<String>> requestHeaders, final JPAResultConverter converter, final List<JPAPath> foreignKey) throws ODataJPAModelException, ODataApplicationException { super(targetType, requestHeaders); for (final JPARequestEntity entity : entities) { final var key = buildConcatenatedForeignKey(foreignKey, entity.getData()); final List<Tuple> part = result.computeIfAbsent(key, k -> new ArrayList<Tuple>()); part.add(new JPAMapResult(entity.getEntityType(), entity.getData(), requestHeaders, converter) .getResult(ROOT_RESULT_KEY).get(0)); } } private String buildConcatenatedForeignKey(final List<JPAPath> foreignKey, final Map<String, Object> properties) { return foreignKey.stream() .map(column -> (properties.get(column.getLeaf().getInternalName())).toString()) .collect(joining(JPAPath.PATH_SEPARATOR)); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPATupleBasedResult.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPATupleBasedResult.java
package com.sap.olingo.jpa.processor.core.modify; import java.util.HashMap; import java.util.List; import java.util.Map; import jakarta.persistence.Tuple; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public abstract class JPATupleBasedResult extends JPACreateResult { protected List<Tuple> result; protected JPATupleBasedResult(final JPAEntityType et, final Map<String, List<String>> requestHeaders) throws ODataJPAModelException { super(et, requestHeaders); } @Override public List<Tuple> getResult(final String key) { return result; } @Override public List<Tuple> removeResult(final String key) { final var cache = result; result = null; return cache; } @Override public Map<String, List<Tuple>> getResults() { final Map<String, List<Tuple>> results = new HashMap<>(1); results.put(ROOT_RESULT_KEY, result); return results; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAConversionHelper.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/modify/JPAConversionHelper.java
package com.sap.olingo.jpa.processor.core.modify; import static com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException.MessageKeys.ATTRIBUTE_NOT_FOUND; import static com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException.MessageKeys.ENUMERATION_UNKNOWN; import static com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException.MessageKeys.PARAMETER_NULL; import static org.apache.olingo.commons.api.data.ValueType.ENUM; import static org.apache.olingo.commons.api.http.HttpStatusCode.BAD_REQUEST; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Nonnull; import jakarta.persistence.AttributeConverter; import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Parameter; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.edm.EdmEntitySet; import org.apache.olingo.commons.api.edm.EdmProperty; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.deserializer.DeserializerException; import org.apache.olingo.server.api.deserializer.ODataDeserializer; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.uri.UriParameter; import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourceProperty; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEnumerationAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAServiceDocument; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAStructuredType; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAFilterException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException.MessageKeys; import com.sap.olingo.jpa.processor.core.query.EdmBindingTargetInfo; import com.sap.olingo.jpa.processor.core.query.ExpressionUtility; import com.sap.olingo.jpa.processor.core.query.Utility; /** * Helper method for modifying requests. * <p> * Mainly created to increase testability * @author Oliver Grande * */ public class JPAConversionHelper { private final Map<Object, Map<String, Object>> getterBuffer; public static Object convertParameter(final Parameter param, final JPAServiceDocument sd) throws ODataJPAModelException, ODataJPAProcessorException { if (param.getValueType() == ENUM) { final JPAEnumerationAttribute enumType = sd.getEnumType(param.getType()); if (enumType == null) throw new ODataJPAProcessorException(ENUMERATION_UNKNOWN, BAD_REQUEST, param.getName()); return enumType.enumOf((Number) param.getValue()); } else { return param.getValue(); } } public JPAConversionHelper() { super(); this.getterBuffer = new HashMap<>(); } /** * Creates a map of attribute name and the return value of there getter method. * <p> * It is assumed that the method name is composed from <i>get</> and the * name of the attribute and that the attribute name starts with a lower case * letter. * @param instance * @return * @throws ODataJPAProcessorException */ public Map<String, Object> buildGetterMap(final Object instance) throws ODataJPAProcessorException { if (instance != null) { final ODataJPAProcessorException[] exception = { null }; final Map<String, Object> getterMap = getterBuffer.computeIfAbsent(instance, k -> { try { return this.determineGetter(instance); } catch (final ODataJPAProcessorException e) { exception[0] = e; return new HashMap<>(1); } }); if (exception[0] == null) return getterMap; else throw exception[0]; } else { throw new ODataJPAProcessorException(PARAMETER_NULL, HttpStatusCode.INTERNAL_SERVER_ERROR); } } /** * Converts the payload of a request into the corresponding odata entity * @param odata * @param request * @param requestFormat * @param uriResourceParts * @return * @throws ODataJPAProcessorException */ public Entity convertInputStream(final OData odata, final ODataRequest request, final ContentType requestFormat, final List<UriResource> uriResourceParts) throws ODataJPAProcessorException { final InputStream requestInputStream = request.getBody(); final EdmBindingTargetInfo targetEntityInfo = Utility.determineModifyEntitySetAndKeys(uriResourceParts); try { final ODataDeserializer deserializer = createDeserializer(odata, requestFormat, request.getHeaders(HttpHeader.ODATA_VERSION)); final UriResource lastPart = uriResourceParts.get(uriResourceParts.size() - 1); if (lastPart instanceof final UriResourceProperty lastResourceProperty) { // Convert requests on property level into request on entity level final Entity requestEntity = new Entity(); final String startProperty = targetEntityInfo.getNavigationPath().split(JPAPath.PATH_SEPARATOR)[0]; int i = uriResourceParts.size() - 1; for (; i > 0; i--) { if (uriResourceParts.get(i) instanceof final UriResourceProperty resourceProperty && resourceProperty.getProperty().getName().equals(startProperty)) { break; } } List<Property> properties = requestEntity.getProperties(); for (int j = i; j < uriResourceParts.size() - 1; j++) { // NO $value supported yet if (!(uriResourceParts.get(i) instanceof UriResourceProperty)) { break; } final EdmProperty edmProperty = ((UriResourceProperty) uriResourceParts.get(i)).getProperty(); final Property intermediateProperty = new Property(); intermediateProperty.setType(edmProperty.getType().getFullQualifiedName().getFullQualifiedNameAsString()); intermediateProperty.setName(edmProperty.getName()); intermediateProperty.setValue(ValueType.COMPLEX, new ComplexValue()); properties.add(intermediateProperty); properties = ((ComplexValue) intermediateProperty.getValue()).getValue(); } properties.add(deserializer.property(requestInputStream, lastResourceProperty.getProperty()).getProperty()); return requestEntity; } else { return deserializer.entity(requestInputStream, targetEntityInfo.getTargetEdmBindingTarget().getEntityType()) .getEntity(); } } catch (final DeserializerException e) { throw new ODataJPAProcessorException(e, HttpStatusCode.BAD_REQUEST); } } /** * * @param odata * @param request * @param edmEntitySet * @param et * @param newPOJO * @return * @throws SerializerException * @throws ODataJPAProcessorException */ @SuppressWarnings("unchecked") public String convertKeyToLocal(final OData odata, final ODataRequest request, final EdmEntitySet edmEntitySet, final JPAEntityType et, final Object newPOJO) throws SerializerException, ODataJPAProcessorException { if (newPOJO instanceof Map<?, ?>) return convertKeyToLocalMap(odata, request, edmEntitySet, et, (Map<String, Object>) newPOJO); else return convertKeyToLocalEntity(odata, request, edmEntitySet, et, newPOJO); } /** * Creates nested map of attributes and there (new) values. Primitive values are instances of e.g. Integer. Embedded * Types are returned as maps. * * @param odata * @param st * @param odataProperties * @return * @throws ODataJPAProcessException */ @SuppressWarnings("unchecked") public Map<String, Object> convertProperties(final OData odata, final JPAStructuredType st, final List<Property> odataProperties) throws ODataJPAProcessException { final Map<String, Object> jpaAttributes = new HashMap<>(); String internalName = null; Object jpaAttribute = null; JPAPath path; for (final Property odataProperty : odataProperties) { try { path = st.getPath(odataProperty.getName()); } catch (final ODataJPAModelException e) { throw new ODataJPAProcessorException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } if (path != null) { switch (odataProperty.getValueType()) { case COMPLEX: try { final String name = path.getPath().get(0).getInternalName(); final JPAStructuredType a = st.getAttribute(name) .orElseThrow(() -> new ODataJPAProcessorException(ATTRIBUTE_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR, name)) .getStructuredType(); internalName = name; jpaAttribute = convertProperties(odata, a, ((ComplexValue) odataProperty.getValue()).getValue()); } catch (final ODataJPAModelException e) { throw new ODataJPAProcessorException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } break; case PRIMITIVE, ENUM: final JPAAttribute attribute = path.getLeaf(); internalName = attribute.getInternalName(); jpaAttribute = processAttributeConverter(odataProperty.getValue(), attribute); break; case COLLECTION_PRIMITIVE, COLLECTION_ENUM: final JPAAttribute attribute2 = path.getLeaf(); internalName = attribute2.getInternalName(); jpaAttribute = new ArrayList<>(); for (final Object property : (List<?>) odataProperty.getValue()) ((List<Object>) jpaAttribute).add(processAttributeConverter(property, attribute2)); break; case COLLECTION_COMPLEX: final String name = path.getPath().get(0).getInternalName(); jpaAttribute = new ArrayList<>(); try { final JPAStructuredType a = st.getAttribute(name) .orElseThrow(() -> new ODataJPAProcessorException(ATTRIBUTE_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR, name)) .getStructuredType(); internalName = name; for (final ComplexValue property : (List<ComplexValue>) odataProperty.getValue()) ((List<Object>) jpaAttribute).add(convertProperties(odata, a, property.getValue())); } catch (final ODataJPAModelException e) { throw new ODataJPAProcessorException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } break; default: throw new ODataJPAProcessorException(MessageKeys.NOT_SUPPORTED_PROP_TYPE, HttpStatusCode.NOT_IMPLEMENTED, odataProperty.getValueType().name()); } jpaAttributes.put(internalName, jpaAttribute); } else { throw new ODataJPAProcessorException(MessageKeys.NOT_SUPPORTED_PROP_TYPE, HttpStatusCode.NOT_IMPLEMENTED, odataProperty.getValueType().name()); } } return jpaAttributes; } /** * * @param keyPredicates * @return * @throws ODataJPAFilterException * @throws ODataJPAProcessorException */ public Map<String, Object> convertUriKeys(final OData odata, final JPAStructuredType st, final List<UriParameter> keyPredicates) throws ODataJPAFilterException, ODataJPAProcessorException { final Map<String, Object> result = new HashMap<>(keyPredicates.size()); String internalName; for (final UriParameter key : keyPredicates) { try { final JPAAttribute attribute = getJPAPath(st, key.getName()).getLeaf(); internalName = attribute.getInternalName(); final Object jpaAttribute = ExpressionUtility.convertValueOnAttribute(odata, attribute, key.getText(), true); result.put(internalName, jpaAttribute); } catch (final ODataJPAModelException e) { throw new ODataJPAProcessorException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } } return result; } @Nonnull private JPAPath getJPAPath(final JPAStructuredType st, final String name) throws ODataJPAModelException, ODataJPAProcessorException { final var jpaPath = st.getPath(name); if (jpaPath != null) return jpaPath; else throw new ODataJPAProcessorException(ATTRIBUTE_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); } /** * Like {@link #buildGetterMap}, but without buffer * @param instance * @return * @throws ODataJPAProcessorException */ public Map<String, Object> determineGetter(final Object instance) throws ODataJPAProcessorException { Map<String, Object> getterMap; getterMap = new HashMap<>(); final Method[] methods = instance.getClass().getMethods(); for (final Method meth : methods) { final String methodName = meth.getName(); if (methodName.substring(0, 3).equals("get") && methodName.length() > 3) { final String attributeName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4); try { final Object value = meth.invoke(instance); getterMap.put(attributeName, value); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new ODataJPAProcessorException(MessageKeys.ATTRIBUTE_RETRIEVAL_FAILED, HttpStatusCode.INTERNAL_SERVER_ERROR, e, attributeName); } } } return getterMap; } @SuppressWarnings("unchecked") public <S, T> Object processAttributeConverter(final Object value, final JPAAttribute attribute) { Object jpaAttribute; if (attribute.getConverter() != null) { final AttributeConverter<T, S> converter = attribute.getConverter(); jpaAttribute = converter.convertToEntityAttribute((S) value); } else if (attribute.isEnum()) { jpaAttribute = findEnumConstantsByOrdinal(attribute.getType().getEnumConstants(), value); } else { jpaAttribute = value; } return jpaAttribute; } private void collectKeyProperties(final Map<String, Object> newPOJO, final List<JPAPath> keyPath, final List<Property> properties) throws ODataJPAProcessorException, ODataJPAModelException { if (keyPath.size() > 1) { for (final JPAPath key : keyPath) { final Object keyElement = newPOJO.get(key.getLeaf().getInternalName()); final Property property = new Property(null, key.getLeaf().getExternalName()); property.setValue(ValueType.PRIMITIVE, keyElement); properties.add(property); } } else { final JPAPath key = keyPath.get(0); if (key.getLeaf().isComplex()) { // EmbeddedId @SuppressWarnings("unchecked") final Map<String, Object> embeddedId = (Map<String, Object>) newPOJO.get(key.getLeaf().getInternalName()); collectKeyProperties(embeddedId, key.getLeaf().getStructuredType().getPathList(), properties); } else { final Property property = new Property(null, key.getLeaf().getExternalName()); property.setValue(ValueType.PRIMITIVE, newPOJO.get(key.getLeaf().getInternalName())); properties.add(property); } } } private void collectKeyProperties(final Object newPOJO, final List<JPAPath> keyPath, final List<Property> properties) throws ODataJPAProcessorException, ODataJPAModelException { final Map<String, Object> getter = buildGetterMap(newPOJO); if (keyPath.size() > 1) { for (final JPAPath key : keyPath) { final Property property = new Property(null, key.getLeaf().getExternalName()); property.setValue(ValueType.PRIMITIVE, getter.get(key.getLeaf().getInternalName())); properties.add(property); } } else { final JPAPath key = keyPath.get(0); if (key.getLeaf().isComplex()) { // EmbeddedId final Object embeddedId = getter.get(key.getLeaf().getInternalName()); collectKeyProperties(embeddedId, key.getLeaf().getStructuredType().getPathList(), properties); } else { final Property property = new Property(null, key.getLeaf().getExternalName()); property.setValue(ValueType.PRIMITIVE, getter.get(key.getLeaf().getInternalName())); properties.add(property); } } } private String convertKeyToLocalEntity(final OData odata, final ODataRequest request, final EdmEntitySet edmEntitySet, final JPAEntityType et, final Object newPOJO) throws SerializerException, ODataJPAProcessorException { final Entity createdEntity = new Entity(); try { final List<JPAPath> keyPath = et.getKeyPath(); final List<Property> properties = createdEntity.getProperties(); collectKeyProperties(newPOJO, keyPath, properties); } catch (final ODataJPAModelException e) { throw new ODataJPAProcessorException(e, HttpStatusCode.BAD_REQUEST); } return request.getRawBaseUri() + '/' + odata.createUriHelper().buildCanonicalURL(edmEntitySet, createdEntity); } private String convertKeyToLocalMap(final OData odata, final ODataRequest request, final EdmEntitySet edmEntitySet, final JPAEntityType et, final Map<String, Object> newPOJO) throws SerializerException, ODataJPAProcessorException { final Entity createdEntity = new Entity(); try { final List<Property> properties = createdEntity.getProperties(); final List<JPAPath> keyPath = et.getKeyPath(); collectKeyProperties(newPOJO, keyPath, properties); } catch (final ODataJPAModelException e) { throw new ODataJPAProcessorException(e, HttpStatusCode.BAD_REQUEST); } return request.getRawBaseUri() + '/' + odata.createUriHelper().buildCanonicalURL(edmEntitySet, createdEntity); } private ODataDeserializer createDeserializer(final OData odata, final ContentType requestFormat, final List<String> version) throws DeserializerException { return odata.createDeserializer(requestFormat, version); } private <T> Object findEnumConstantsByOrdinal(final T[] enumConstants, final Object value) { for (int i = 0; i < enumConstants.length; i++) { if (((Enum<?>) enumConstants[i]).ordinal() == (Integer) value) return enumConstants[i]; } return null; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPAExpandResult.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPAExpandResult.java
package com.sap.olingo.jpa.processor.core.converter; import java.util.Collection; import java.util.List; import java.util.Map; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import jakarta.persistence.Tuple; import org.apache.olingo.server.api.ODataApplicationException; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.processor.core.api.JPAODataPageExpandInfo; public interface JPAExpandResult { // NOSONAR String ROOT_RESULT_KEY = "root"; @CheckForNull JPAExpandResult getChild(final JPAAssociationPath associationPath); Map<JPAAssociationPath, JPAExpandResult> getChildren(); @CheckForNull Long getCount(final String string); @Nonnull JPAEntityType getEntityType(); List<Tuple> getResult(final String key); List<Tuple> removeResult(final String key); Map<String, List<Tuple>> getResults(); boolean hasCount(); void convert(final JPAResultConverter converter) throws ODataApplicationException; @CheckForNull String getSkipToken(@Nonnull final List<JPAODataPageExpandInfo> newInfo); Collection<JPAPath> getRequestedSelection(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPAEntityResultConverter.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPAEntityResultConverter.java
package com.sap.olingo.jpa.processor.core.converter; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; import java.net.URISyntaxException; import java.util.List; import java.util.Map; import javax.annotation.CheckForNull; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.uri.UriHelper; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAElement; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAServiceDocument; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAStructuredType; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.api.JPAODataEtagHelper; import com.sap.olingo.jpa.processor.core.exception.ODataJPAQueryException; import com.sap.olingo.jpa.processor.core.serializer.JPAEntityCollection; import com.sap.olingo.jpa.processor.core.serializer.JPAEntityCollectionExtension; public class JPAEntityResultConverter extends JPAStructuredResultConverter { private final EdmEntityType edmEntityType; private final UriHelper odataUriHelper; private final JPAODataEtagHelper etagHelper; public JPAEntityResultConverter(final UriHelper uriHelper, final JPAServiceDocument sd, final List<?> jpaQueryResult, final EdmEntityType returnType, final JPAODataEtagHelper etagHelper) throws ODataJPAModelException { super(jpaQueryResult, sd.getEntity(returnType)); this.edmEntityType = returnType; this.odataUriHelper = uriHelper; this.etagHelper = etagHelper; } @Override public JPAEntityCollectionExtension getResult() throws ODataApplicationException, SerializerException, URISyntaxException { final JPAEntityCollection odataEntityCollection = new JPAEntityCollection(); final List<Entity> odataResults = odataEntityCollection.getEntities(); for (final Object row : jpaQueryResult) { final Entity odataEntity = new Entity(); odataEntity.setType(this.jpaTopLevelType.getExternalFQN().getFullQualifiedNameAsString()); final List<Property> properties = odataEntity.getProperties(); convertProperties(row, properties, jpaTopLevelType); odataEntity.setETag(createEtag(row, jpaTopLevelType)); odataEntity.setId(new URI(odataUriHelper.buildKeyPredicate(edmEntityType, odataEntity))); odataResults.add(odataEntity); } return odataEntityCollection; } @CheckForNull private String createEtag(final Object row, final JPAStructuredType jpaType) throws ODataJPAQueryException { if (jpaType instanceof final JPAEntityType et) { try { if (et.hasEtag()) { Object value = row; for (final JPAElement part : et.getEtagPath().getPath()) { final Map<String, Method> methodMap = getMethods(value.getClass()); final Method getMethod = getGetter(part.getInternalName(), methodMap); value = getMethod.invoke(value); } return etagHelper.asEtag(et, value); } } catch (final ODataJPAModelException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new ODataJPAQueryException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } } return null; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPACollectionResult.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPACollectionResult.java
package com.sap.olingo.jpa.processor.core.converter; import java.util.Collection; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationPath; public interface JPACollectionResult extends JPAExpandResult { /** * Returns the result of a query for a collection property, which is either a list of attributes e.g. Integer for * primitive properties or a list of ComplexValues * @param key * @return */ public Collection<Object> getPropertyCollection(final String key); public JPAAssociationPath getAssociation(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPAStructuredResultConverter.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPAStructuredResultConverter.java
package com.sap.olingo.jpa.processor.core.converter; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import jakarta.persistence.AttributeConverter; import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.serializer.SerializerException; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAStructuredType; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.metadata.core.edm.mapper.impl.JPADefaultEdmNameBuilder; import com.sap.olingo.jpa.processor.core.exception.ODataJPAQueryException; /** * Abstract super class to converts a list of JPA POJOs into Olingo format. The POJOs have to have * @author Oliver Grande * */ public abstract class JPAStructuredResultConverter { public static final String ACCESS_MODIFIER_GET = "get"; public static final String ACCESS_MODIFIER_SET = "set"; public static final String ACCESS_MODIFIER_IS = "is"; private static final Map<String, HashMap<String, Method>> METHOD_BUFFER = new HashMap<>(); protected final List<?> jpaQueryResult; protected final JPAStructuredType jpaTopLevelType; protected JPAStructuredResultConverter(final List<?> jpaQueryResult, final JPAStructuredType jpaStructuredType) { super(); this.jpaQueryResult = jpaQueryResult; this.jpaTopLevelType = jpaStructuredType; } public abstract Object getResult() throws ODataApplicationException, SerializerException, URISyntaxException; protected Map<String, Method> getMethods(final Class<?> clazz) { HashMap<String, Method> methods = METHOD_BUFFER.get(clazz.getName()); if (methods == null) { methods = new HashMap<>(); final Method[] allMethods = clazz.getMethods(); for (final Method m : allMethods) { if (!m.getReturnType().getName().equalsIgnoreCase("void") && Modifier.isPublic(m.getModifiers())) methods.put(m.getName(), m); } METHOD_BUFFER.put(clazz.getName(), methods); } return methods; } protected void convertProperties(final Object row, final List<Property> properties, final JPAStructuredType jpaStructuredType) throws ODataJPAQueryException { List<JPAAttribute> attributeList; final Map<String, Method> methodMap = getMethods(jpaStructuredType.getTypeClass()); try { attributeList = jpaStructuredType.getAttributes(); } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } for (final JPAAttribute attribute : attributeList) { final String attributeName = attribute.getInternalName(); if (attribute.isTransient()) continue; final Method getMethod = getGetter(attributeName, methodMap); try { if (attribute.isCollection()) { convertCollectionProperty(row, properties, attribute, getMethod); } else if (attribute.isComplex()) { convertComplexProperty(row, properties, attribute, getMethod); } else { convertPrimitiveProperty(row, properties, attribute, getMethod); } } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | ODataJPAModelException e) { throw new ODataJPAQueryException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } } } @SuppressWarnings("unchecked") private <T, S> void convertPrimitiveProperty(final Object row, final List<Property> properties, final JPAAttribute attribute, final Method getMethod) throws IllegalAccessException, InvocationTargetException { if (row != null) { Object odataValue = getMethod.invoke(row); if (attribute.getConverter() != null) { final AttributeConverter<T, S> converter = attribute.getConverter(); odataValue = converter.convertToDatabaseColumn((T) odataValue); } properties.add(new Property( attribute.getExternalFQN().getFullQualifiedNameAsString(), attribute.getExternalName(), ValueType.PRIMITIVE, odataValue)); } else { properties.add(new Property( attribute.getExternalFQN().getFullQualifiedNameAsString(), attribute.getExternalName(), ValueType.PRIMITIVE, null)); } } private void convertComplexProperty(final Object row, final List<Property> properties, final JPAAttribute attribute, final Method getMethod) throws ODataJPAModelException, ODataJPAQueryException, IllegalAccessException, InvocationTargetException { final var complexResult = getMethod.invoke(row); if (complexResult != null) { final ComplexValue complexValue = new ComplexValue(); properties.add(new Property( attribute.getStructuredType().getExternalFQN().getFullQualifiedNameAsString(), attribute.getExternalName(), ValueType.COMPLEX, complexValue)); final List<Property> values = complexValue.getValue(); convertProperties(complexResult, values, attribute.getStructuredType()); } } private void convertCollectionProperty(final Object row, final List<Property> properties, final JPAAttribute attribute, final Method getMethod) throws IllegalAccessException, InvocationTargetException, ODataJPAQueryException, ODataJPAModelException { final Collection<?> odataValue = (Collection<?>) getMethod.invoke(row); final List<Object> collection = new ArrayList<>(); if (attribute.isComplex() && odataValue != null) { for (final Object element : odataValue) { final ComplexValue values = new ComplexValue(); convertProperties(element, values.getValue(), attribute.getStructuredType()); collection.add(values); } } else if (odataValue != null) { collection.addAll(odataValue); } properties.add(new Property( attribute.getExternalFQN().getFullQualifiedNameAsString(), attribute.getExternalName(), attribute.isComplex() ? ValueType.COLLECTION_COMPLEX : ValueType.COLLECTION_PRIMITIVE, collection)); } Method getGetter(final String attributeName, final Map<String, Method> methodMap) throws ODataJPAQueryException { final String getterName = ACCESS_MODIFIER_GET + JPADefaultEdmNameBuilder.firstToUpper(attributeName); if (methodMap.get(getterName) == null) throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_ACCESS_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR, attributeName); Method getMethod; getMethod = methodMap.get(getterName); return getMethod; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPARowConverter.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPARowConverter.java
package com.sap.olingo.jpa.processor.core.converter; import java.util.Collection; import java.util.List; import jakarta.persistence.Tuple; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.server.api.ODataApplicationException; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.processor.core.api.JPAODataPageExpandInfo; public interface JPARowConverter { Entity convertRow(JPAEntityType rowEntity, Tuple row, Collection<JPAPath> requestedSelection, List<JPAODataPageExpandInfo> expandInfo, JPAExpandResult jpaResult) throws ODataApplicationException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPATupleCollectionConverter.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPATupleCollectionConverter.java
package com.sap.olingo.jpa.processor.core.converter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; import jakarta.persistence.AttributeConverter; import jakarta.persistence.Tuple; import jakarta.persistence.TupleElement; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.uri.UriHelper; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransientPropertyCalculator; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPACollectionAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAServiceDocument; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAStructuredType; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.api.JPAODataPageExpandInfo; import com.sap.olingo.jpa.processor.core.api.JPAODataRequestContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAQueryException; import com.sap.olingo.jpa.processor.core.query.JPAExpandQueryResult; import com.sap.olingo.jpa.processor.core.serializer.JPAEntityCollectionExtension; public class JPATupleCollectionConverter extends JPATupleResultConverter { private static final Log LOGGER = LogFactory.getLog(JPATupleCollectionConverter.class); public JPATupleCollectionConverter(final JPAServiceDocument sd, final UriHelper uriHelper, final ServiceMetadata serviceMetadata, final JPAODataRequestContextAccess requestContext) { super(sd, uriHelper, serviceMetadata, requestContext); } @Override public Map<String, List<Object>> getResult(final JPAExpandResult dbResult, final Collection<JPAPath> requestedSelection) throws ODataApplicationException { jpaQueryResult = dbResult; final JPACollectionResult jpaResult = (JPACollectionResult) dbResult; final Map<String, List<Tuple>> childResult = jpaResult.getResults(); final Map<String, List<Object>> result = new HashMap<>(childResult.size()); try { final JPAStructuredType st = determineCollectionRoot(jpaResult.getEntityType(), jpaResult.getAssociation() .getPath()); final String prefix = determinePrefix(jpaResult.getAssociation().getAlias()); for (final Entry<String, List<Tuple>> tuple : childResult.entrySet()) { result.put(tuple.getKey(), getResult(requestedSelection, jpaResult.getAssociation(), st, prefix, tuple.getValue())); } } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_CONV_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e); } finally { childResult.replaceAll((k, v) -> null); } return result; } public List<Object> getResult(final Collection<JPAPath> requestedSelection, final JPAAssociationPath jpaAssociationPath, final JPAStructuredType st, final String prefix, final List<Tuple> rows) throws ODataJPAModelException, ODataApplicationException { if (jpaAssociationPath.getLeaf().isTransient()) { return convertTransientCollection(jpaAssociationPath.getLeaf(), rows); } else { return convertPersistentCollection(jpaAssociationPath, st, prefix, rows, requestedSelection, Collections.emptyList()); } } @Override public Map<String, List<Object>> getCollectionResult(final JPACollectionResult jpaResult, final Collection<JPAPath> requestedSelection) throws ODataApplicationException { return Map.of(); } @Override public JPAEntityCollectionExtension getResult(final JPAExpandQueryResult jpaExpandQueryResult, final Collection<JPAPath> requestedSelection, final String parentKey, final List<JPAODataPageExpandInfo> expandInfo) throws ODataApplicationException { return null; } private List<Object> convertPersistentCollection(final JPAAssociationPath jpaAssociationPath, final JPAStructuredType st, final String prefix, final List<Tuple> rows, final Collection<JPAPath> requestedSelection, final List<JPAODataPageExpandInfo> expandInfo) throws ODataJPAModelException, ODataApplicationException { final List<Object> collection = new ArrayList<>(); for (final Tuple row : rows) { if (jpaAssociationPath.getLeaf().isComplex()) { final ComplexValue value = new ComplexValue(); final Map<String, ComplexValue> complexValueBuffer = new HashMap<>(); if (requestedSelection.isEmpty()) { convertWithOutSelection(st, prefix, row, value, complexValueBuffer); } else { convertRowWithSelection(row, requestedSelection, complexValueBuffer, null, value.getValue(), expandInfo); } collection.add(complexValueBuffer.get(jpaAssociationPath.getAlias())); } else { collection.add(convertPrimitiveCollectionAttribute(row.get(jpaAssociationPath.getAlias()), (JPACollectionAttribute) jpaAssociationPath.getLeaf())); } } return collection; } private void convertWithOutSelection(final JPAStructuredType st, final String prefix, final Tuple row, final ComplexValue value, final Map<String, ComplexValue> complexValueBuffer) throws ODataJPAModelException, ODataApplicationException { for (final TupleElement<?> element : row.getElements()) { final String alias = determineAlias(element.getAlias(), prefix); if (alias != null) { final JPAPath path = st.getPath(alias); convertAttribute(row.get(element.getAlias()), path, complexValueBuffer, value.getValue(), row, prefix, null, Collections.emptyList()); } } } @SuppressWarnings("unchecked") private List<Object> convertTransientCollection(final JPAAssociationAttribute attribute, final List<Tuple> tuple) throws ODataJPAProcessorException { final Optional<EdmTransientPropertyCalculator<?>> calculator = requestContext.getCalculator(attribute); if (calculator.isPresent()) { // The tuple contains only one row with required fields return (List<Object>) calculator.get().calculateCollectionProperty(tuple.get(0)); } return Collections.emptyList(); } @SuppressWarnings("unchecked") private <T extends Object, S extends Object> S convertPrimitiveCollectionAttribute(final Object value, final JPAAttribute attribute) { if (attribute.getConverter() != null) { final AttributeConverter<T, S> converter = attribute.getConverter(); return converter.convertToDatabaseColumn((T) value); } return (S) value; } @Override protected Log getLogger() { return LOGGER; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPAResultConverter.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPAResultConverter.java
package com.sap.olingo.jpa.processor.core.converter; import java.util.Collection; import java.util.List; import java.util.Map; import org.apache.olingo.server.api.ODataApplicationException; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.processor.core.api.JPAODataPageExpandInfo; import com.sap.olingo.jpa.processor.core.query.JPAExpandQueryResult; import com.sap.olingo.jpa.processor.core.serializer.JPAEntityCollectionExtension; public interface JPAResultConverter { public Object getResult(final JPAExpandResult jpaResult, final Collection<JPAPath> requestedSelection) throws ODataApplicationException; public Map<String, List<Object>> getCollectionResult(final JPACollectionResult jpaResult, final Collection<JPAPath> requestedSelection) throws ODataApplicationException; public JPAEntityCollectionExtension getResult(JPAExpandQueryResult jpaExpandQueryResult, Collection<JPAPath> requestedSelection, String parentKey, List<JPAODataPageExpandInfo> expandInfo) throws ODataApplicationException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPATuple.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPATuple.java
package com.sap.olingo.jpa.processor.core.converter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import jakarta.persistence.Tuple; import jakarta.persistence.TupleElement; public final class JPATuple implements Tuple { private final List<TupleElement<?>> elements = new ArrayList<>(); private final Map<String, Object> values = new HashMap<>(); public void addElement(final String alias, final Class<?> javaType, final Object value) { elements.add(new JPATupleElement<>(alias, javaType)); values.put(alias, value); } @Override public Object get(final int arg0) { assert 1 == 2; return null; } @Override public <X> X get(final int arg0, final Class<X> arg1) { assert 1 == 2; return null; } /** * Get the value of the tuple element to which the * specified alias has been assigned. * @param alias alias assigned to tuple element * @return value of the tuple element * @throws IllegalArgumentException if alias * does not correspond to an element in the * query result tuple */ @Override public Object get(final String alias) { return values.get(alias); } @Override public <X> X get(final String arg0, final Class<X> arg1) { assert 1 == 2; return null; } @Override public <X> X get(final TupleElement<X> arg0) { return null; } @Override public List<TupleElement<?>> getElements() { return elements; } @Override public Object[] toArray() { return new Object[] {}; } private static record JPATupleElement<X>(String alias, Class<? extends X> javaType) implements TupleElement<X> { @Override public String getAlias() { return alias; } @Override public Class<? extends X> getJavaType() { return javaType; } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPATupleRowConverter.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPATupleRowConverter.java
package com.sap.olingo.jpa.processor.core.converter; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Nonnull; import jakarta.persistence.Tuple; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.uri.UriHelper; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPACollectionAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAElement; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntitySet; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAServiceDocument; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAStructuredType; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.api.JPAODataPageExpandInfo; import com.sap.olingo.jpa.processor.core.api.JPAODataRequestContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAQueryException; import com.sap.olingo.jpa.processor.core.query.JPAExpandQueryResult; import com.sap.olingo.jpa.processor.core.serializer.JPAEntityCollectionExtension; import com.sap.olingo.jpa.processor.core.serializer.JPAEntityCollectionLazy; public class JPATupleRowConverter extends JPATupleResultConverter implements JPARowConverter { private static final Log LOGGER = LogFactory.getLog(JPATupleRowConverter.class); private final JPATupleCollectionConverter collectionConverter; private final JPATupleResultConverter childConverter; public JPATupleRowConverter(final JPAEntityType jpaEntity, final JPAServiceDocument sd, final UriHelper uriHelper, final ServiceMetadata serviceMetadata, final JPAODataRequestContextAccess requestContext) throws ODataApplicationException { super(sd, uriHelper, serviceMetadata, requestContext); this.setName = determineSetName(jpaEntity); this.jpaConversionTargetEntity = jpaEntity; this.edmType = determineEdmType(jpaEntity); this.collectionConverter = new JPATupleCollectionConverter(sd, uriHelper, serviceMetadata, requestContext); this.childConverter = new JPATupleChildConverter(sd, uriHelper, serviceMetadata, requestContext); } @Override public Entity convertRow(final JPAEntityType rowEntity, final Tuple row, final Collection<JPAPath> requestedSelection, final List<JPAODataPageExpandInfo> expandInfo, final JPAExpandResult result) throws ODataApplicationException { jpaQueryResult = result; final Map<String, ComplexValue> complexValueBuffer = new HashMap<>(); final Entity odataEntity = new Entity(); odataEntity.setType(edmType.getFullQualifiedName().getFullQualifiedNameAsString()); final List<Property> properties = odataEntity.getProperties(); final var navigationLinks = odataEntity.getNavigationLinks(); // Creates and add the key of an entity. In general OData allows a server to add additional properties that are not // part of $select. As Olingo adds the key properties (with null) anyhow this can be done here already createId(rowEntity, row, odataEntity, expandInfo); createEtag(rowEntity, row, odataEntity); if (requestedSelection.isEmpty()) convertRowWithOutSelection(rowEntity, row, complexValueBuffer, odataEntity, properties, expandInfo); else convertRowWithSelection(row, requestedSelection, complexValueBuffer, odataEntity, properties, expandInfo); createCollectionProperties(rowEntity, row, properties, result.getChildren()); navigationLinks.addAll(createExpand(rowEntity, row, EMPTY_PREFIX, odataEntity.getId().toString(), expandInfo)); return odataEntity; } private void createCollectionProperties(final JPAEntityType rowEntity, final Tuple row, final List<Property> properties, final Map<JPAAssociationPath, JPAExpandResult> children) throws ODataJPAQueryException { try { final var requestedCollections = getRequestedCollectionsProperties(rowEntity); for (final var requestedCollection : requestedCollections) { List<Property> result = properties; for (final JPAElement pathElement : requestedCollection.getPath()) { result = findOrCreateComplexProperty(result, pathElement); } final JPACollectionAttribute collection = (JPACollectionAttribute) requestedCollection.getLeaf(); if (collection.isTransient()) { result.add(createTransientCollection(row, collection)); } else { final JPACollectionResult child = (JPACollectionResult) children.get(collection.asAssociation()); if (child != null) { result.add(createPersistedCollection(rowEntity, row, child, requestedCollection, collection)); } } } } catch (ODataJPAModelException | ODataApplicationException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_CONV_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e); } } private Property createPersistedCollection(final JPAEntityType rowEntity, final Tuple row, final JPAExpandResult child, final JPAPath requestedCollection, final JPACollectionAttribute collection) throws ODataJPAModelException, ODataApplicationException { final JPAStructuredType st = determineCollectionRoot(rowEntity, requestedCollection.getPath()); final var dbResult = child.removeResult(buildConcatenatedKey(row, collection.asAssociation() .getLeftColumnsList())); final List<Object> collectionResult; if (dbResult != null) { final String prefix = determinePrefix(collection.asAssociation().getAlias()); collectionResult = collectionConverter.getResult(child.getRequestedSelection(), collection .asAssociation(), st, prefix, dbResult); } else { collectionResult = null; } return new Property( null, collection.getExternalName(), collection.isComplex() ? ValueType.COLLECTION_COMPLEX : ValueType.COLLECTION_PRIMITIVE, collectionResult != null ? collectionResult : Collections.emptyList()); } private Property createTransientCollection(final Tuple row, final JPACollectionAttribute collection) throws ODataJPAProcessorException { return requestContext.getCalculator(collection) .map(c -> c.calculateCollectionProperty(row)) .map(collectionResult -> new Property( null, collection.getExternalName(), collection.isComplex() ? ValueType.COLLECTION_COMPLEX : ValueType.COLLECTION_PRIMITIVE, collectionResult)) .orElseGet(() -> { LOGGER.warn("No transient property calculator found for" + collection.getInternalName()); return new Property( null, collection.getExternalName(), collection.isComplex() ? ValueType.COLLECTION_COMPLEX : ValueType.COLLECTION_PRIMITIVE, List.of()); }); } private List<JPAPath> getRequestedCollectionsProperties(final JPAStructuredType rowEntity) throws ODataJPAModelException { return rowEntity.getCollectionAttributesPath(); } protected void createId(final JPAEntityType rowEntity, final Tuple row, final Entity odataEntity, final List<JPAODataPageExpandInfo> expandInfo) throws ODataApplicationException { final Map<String, ComplexValue> complexValueBuffer = Collections.emptyMap(); try { for (final JPAAttribute path : rowEntity.getKey()) { convertAttribute(row.get(path.getExternalName()), rowEntity.getPath(path.getExternalName()), complexValueBuffer, odataEntity.getProperties(), row, EMPTY_PREFIX, null, expandInfo); } } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_CONV_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e); } odataEntity.setId(createId(odataEntity)); } protected String determineSetName(@Nonnull final JPAEntityType jpaEntityType) throws ODataJPAQueryException { try { final JPAEntitySet es = sd.getEntitySet(jpaEntityType); return es != null ? es.getExternalName() : ""; } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_ENTITY_SET_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e, jpaEntityType.getExternalFQN() .getFullQualifiedNameAsString()); } } protected EdmEntityType determineEdmType(final JPAEntityType jpaEntityType) { return serviceMetadata.getEdm().getEntityType(jpaEntityType.getExternalFQN()); } @Override public Object getResult(final JPAExpandResult jpaResult, final Collection<JPAPath> requestedSelection) throws ODataApplicationException { return null; } @Override public Map<String, List<Object>> getCollectionResult(final JPACollectionResult jpaResult, final Collection<JPAPath> requestedSelection) throws ODataApplicationException { return new JPATupleCollectionConverter(sd, uriHelper, serviceMetadata, requestContext) .getResult(jpaResult, requestedSelection); } @Override public JPAEntityCollectionExtension getResult(final JPAExpandQueryResult jpaExpandQueryResult, final Collection<JPAPath> requestedSelection, final String parentKey, final List<JPAODataPageExpandInfo> expandInfo) throws ODataApplicationException { if (JPAExpandResult.ROOT_RESULT_KEY.equals(parentKey)) return new JPAEntityCollectionLazy(jpaExpandQueryResult, this); return childConverter.getResult(jpaExpandQueryResult, requestedSelection, parentKey, expandInfo); } @Override protected Log getLogger() { return LOGGER; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPATupleChildConverter.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPATupleChildConverter.java
package com.sap.olingo.jpa.processor.core.converter; import java.util.ArrayDeque; import java.util.Collection; import java.util.Collections; import java.util.Deque; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; import javax.annotation.Nonnull; import jakarta.persistence.Tuple; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.uri.UriHelper; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransientPropertyCalculator; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPACollectionAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAElement; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntitySet; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAServiceDocument; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAStructuredType; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.api.JPAODataPageExpandInfo; import com.sap.olingo.jpa.processor.core.api.JPAODataRequestContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAQueryException; import com.sap.olingo.jpa.processor.core.query.JPAExpandQueryResult; import com.sap.olingo.jpa.processor.core.serializer.JPAEntityCollection; import com.sap.olingo.jpa.processor.core.serializer.JPAEntityCollectionExtension; /** * Converts the query result based on Tuples from JPA format into Olingo format. * <p> * To reduce the memory footprint each converted row is set to null. This is done as currently the query result is * stored in an ArrayList and deleting a row, which is not the last row, leads to an array copy, which can consume a lot * of time. For the same reason no trimToSize() is called. As an alternative to an ArrayList also a simple linked list * could be used, but this comes with the draw back that each entry would consume round about double space in the list. * @author Oliver Grande * */ public class JPATupleChildConverter extends JPATupleResultConverter { static final Log LOGGER = LogFactory.getLog(JPATupleChildConverter.class); private final Deque<Result> resultStack; private final JPATupleCollectionConverter collectionConverter; public JPATupleChildConverter(final JPAServiceDocument sd, final UriHelper uriHelper, final ServiceMetadata serviceMetadata, final JPAODataRequestContextAccess requestContext) { super(sd, uriHelper, serviceMetadata, requestContext); resultStack = new ArrayDeque<>(); collectionConverter = new JPATupleCollectionConverter(sd, uriHelper, serviceMetadata, requestContext); } @Override public Map<String, List<Object>> getCollectionResult(final JPACollectionResult jpaResult, final Collection<JPAPath> requestedSelection) throws ODataApplicationException { return new JPATupleCollectionConverter(sd, uriHelper, serviceMetadata, requestContext) .getResult(jpaResult, requestedSelection); } @Override public Map<String, JPAEntityCollectionExtension> getResult(@Nonnull final JPAExpandResult jpaResult, @Nonnull final Collection<JPAPath> requestedSelection) throws ODataApplicationException { jpaQueryResult = jpaResult; this.setName = determineSetName(jpaQueryResult); this.jpaConversionTargetEntity = jpaQueryResult.getEntityType(); this.edmType = determineEdmType(jpaConversionTargetEntity); final Map<String, List<Tuple>> childResult = jpaResult.getResults(); final Map<String, JPAEntityCollectionExtension> result = new HashMap<>(childResult.size()); for (final Entry<String, List<Tuple>> tuple : childResult.entrySet()) { final JPAEntityCollectionExtension entityCollection = new JPAEntityCollection(); final List<Entity> entities = entityCollection.getEntities(); final List<Tuple> rows = tuple.getValue(); for (int i = 0; i < rows.size(); i++) { final Tuple row = rows.set(i, null); final Entity odataEntity = convertRow(jpaConversionTargetEntity, row, requestedSelection, Collections .emptyList()); odataEntity.setMediaContentType(determineContentType(jpaConversionTargetEntity, row)); entities.add(odataEntity); } result.put(tuple.getKey(), entityCollection); childResult.replace(tuple.getKey(), null); } return result; } @Override public JPAEntityCollectionExtension getResult(@Nonnull final JPAExpandQueryResult jpaResult, @Nonnull final Collection<JPAPath> requestedSelection, @Nonnull final String parentKey, final List<JPAODataPageExpandInfo> expandInfo) throws ODataApplicationException { pushResult(); jpaQueryResult = jpaResult; this.setName = determineSetName(jpaResult); this.jpaConversionTargetEntity = jpaResult.getEntityType(); this.edmType = determineEdmType(jpaConversionTargetEntity); final List<Tuple> rows = jpaResult.getResults().get(parentKey); final JPAEntityCollection entityCollection = new JPAEntityCollection(); final List<Entity> entities = entityCollection.getEntities(); for (int i = 0; i < rows.size(); i++) { final Tuple row = rows.set(i, null); final Entity odataEntity = convertRow(jpaConversionTargetEntity, row, requestedSelection, expandInfo); odataEntity.setMediaContentType(determineContentType(jpaConversionTargetEntity, row)); entities.add(odataEntity); } popResult(); return entityCollection; } private void popResult() { if (!resultStack.isEmpty()) { final var result = resultStack.pop(); jpaQueryResult = result.jpaResult; this.setName = result.esName; this.jpaConversionTargetEntity = jpaQueryResult.getEntityType(); this.edmType = result.edmType; } } private void pushResult() { if (jpaQueryResult != null) resultStack.push(new Result(jpaQueryResult, setName, edmType)); } protected Entity convertRow(final JPAEntityType rowEntity, final Tuple row, final Collection<JPAPath> requestedSelection, final List<JPAODataPageExpandInfo> expandInfo) throws ODataApplicationException { final Map<String, ComplexValue> complexValueBuffer = new HashMap<>(); final Entity odataEntity = new Entity(); odataEntity.setType(edmType.getFullQualifiedName().getFullQualifiedNameAsString()); final List<Property> properties = odataEntity.getProperties(); // Creates and add the key of an entity. In general OData allows a server to add additional properties that are not // part of $select. As Olingo adds the key properties (with null) anyhow this can be done here already createId(rowEntity, row, odataEntity, expandInfo); createEtag(rowEntity, row, odataEntity); if (requestedSelection.isEmpty()) convertRowWithOutSelection(rowEntity, row, complexValueBuffer, odataEntity, properties, expandInfo); else convertRowWithSelection(row, requestedSelection, complexValueBuffer, odataEntity, properties, expandInfo); createCollectionProperties(rowEntity, row, properties); odataEntity.getNavigationLinks().addAll(createExpand(rowEntity, row, EMPTY_PREFIX, odataEntity.getId().toString(), expandInfo)); return odataEntity; } protected void createCollectionProperties(final JPAStructuredType jpaStructuredType, final Tuple row, final List<Property> properties) throws ODataJPAQueryException { List<Property> result; try { for (final JPAPath path : jpaStructuredType.getCollectionAttributesPath()) { result = properties; for (final JPAElement pathElement : path.getPath()) { result = findOrCreateComplexProperty(result, pathElement); } final JPACollectionAttribute collection = (JPACollectionAttribute) path.getLeaf(); if (collection.isTransient()) { addTransientCollection(row, result, collection); } else { final JPAExpandResult child = jpaQueryResult.getChild(collection.asAssociation()); if (child != null) { addPersistedCollection(jpaConversionTargetEntity, row, result, child, path, collection); } } } } catch (ODataJPAModelException | ODataApplicationException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_CONV_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e); } } /** * @param row * @param collection * @throws ODataJPAProcessorException */ private void addTransientCollection(final Tuple row, final List<Property> result, final JPACollectionAttribute collection) throws ODataJPAProcessorException { final Optional<EdmTransientPropertyCalculator<?>> calculator = requestContext.getCalculator(collection); if (calculator.isPresent()) { final Collection<?> collectionResult = calculator.get().calculateCollectionProperty(row); result.add(new Property( null, collection.getExternalName(), collection.isComplex() ? ValueType.COLLECTION_COMPLEX : ValueType.COLLECTION_PRIMITIVE, collectionResult)); } } private void addPersistedCollection(final JPAEntityType rowEntity, final Tuple row, final List<Property> result, final JPAExpandResult child, final JPAPath requestedCollection, final JPACollectionAttribute collection) throws ODataJPAModelException, ODataApplicationException { final JPAStructuredType st = determineCollectionRoot(rowEntity, requestedCollection.getPath()); final var dbResult = child.getResult(buildConcatenatedKey(row, collection.asAssociation() .getLeftColumnsList())); final List<Object> collectionResult; if (dbResult != null) { final String prefix = determinePrefix(collection.asAssociation().getAlias()); collectionResult = collectionConverter.getResult(child.getRequestedSelection(), collection .asAssociation(), st, prefix, dbResult); } else { collectionResult = null; } result.add(new Property( null, collection.getExternalName(), collection.isComplex() ? ValueType.COLLECTION_COMPLEX : ValueType.COLLECTION_PRIMITIVE, collectionResult != null ? collectionResult : Collections.emptyList())); } protected void createId(final JPAEntityType rowEntity, final Tuple row, final Entity odataEntity, final List<JPAODataPageExpandInfo> expandInfo) throws ODataApplicationException { final Map<String, ComplexValue> complexValueBuffer = Collections.emptyMap(); try { for (final JPAAttribute path : rowEntity.getKey()) { convertAttribute(row.get(path.getExternalName()), rowEntity.getPath(path.getExternalName()), complexValueBuffer, odataEntity.getProperties(), row, EMPTY_PREFIX, null, expandInfo); } } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_CONV_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e); } odataEntity.setId(createId(odataEntity)); } protected EdmEntityType determineEdmType(final JPAEntityType jpaEntityType) { return serviceMetadata.getEdm().getEntityType(jpaEntityType.getExternalFQN()); } /** * Returns the name of the first entity set that point to the entity type mentioned in <code>jpaQueryResult</code> * @param jpaQueryResult * @return * @throws ODataJPAQueryException */ protected String determineSetName(@Nonnull final JPAExpandResult jpaQueryResult) throws ODataJPAQueryException { try { final JPAEntitySet es = sd.getEntitySet(jpaQueryResult.getEntityType()); return es != null ? es.getExternalName() : ""; } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_ENTITY_SET_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e, jpaQueryResult.getEntityType().getExternalFQN() .getFullQualifiedNameAsString()); } } protected String determineSetName(@Nonnull final JPAEntityType jpaEntityType) throws ODataJPAQueryException { try { final JPAEntitySet es = sd.getEntitySet(jpaEntityType); return es != null ? es.getExternalName() : ""; } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_ENTITY_SET_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e, jpaQueryResult.getEntityType().getExternalFQN() .getFullQualifiedNameAsString()); } } private String determineContentType(final JPAEntityType jpaEntity, final Tuple row) throws ODataJPAQueryException { try { if (jpaEntity.hasStream()) { if (jpaEntity.getContentType() != null && !jpaEntity.getContentType().isEmpty()) { return jpaEntity.getContentType(); } else { Object rowElement = null; for (final JPAElement element : jpaEntity.getContentTypeAttributePath().getPath()) { rowElement = row.get(element.getExternalName()); } return rowElement != null ? rowElement.toString() : null; } } return null; } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } } @Override protected Log getLogger() { return LOGGER; } private static record Result(JPAExpandResult jpaResult, String esName, EdmEntityType edmType) { } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPATupleResultConverter.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPATupleResultConverter.java
package com.sap.olingo.jpa.processor.core.converter; import static com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException.MessageKeys.ODATA_MAXPAGESIZE_NOT_A_NUMBER; import java.net.URI; import java.net.URISyntaxException; import java.time.Duration; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; import javax.annotation.Nonnull; import javax.annotation.Nullable; import jakarta.persistence.AttributeConverter; import jakarta.persistence.Tuple; import jakarta.persistence.TupleElement; import org.apache.commons.logging.Log; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.Link; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.ex.ODataRuntimeException; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.uri.UriHelper; import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransientPropertyCalculator; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAElement; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAServiceDocument; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAStructuredType; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.api.JPAODataPageExpandInfo; import com.sap.olingo.jpa.processor.core.api.JPAODataRequestContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAQueryException; import com.sap.olingo.jpa.processor.core.query.JPAConvertibleResult; import com.sap.olingo.jpa.processor.core.query.Utility; import com.sap.olingo.jpa.processor.core.serializer.JPAEntityCollectionExtension; /** * Abstract super class for result converter, which convert Tuple based results. * @author Oliver Grande * */ abstract class JPATupleResultConverter implements JPAResultConverter { protected static final String EMPTY_PREFIX = ""; protected JPAEntityType jpaConversionTargetEntity; protected JPAExpandResult jpaQueryResult; protected final UriHelper uriHelper; protected String setName; protected final JPAServiceDocument sd; protected final ServiceMetadata serviceMetadata; protected EdmEntityType edmType; protected final JPAODataRequestContextAccess requestContext; protected JPATupleResultConverter(final JPAServiceDocument sd, final UriHelper uriHelper, final ServiceMetadata serviceMetadata, final JPAODataRequestContextAccess requestContext) { this.uriHelper = uriHelper; this.sd = sd; this.serviceMetadata = serviceMetadata; this.requestContext = requestContext; } protected String buildConcatenatedKey(final Tuple row, final List<JPAPath> leftColumns) { final StringBuilder buffer = new StringBuilder(); for (final JPAPath item : leftColumns) { buffer.append(JPAPath.PATH_SEPARATOR); // TODO Tuple returns the converted value in case a @Convert(converter = annotation is given buffer.append(row.get(item.getAlias())); } buffer.deleteCharAt(0); return buffer.toString(); } protected String buildPath(final String prefix, final JPAAssociationAttribute association) { return EMPTY_PREFIX.equals(prefix) ? association.getExternalName() : prefix + JPAPath.PATH_SEPARATOR + association .getExternalName(); } protected void convertAttribute(final Object value, final JPAPath jpaPath, final Map<String, ComplexValue> complexValueBuffer, final List<Property> properties, final Tuple parentRow, final String prefix, @Nullable final Entity odataEntity, final List<JPAODataPageExpandInfo> expandInfo) throws ODataJPAModelException, ODataApplicationException { if (jpaPath != null) { final JPAAttribute attribute = (JPAAttribute) jpaPath.getPath().get(0); if (attribute != null && !attribute.isKey() && attribute.isComplex()) { convertComplexAttribute(value, jpaPath.getAlias(), complexValueBuffer, properties, attribute, parentRow, prefix, odataEntity, expandInfo); } else if (attribute != null) { convertPrimitiveAttribute(value, properties, jpaPath, attribute, parentRow); } } } protected void convertRowWithOutSelection(final JPAEntityType rowEntity, final Tuple row, final Map<String, ComplexValue> complexValueBuffer, final Entity odataEntity, final List<Property> properties, final List<JPAODataPageExpandInfo> expandInfo) throws ODataApplicationException { for (final TupleElement<?> element : row.getElements()) { try { if (odataEntity.getProperty(element.getAlias()) == null) { final JPAPath path = rowEntity.getPath(element.getAlias()); convertAttribute(row.get(element.getAlias()), path, complexValueBuffer, properties, row, EMPTY_PREFIX, odataEntity, expandInfo); } } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_CONV_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e); } } } protected void convertRowWithSelection(final Tuple row, final Collection<JPAPath> requestedSelection, final Map<String, ComplexValue> complexValueBuffer, final Entity odataEntity, final List<Property> properties, final List<JPAODataPageExpandInfo> expandInfo) throws ODataApplicationException { for (final JPAPath p : requestedSelection) { try { final Object value = p.isTransient() ? null : row.get(p.getAlias()); if (odataEntity == null || odataEntity.getProperty(p.getAlias()) == null) convertAttribute(value, p, complexValueBuffer, properties, row, EMPTY_PREFIX, odataEntity, expandInfo); } catch (final IllegalArgumentException e) { // Skipped property; add it to result final JPATuple skipped = new JPATuple(); skipped.addElement(p.getAlias(), p.getLeaf().getType(), null); try { convertAttribute(null, p, complexValueBuffer, properties, skipped, EMPTY_PREFIX, odataEntity, expandInfo); } catch (final ODataJPAModelException e1) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_CONV_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e1); } } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_CONV_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e); } } } protected void createComplexValue(final Map<String, ComplexValue> complexValueBuffer, final List<Property> properties, final JPAAttribute attribute, final Tuple parentRow, final String bufferKey, final String rootURI, final List<JPAODataPageExpandInfo> expandInfo) throws ODataJPAModelException, ODataApplicationException { final ComplexValue complexValue = new ComplexValue(); complexValueBuffer.put(bufferKey, complexValue); properties.add(new Property( attribute.getStructuredType().getExternalFQN().getFullQualifiedNameAsString(), attribute.getExternalName(), ValueType.COMPLEX, complexValue)); complexValue.getNavigationLinks().addAll(createExpand(attribute.getStructuredType(), parentRow, bufferKey, rootURI, expandInfo)); } protected Collection<Link> createExpand(final JPAStructuredType jpaStructuredType, final Tuple row, final String prefix, final String rootURI, final List<JPAODataPageExpandInfo> expandInfo) throws ODataApplicationException { final List<Link> entityExpandLinks = new ArrayList<>(); JPAAssociationPath path = null; try { for (final JPAAssociationAttribute a : jpaStructuredType.getDeclaredAssociations()) { path = jpaConversionTargetEntity.getAssociationPath(buildPath(prefix, a)); final JPAExpandResult child = jpaQueryResult.getChild(path); final String linkURI = rootURI + JPAPath.PATH_SEPARATOR + path.getAlias(); if (child != null) { // TODO Check how to convert Organizations('3')/AdministrativeInformation?$expand=Created/User entityExpandLinks.add(getLink(path, row, child, linkURI, expandInfo)); } else { entityExpandLinks.add(getLink(path, linkURI)); } } } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_NAVI_PROPERTY_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e, path != null ? path.getAlias() : EMPTY_PREFIX); } return entityExpandLinks; } protected final String determineAlias(final String alias, final String prefix) { if (EMPTY_PREFIX.equals(prefix)) return alias; final int startPos = alias.indexOf(prefix) + prefix.length() + 1; if (startPos > alias.length()) return null; return alias.substring(startPos); } protected final JPAStructuredType determineCollectionRoot(final JPAEntityType et, final List<JPAElement> pathList) throws ODataJPAModelException { if (pathList.size() > 1) return ((JPAAttribute) pathList.get(pathList.size() - 2)).getStructuredType(); else return et; } protected final String determinePrefix(final String alias) { final String prefix = alias; final int index = prefix.lastIndexOf(JPAPath.PATH_SEPARATOR); if (index < 0) return EMPTY_PREFIX; else return prefix.substring(0, index); } String buildPath(final JPAAttribute attribute, final String prefix) { return EMPTY_PREFIX.equals(prefix) ? attribute.getExternalName() : prefix + JPAPath.PATH_SEPARATOR + attribute .getExternalName(); } void convertComplexAttribute(final Object value, final String externalName, final Map<String, ComplexValue> complexValueBuffer, final List<Property> properties, final JPAAttribute attribute, final Tuple parentRow, final String prefix, final Entity odataEntity, final List<JPAODataPageExpandInfo> expandInfo) throws ODataJPAModelException, ODataApplicationException { final String bufferKey = buildPath(attribute, prefix); if (!complexValueBuffer.containsKey(bufferKey)) { createComplexValue(complexValueBuffer, properties, attribute, parentRow, bufferKey, odataEntity == null ? "" : odataEntity.getId().toString(), expandInfo); } final List<Property> values = complexValueBuffer.get(bufferKey).getValue(); final int splitIndex = attribute.getExternalName().length() + JPAPath.PATH_SEPARATOR.length(); final String attributeName = splitIndex < externalName.length() ? externalName.substring(splitIndex) : externalName; convertAttribute(value, attribute.getStructuredType().getPath(attributeName), complexValueBuffer, values, parentRow, buildPath(attribute, prefix), odataEntity, expandInfo); } @SuppressWarnings("unchecked") <T extends Object, S extends Object> void convertPrimitiveAttribute(final Object value, final List<Property> properties, final JPAPath jpaPath, final JPAAttribute attribute, final Tuple parentRow) throws ODataJPAProcessorException { Object odataValue = null; if (attribute != null && attribute.isTransient()) { if (attribute.isCollection()) return; final Optional<EdmTransientPropertyCalculator<?>> calculator = requestContext.getCalculator(attribute); if (calculator.isPresent()) { try { odataValue = calculator.get().calculateProperty(parentRow); } catch (final IllegalArgumentException e) { requestContext.getDebugger().debug(this, "Error in transient field calculator %s: %s", calculator.get().getClass().getName(), e.getMessage()); throw new ODataJPAProcessorException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } } } else if (attribute != null && value != null && attribute.isEnum() && !value.getClass().isArray()) { odataValue = ((Enum<?>) value).ordinal(); } else if (attribute != null && attribute.getConverter() != null) { final AttributeConverter<T, S> converter = attribute.getConverter(); odataValue = converter.convertToDatabaseColumn((T) value); } else if (attribute != null && value != null && attribute.isCollection()) { return; } else if (attribute != null && value != null && attribute.getType() == Duration.class) { odataValue = ((Duration) value).getSeconds(); } else { odataValue = value; } if (attribute != null && attribute.isKey() && attribute.isComplex()) { properties.add(new Property( null, jpaPath.getLeaf().getExternalName(), attribute.isEnum() ? ValueType.ENUM : ValueType.PRIMITIVE, odataValue)); } else if (attribute != null) { // ...$select=Name1,Address/Region properties.add(new Property( null, attribute.getExternalName(), attribute.isEnum() ? ValueType.ENUM : ValueType.PRIMITIVE, odataValue)); } } Integer determineCount(final JPAExpandResult child, final String foreignKey) { final Long count = child.getCount(foreignKey); return count != null ? count.intValue() : null; } protected Link getLink(final JPAAssociationPath association, final String linkURI) { final Link link = new Link(); link.setTitle(association.getLeaf().getExternalName()); link.setRel(Constants.NS_NAVIGATION_LINK_REL + link.getTitle()); link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE); link.setHref(linkURI); return link; } protected Link getLink(final JPAAssociationPath association, final Tuple parentRow, final JPAExpandResult child, final String linkURI, final List<JPAODataPageExpandInfo> expandInfo) throws ODataApplicationException { final Link link = new Link(); link.setTitle(association.getLeaf().getExternalName()); link.setRel(Constants.NS_NAVIGATION_LINK_REL + link.getTitle()); link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE); try { final var foreignKey = buildConcatenatedKey(parentRow, association.getLeftColumnsList()); final List<JPAODataPageExpandInfo> newInfo = new ArrayList<>(expandInfo); newInfo.add(new JPAODataPageExpandInfo(association.getAlias(), foreignKey)); final JPAEntityCollectionExtension expandCollection = ((JPAConvertibleResult) child).getEntityCollection( foreignKey, this, association, newInfo); expandCollection.setCount(determineCount(child, foreignKey)); if (association.getLeaf().isCollection()) { if (!expandCollection.getEntities().isEmpty()) { expandCollection.setNext(createNextLink(child, newInfo)); } link.setInlineEntitySet((EntityCollection) expandCollection); link.setHref(linkURI); } else { if (expandCollection.getEntities() != null && !expandCollection.getEntities().isEmpty()) { final Entity expandEntity = expandCollection.getEntities().get(0); link.setInlineEntity(expandEntity); link.setHref(linkURI); } } } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_CONV_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e); } return link; } private URI createNextLink(final JPAExpandResult child, final List<JPAODataPageExpandInfo> newInfo) throws ODataJPAProcessorException { try { final String skipToken = child.getSkipToken(newInfo); if (skipToken == null) return null; return new URI(Utility.determineBindingTarget(requestContext.getUriInfo().getUriResourceParts()).getName() + "?" + SystemQueryOptionKind.SKIPTOKEN.toString() + "=" + skipToken); } catch (final URISyntaxException e) { throw new ODataJPAProcessorException(ODATA_MAXPAGESIZE_NOT_A_NUMBER, HttpStatusCode.INTERNAL_SERVER_ERROR, e); } } protected List<Property> findOrCreateComplexProperty(List<Property> result, final JPAElement pathElement) throws ODataJPAModelException { boolean found = false; for (final Property p : result) { if (p.getName().equals(pathElement.getExternalName())) { result = ((ComplexValue) p.getValue()).getValue(); found = true; break; } } if (!found && pathElement instanceof final JPAAttribute attribute && attribute.isComplex() && !attribute.isCollection()) { final Property path = new Property( attribute.getStructuredType().getExternalFQN().getFullQualifiedNameAsString(), attribute.getExternalName(), ValueType.COMPLEX, new ComplexValue()); result.add(path); result = ((ComplexValue) path.getValue()).getValue(); } return result; } protected URI createId(final Entity entity) { try { // No host-name and port as part of ID; only relative path // 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 (final URISyntaxException e) { throw new ODataRuntimeException("Unable to create id for entity: " + edmType.getName(), e); } catch (final IllegalArgumentException e) { getLogger().debug(e.getMessage() + ": No URI created"); return null; } catch (final SerializerException e) { throw new ODataRuntimeException(e); } } void createEtag(@Nonnull final JPAEntityType rowEntity, final Tuple row, final Entity odataEntity) throws ODataJPAQueryException { try { if (rowEntity.hasEtag()) { final String etagAlias = rowEntity.getEtagPath().getAlias(); final Object etag = row.get(etagAlias); if (etag != null) { odataEntity.setETag(requestContext.getEtagHelper().asEtag(rowEntity, etag)); } } } catch (final ODataJPAModelException e) { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_RESULT_CONV_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR, e); } } protected abstract Log getLogger(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPAComplexResultConverter.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/converter/JPAComplexResultConverter.java
package com.sap.olingo.jpa.processor.core.converter; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.edm.EdmComplexType; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.serializer.SerializerException; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAServiceDocument; public class JPAComplexResultConverter extends JPAStructuredResultConverter { public JPAComplexResultConverter(final JPAServiceDocument sd, final List<?> jpaQueryResult, final EdmComplexType edmComplexType) { super(jpaQueryResult, sd.getComplexType(edmComplexType)); } @Override public List<ComplexValue> getResult() throws ODataApplicationException, SerializerException, URISyntaxException { List<ComplexValue> result = new ArrayList<>(); for (Object row : this.jpaQueryResult) { final ComplexValue value = new ComplexValue(); final List<Property> properties = value.getValue(); convertProperties(row, properties, jpaTopLevelType); result.add(value); } return result; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeCount.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeCount.java
package com.sap.olingo.jpa.processor.core.serializer; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.serializer.FixedFormatSerializer; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerResult; final class JPASerializeCount implements JPASerializer { private final FixedFormatSerializer serializer; JPASerializeCount(final FixedFormatSerializer serializer) { this.serializer = serializer; } @Override public SerializerResult serialize(final ODataRequest request, final JPAEntityCollectionExtension result) throws SerializerException { return new JPAValueSerializerResult(serializer.count(result.getCount())); } @Override public ContentType getContentType() { return ContentType.TEXT_PLAIN; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializePrimitiveAbstract.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializePrimitiveAbstract.java
package com.sap.olingo.jpa.processor.core.serializer; import java.util.List; import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.uri.UriInfoResource; import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourceProperty; public abstract class JPASerializePrimitiveAbstract implements JPAOperationSerializer { protected static final char PATH_SEPARATOR = '/'; protected final ServiceMetadata serviceMetadata; protected final UriInfoResource uriInfo; protected JPASerializePrimitiveAbstract(final ServiceMetadata serviceMetadata, final UriInfoResource uriInfo) { super(); this.serviceMetadata = serviceMetadata; this.uriInfo = uriInfo; } protected final JPAPrimitivePropertyInfo determinePrimitiveProperty(final JPAEntityCollectionExtension result, final List<UriResource> uriResources) { Property property = null; Object value = null; final StringBuilder path = new StringBuilder(); for (final Property item : result.getFirstResult().getProperties()) if (partOfPath(item, uriResources)) { property = item; boolean found = false; while (!found) { path.append(property.getName()); if (property.getValue() instanceof ComplexValue) { value = property.getValue(); property = ((ComplexValue) value).getValue().get(0); path.append(PATH_SEPARATOR); } else { found = true; } } break; } return new JPAPrimitivePropertyInfo(path.toString(), property); } private boolean partOfPath(final Property item, final List<UriResource> uriResources) { for (final UriResource resource : uriResources) if (resource instanceof final UriResourceProperty resourceProperty && resourceProperty.getProperty().getName().equals(item.getName())) return true; return false; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeEntityCollection.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeEntityCollection.java
package com.sap.olingo.jpa.processor.core.serializer; import java.net.URISyntaxException; import org.apache.olingo.commons.api.data.Annotatable; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.edm.EdmBindingTarget; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions; import org.apache.olingo.server.api.serializer.ODataSerializer; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerResult; import org.apache.olingo.server.api.uri.UriHelper; import org.apache.olingo.server.api.uri.UriInfoResource; import com.sap.olingo.jpa.processor.core.api.JPAODataSessionContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPASerializerException; import com.sap.olingo.jpa.processor.core.query.Utility; final class JPASerializeEntityCollection implements JPAOperationSerializer { private final ServiceMetadata serviceMetadata; private final UriInfoResource uriInfo; private final UriHelper uriHelper; private final ODataSerializer serializer; private final ContentType responseFormat; private final JPAODataSessionContextAccess serviceContext; JPASerializeEntityCollection(final ServiceMetadata serviceMetadata, final ODataSerializer serializer, final UriHelper uriHelper, final UriInfoResource uriInfo, final ContentType responseFormat, final JPAODataSessionContextAccess serviceContext) { this.uriInfo = uriInfo; this.serializer = serializer; this.serviceMetadata = serviceMetadata; this.uriHelper = uriHelper; this.responseFormat = responseFormat; this.serviceContext = serviceContext; } @Override public SerializerResult serialize(final ODataRequest request, final JPAEntityCollectionExtension result) throws SerializerException, ODataJPASerializerException { final EdmBindingTarget targetEdmBindingTarget = Utility.determineBindingTarget(uriInfo.getUriResourceParts()); final String selectList = uriHelper.buildContextURLSelectList(targetEdmBindingTarget.getEntityType(), uriInfo.getExpandOption(), uriInfo.getSelectOption()); ContextURL contextUrl; try { contextUrl = ContextURL.with() .serviceRoot(buildServiceRoot(request, serviceContext)) .entitySetOrSingletonOrType(targetEdmBindingTarget.getName()) .selectList(selectList) .build(); } catch (final URISyntaxException e) { throw new ODataJPASerializerException(e, HttpStatusCode.BAD_REQUEST); } final String id = request.getRawBaseUri() + "/" + targetEdmBindingTarget.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, targetEdmBindingTarget.getEntityType(), (EntityCollection) result, opts); } @Override public SerializerResult serialize(final Annotatable annotatable, final EdmType entityType, final ODataRequest request) throws SerializerException, ODataJPASerializerException { final EntityCollection result = (EntityCollection) annotatable; final String selectList = uriHelper.buildContextURLSelectList((EdmEntityType) entityType, uriInfo.getExpandOption(), uriInfo.getSelectOption()); ContextURL contextUrl; try { contextUrl = ContextURL.with() .serviceRoot(buildServiceRoot(request, serviceContext)) .asCollection() .type(entityType) .selectList(selectList) .build(); } catch (final URISyntaxException e) { throw new ODataJPASerializerException(e, HttpStatusCode.BAD_REQUEST); } final EntityCollectionSerializerOptions options = EntityCollectionSerializerOptions.with() .contextURL(contextUrl) .select(uriInfo.getSelectOption()) .expand(uriInfo.getExpandOption()) .build(); return serializer.entityCollection(serviceMetadata, (EdmEntityType) entityType, result, options); } @Override public ContentType getContentType() { return responseFormat; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPAEntityCollectionExtension.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPAEntityCollectionExtension.java
package com.sap.olingo.jpa.processor.core.serializer; import java.net.URI; import java.util.List; import org.apache.olingo.commons.api.data.Entity; public interface JPAEntityCollectionExtension extends Iterable<Entity> { boolean hasResults(); Entity getFirstResult(); void setNext(final URI nextLink); URI getNext(); void setCount(final Integer count); Integer getCount(); List<Entity> getEntities(); boolean hasSingleResult(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPAPrimitivePropertyInfo.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPAPrimitivePropertyInfo.java
package com.sap.olingo.jpa.processor.core.serializer; import org.apache.olingo.commons.api.data.Property; record JPAPrimitivePropertyInfo(String path, Property property) {}
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeComplexCollection.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeComplexCollection.java
package com.sap.olingo.jpa.processor.core.serializer; import java.net.URISyntaxException; import org.apache.olingo.commons.api.data.Annotatable; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.edm.EdmComplexType; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.serializer.ComplexSerializerOptions; import org.apache.olingo.server.api.serializer.ODataSerializer; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerResult; import com.sap.olingo.jpa.processor.core.api.JPAODataSessionContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPASerializerException; public class JPASerializeComplexCollection implements JPAOperationSerializer { private final ServiceMetadata serviceMetadata; private final ODataSerializer serializer; private final ContentType responseFormat; private final JPAODataSessionContextAccess serviceContext; JPASerializeComplexCollection(final ServiceMetadata serviceMetadata, final ODataSerializer serializer, final ContentType responseFormat, final JPAODataSessionContextAccess context) { this.serializer = serializer; this.serviceMetadata = serviceMetadata; this.responseFormat = responseFormat; this.serviceContext = context; } @Override public ContentType getContentType() { return responseFormat; } @Override public SerializerResult serialize(final Annotatable result, final EdmType complexType, final ODataRequest request) throws SerializerException, ODataJPASerializerException { try { final ContextURL contextUrl = ContextURL.with() .serviceRoot(buildServiceRoot(request, serviceContext)) .asCollection() .build(); final ComplexSerializerOptions options = ComplexSerializerOptions.with().contextURL(contextUrl).build(); return serializer.complexCollection(serviceMetadata, (EdmComplexType) complexType, (Property) result, options); } catch (final URISyntaxException e) { throw new ODataJPASerializerException(e, HttpStatusCode.BAD_REQUEST); } } @Override public SerializerResult serialize(final ODataRequest request, final JPAEntityCollectionExtension result) throws SerializerException, ODataJPASerializerException { return null; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPAEntityCollection.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPAEntityCollection.java
package com.sap.olingo.jpa.processor.core.serializer; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntityCollection; public class JPAEntityCollection extends EntityCollection implements JPAEntityCollectionExtension { @Override public boolean hasResults() { return !getEntities().isEmpty(); } @Override public Entity getFirstResult() { if (hasResults()) return getEntities().get(0); return null; } @Override public boolean hasSingleResult() { return getEntities().size() == 1; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializePrimitive.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializePrimitive.java
package com.sap.olingo.jpa.processor.core.serializer; import java.net.URISyntaxException; import org.apache.olingo.commons.api.data.Annotatable; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.edm.EdmBindingTarget; import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.serializer.ODataSerializer; import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerResult; import org.apache.olingo.server.api.uri.UriInfoResource; import org.apache.olingo.server.api.uri.UriResourceProperty; import com.sap.olingo.jpa.processor.core.api.JPAODataSessionContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPASerializerException; import com.sap.olingo.jpa.processor.core.query.Utility; final class JPASerializePrimitive extends JPASerializePrimitiveAbstract { private final ODataSerializer serializer; private final ContentType responseFormat; private final JPAODataSessionContextAccess serviceContext; JPASerializePrimitive(final ServiceMetadata serviceMetadata, final ODataSerializer serializer, final UriInfoResource uriInfo, final ContentType responseFormat, final JPAODataSessionContextAccess context) { super(serviceMetadata, uriInfo); this.serializer = serializer; this.responseFormat = responseFormat; this.serviceContext = context; } @Override public ContentType getContentType() { return responseFormat; } @Override public SerializerResult serialize(final Annotatable result, final EdmType primitiveType, final ODataRequest request) throws SerializerException, ODataJPASerializerException { try { final ContextURL contextUrl = ContextURL.with() .serviceRoot(buildServiceRoot(request, serviceContext)) .build(); final PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextUrl).build(); return serializer.primitive(serviceMetadata, (EdmPrimitiveType) primitiveType, (Property) result, options); } catch (final URISyntaxException e) { throw new ODataJPASerializerException(e, HttpStatusCode.BAD_REQUEST); } } @Override public SerializerResult serialize(final ODataRequest request, final JPAEntityCollectionExtension result) throws SerializerException, ODataJPASerializerException { final EdmBindingTarget targetEdmBindingTarget = Utility.determineBindingTarget(uriInfo.getUriResourceParts()); final UriResourceProperty uriProperty = (UriResourceProperty) uriInfo.getUriResourceParts().get(uriInfo .getUriResourceParts().size() - 1); try { final JPAPrimitivePropertyInfo property = determinePrimitiveProperty(result, uriInfo.getUriResourceParts()); final EdmPrimitiveType edmPropertyType = (EdmPrimitiveType) uriProperty.getProperty().getType(); final ContextURL contextUrl = ContextURL.with() .serviceRoot(buildServiceRoot(request, serviceContext)) .entitySetOrSingletonOrType(targetEdmBindingTarget.getName()) .navOrPropertyPath(property.path()) .build(); final PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextUrl).build(); if (uriProperty.getProperty().isCollection()) return serializer.primitiveCollection(serviceMetadata, edmPropertyType, property.property(), options); else return serializer.primitive(serviceMetadata, edmPropertyType, property.property(), options); } catch (final URISyntaxException e) { throw new ODataJPASerializerException(e, HttpStatusCode.BAD_REQUEST); } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPAOperationSerializer.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPAOperationSerializer.java
package com.sap.olingo.jpa.processor.core.serializer; import org.apache.olingo.commons.api.data.Annotatable; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerResult; import com.sap.olingo.jpa.processor.core.exception.ODataJPASerializerException; public interface JPAOperationSerializer extends JPASerializer { public SerializerResult serialize(final Annotatable result, final EdmType entityType, final ODataRequest request) throws SerializerException, ODataJPASerializerException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeComplex.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeComplex.java
package com.sap.olingo.jpa.processor.core.serializer; import java.net.URISyntaxException; import java.util.List; import org.apache.olingo.commons.api.data.Annotatable; import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.edm.EdmBindingTarget; import org.apache.olingo.commons.api.edm.EdmComplexType; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.serializer.ComplexSerializerOptions; import org.apache.olingo.server.api.serializer.ODataSerializer; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerResult; import org.apache.olingo.server.api.uri.UriHelper; import org.apache.olingo.server.api.uri.UriInfoResource; import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourceComplexProperty; import org.apache.olingo.server.api.uri.UriResourceEntitySet; import org.apache.olingo.server.api.uri.UriResourceKind; import org.apache.olingo.server.api.uri.UriResourceNavigation; import org.apache.olingo.server.api.uri.UriResourceProperty; import org.apache.olingo.server.api.uri.UriResourceSingleton; import com.sap.olingo.jpa.processor.core.api.JPAODataSessionContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPASerializerException; import com.sap.olingo.jpa.processor.core.query.Utility; public final class JPASerializeComplex implements JPAOperationSerializer { private final ServiceMetadata serviceMetadata; private final UriInfoResource uriInfo; private final UriHelper uriHelper; private final ODataSerializer serializer; private final ContentType responseFormat; private final JPAODataSessionContextAccess serviceContext; JPASerializeComplex(final ServiceMetadata serviceMetadata, final ODataSerializer serializer, final UriHelper uriHelper, final UriInfoResource uriInfo, final ContentType responseFormat, final JPAODataSessionContextAccess serviceContext) { this.uriInfo = uriInfo; this.serializer = serializer; this.serviceMetadata = serviceMetadata; this.uriHelper = uriHelper; this.responseFormat = responseFormat; this.serviceContext = serviceContext; } @Override public ContentType getContentType() { return responseFormat; } @Override public SerializerResult serialize(final Annotatable result, final EdmType complexType, final ODataRequest request) throws SerializerException, ODataJPASerializerException { try { final ContextURL contextUrl = ContextURL.with().serviceRoot(buildServiceRoot(request, serviceContext)).build(); final ComplexSerializerOptions options = ComplexSerializerOptions.with().contextURL(contextUrl).build(); return serializer.complex(serviceMetadata, (EdmComplexType) complexType, (Property) result, options); } catch (final URISyntaxException e) { throw new ODataJPASerializerException(e, HttpStatusCode.BAD_REQUEST); } } @Override public SerializerResult serialize(final ODataRequest request, final JPAEntityCollectionExtension result) throws SerializerException, ODataJPASerializerException { final EdmBindingTarget targetEdmBindingTarget = Utility.determineBindingTarget(uriInfo.getUriResourceParts()); final List<UriResource> resourceParts = uriInfo.getUriResourceParts(); final UriResourceProperty uriProperty = (UriResourceProperty) resourceParts.get(resourceParts.size() - 1); final EdmComplexType edmPropertyType = ((UriResourceComplexProperty) uriProperty).getComplexType(); final String selectList = uriHelper.buildContextURLSelectList(targetEdmBindingTarget.getEntityType(), uriInfo.getExpandOption(), uriInfo.getSelectOption()); try { final ContextURL contextUrl = ContextURL.with() .serviceRoot(buildServiceRoot(request, serviceContext)) .entitySetOrSingletonOrType(targetEdmBindingTarget.getName()) .navOrPropertyPath(Utility.determinePropertyNavigationPath(uriInfo.getUriResourceParts())) .selectList(selectList) .build(); final ComplexSerializerOptions options = ComplexSerializerOptions.with() .contextURL(contextUrl) .select(uriInfo.getSelectOption()) .expand(uriInfo.getExpandOption()) .build(); if (uriProperty.getProperty().isCollection()) return serializer.complexCollection(serviceMetadata, edmPropertyType, determineProperty(targetEdmBindingTarget, result), options); else return serializer.complex(serviceMetadata, edmPropertyType, determineProperty(targetEdmBindingTarget, result), options); } catch (final URISyntaxException e) { throw new ODataJPASerializerException(e, HttpStatusCode.BAD_REQUEST); } } private Property determineProperty(final EdmBindingTarget targetEdmBindingTarget, final JPAEntityCollectionExtension result) { UriResourceProperty uriProperty = null; Property property = null; boolean found = false; List<Property> properties = result.getFirstResult().getProperties(); for (final UriResource hop : uriInfo.getUriResourceParts()) { if (isTopLevel(hop) && asTopLevel(hop) == targetEdmBindingTarget || hop.getKind().equals(UriResourceKind.navigationProperty) && ((UriResourceNavigation) hop).getType() == targetEdmBindingTarget.getEntityType()) found = true; if (found && hop.getKind().equals(UriResourceKind.complexProperty)) { uriProperty = (UriResourceProperty) hop; property = getProperty(uriProperty.getProperty().getName(), properties); if (!uriProperty.isCollection() && property != null)// Here it is assumed that the collection is the last hop // anyhow properties = ((ComplexValue) property.getValue()).getValue(); } } return property; } protected EdmBindingTarget asTopLevel(final UriResource hop) { return hop.getKind().equals(UriResourceKind.entitySet) ? ((UriResourceEntitySet) hop).getEntitySet() : ((UriResourceSingleton) hop).getSingleton(); } protected boolean isTopLevel(final UriResource hop) { return hop.getKind().equals(UriResourceKind.entitySet) || hop.getKind().equals(UriResourceKind.singleton); } private Property getProperty(final String name, final List<Property> properties) { for (final Property p : properties) if (p.getName().equals(name) && p.isComplex()) return p; return null; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeEntity.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeEntity.java
package com.sap.olingo.jpa.processor.core.serializer; import java.net.URISyntaxException; import org.apache.olingo.commons.api.data.Annotatable; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.edm.EdmBindingTarget; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.serializer.EntitySerializerOptions; import org.apache.olingo.server.api.serializer.ODataSerializer; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerResult; import org.apache.olingo.server.api.uri.UriHelper; import org.apache.olingo.server.api.uri.UriInfoResource; import com.sap.olingo.jpa.processor.core.api.JPAODataSessionContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPASerializerException; import com.sap.olingo.jpa.processor.core.query.Utility; final class JPASerializeEntity implements JPAOperationSerializer { private final ServiceMetadata serviceMetadata; private final UriInfoResource uriInfo; private final UriHelper uriHelper; private final ODataSerializer serializer; private final ContentType responseFormat; private final JPAODataSessionContextAccess serviceContext; JPASerializeEntity(final ServiceMetadata serviceMetadata, final ODataSerializer serializer, final UriHelper uriHelper, final UriInfoResource uriInfo, final ContentType responseFormat, final JPAODataSessionContextAccess context) { this.uriInfo = uriInfo; this.serializer = serializer; this.serviceMetadata = serviceMetadata; this.uriHelper = uriHelper; this.responseFormat = responseFormat; this.serviceContext = context; } @Override public ContentType getContentType() { return responseFormat; } @Override public SerializerResult serialize(final Annotatable annotatable, final EdmType entityType, final ODataRequest request) throws SerializerException, ODataJPASerializerException { final JPAEntityCollectionExtension result = (JPAEntityCollectionExtension) annotatable; final String selectList = uriHelper.buildContextURLSelectList((EdmEntityType) entityType, uriInfo.getExpandOption(), uriInfo.getSelectOption()); try { final ContextURL contextUrl = ContextURL.with() .serviceRoot(buildServiceRoot(request, serviceContext)) .type(entityType) .selectList(selectList) .build(); final EntitySerializerOptions options = EntitySerializerOptions.with() .contextURL(contextUrl) .select(uriInfo.getSelectOption()) .expand(uriInfo.getExpandOption()) .build(); return serializer.entity(serviceMetadata, (EdmEntityType) entityType, result.getFirstResult(), options); } catch (final URISyntaxException e) { throw new ODataJPASerializerException(e, HttpStatusCode.BAD_REQUEST); } } @Override public SerializerResult serialize(final ODataRequest request, final JPAEntityCollectionExtension result) throws SerializerException, ODataJPASerializerException { final EdmBindingTarget targetEdmBindingTarget = Utility.determineBindingTarget(uriInfo.getUriResourceParts()); final EdmEntityType entityType = targetEdmBindingTarget.getEntityType(); return serialize((Annotatable) result, entityType, request); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializePrimitiveCollection.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializePrimitiveCollection.java
package com.sap.olingo.jpa.processor.core.serializer; import java.net.URISyntaxException; import org.apache.olingo.commons.api.data.Annotatable; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.serializer.ODataSerializer; import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerResult; import com.sap.olingo.jpa.processor.core.api.JPAODataSessionContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPASerializerException; final class JPASerializePrimitiveCollection implements JPAOperationSerializer { private final ServiceMetadata serviceMetadata; private final ODataSerializer serializer; private final ContentType responseFormat; private final JPAODataSessionContextAccess serviceContext; JPASerializePrimitiveCollection(final ServiceMetadata serviceMetadata, final ODataSerializer serializer, final ContentType responseFormat, final JPAODataSessionContextAccess context) { this.serializer = serializer; this.serviceMetadata = serviceMetadata; this.responseFormat = responseFormat; this.serviceContext = context; } @Override public ContentType getContentType() { return responseFormat; } @Override public SerializerResult serialize(final Annotatable result, final EdmType primitiveType, final ODataRequest request) throws SerializerException, ODataJPASerializerException { try { final ContextURL contextUrl = ContextURL.with() .serviceRoot(buildServiceRoot(request, serviceContext)) .asCollection() .build(); final PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextUrl).build(); return serializer.primitiveCollection(serviceMetadata, (EdmPrimitiveType) primitiveType, (Property) result, options); } catch (final URISyntaxException e) { throw new ODataJPASerializerException(e, HttpStatusCode.BAD_REQUEST); } } @Override public SerializerResult serialize(final ODataRequest request, final JPAEntityCollectionExtension result) throws SerializerException, ODataJPASerializerException { return null; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeFunction.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeFunction.java
package com.sap.olingo.jpa.processor.core.serializer; import java.util.List; import java.util.Optional; import org.apache.olingo.commons.api.data.Annotatable; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.edm.constants.EdmTypeKind; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerResult; import org.apache.olingo.server.api.uri.UriInfoResource; import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourceAction; import org.apache.olingo.server.api.uri.UriResourceFunction; import org.apache.olingo.server.api.uri.UriResourcePartTyped; import com.sap.olingo.jpa.processor.core.exception.ODataJPASerializerException; final class JPASerializeFunction implements JPAOperationSerializer { private final JPAOperationSerializer serializer; public JPASerializeFunction(final UriInfoResource uriInfo, final ContentType responseFormat, final JPASerializerFactory jpaSerializerFactory, final Optional<List<String>> responseVersion) throws ODataJPASerializerException, SerializerException { this.serializer = (JPAOperationSerializer) createSerializer(jpaSerializerFactory, responseFormat, uriInfo, responseVersion); } @Override public SerializerResult serialize(final ODataRequest request, final JPAEntityCollectionExtension result) throws SerializerException, ODataJPASerializerException { return serializer.serialize(request, result); } @Override public SerializerResult serialize(final Annotatable annotatable, final EdmType entityType, final ODataRequest request) throws SerializerException, ODataJPASerializerException { return serializer.serialize(annotatable, entityType, request); } JPASerializer getSerializer() { return serializer; } private JPASerializer createSerializer(final JPASerializerFactory jpaSerializerFactory, final ContentType responseFormat, final UriInfoResource uriInfo, final Optional<List<String>> responseVersion) throws ODataJPASerializerException, SerializerException { final List<UriResource> resourceParts = uriInfo.getUriResourceParts(); final UriResourcePartTyped operation = (UriResourcePartTyped) resourceParts.get(resourceParts.size() - 1); final EdmTypeKind edmTypeKind = determineReturnEdmTypeKind(operation); return jpaSerializerFactory.createSerializer(responseFormat, uriInfo, edmTypeKind, operation.isCollection(), responseVersion); } private EdmTypeKind determineReturnEdmTypeKind(final UriResourcePartTyped operation) { if (operation instanceof final UriResourceFunction resourceFunction) return resourceFunction.getFunction().getReturnType().getType().getKind(); else return ((UriResourceAction) operation).getAction().getReturnType().getType().getKind(); } @Override public ContentType getContentType() { return this.serializer.getContentType(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeValue.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeValue.java
package com.sap.olingo.jpa.processor.core.serializer; import java.io.InputStream; import java.util.List; import org.apache.olingo.commons.api.data.Annotatable; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.serializer.FixedFormatSerializer; import org.apache.olingo.server.api.serializer.PrimitiveValueSerializerOptions; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerResult; import org.apache.olingo.server.api.uri.UriInfoResource; import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourceEntitySet; import org.apache.olingo.server.api.uri.UriResourceNavigation; import org.apache.olingo.server.api.uri.UriResourceProperty; import com.sap.olingo.jpa.processor.core.exception.ODataJPASerializerException; final class JPASerializeValue extends JPASerializePrimitiveAbstract { private final FixedFormatSerializer serializer; JPASerializeValue(final ServiceMetadata serviceMetadata, final FixedFormatSerializer serializer, final UriInfoResource uriInfo) { super(serviceMetadata, uriInfo); this.serializer = serializer; } @Override public SerializerResult serialize(final ODataRequest request, final JPAEntityCollectionExtension result) throws SerializerException, ODataJPASerializerException { final var first = result.getFirstResult(); if (first == null || first.getProperties() == null || first.getProperties().isEmpty()) { throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.RESULT_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); } InputStream serializerResult = null; if (isStream()) { final EdmEntityType edmEt = serviceMetadata.getEdm().getEntityType(new FullQualifiedName(first.getType())); final List<EdmKeyPropertyRef> keyProperties = edmEt.getKeyPropertyRefs(); Property property = null; for (final Property item : first.getProperties()) { if (!isKey(keyProperties, item)) { property = item; break; } } if (property == null) throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.RESULT_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); serializerResult = serializer.binary((byte[]) property.getValue()); } else { final UriResourceProperty uriProperty = (UriResourceProperty) uriInfo.getUriResourceParts().get(uriInfo .getUriResourceParts().size() - 2); final EdmPrimitiveType edmPropertyType = (EdmPrimitiveType) uriProperty.getType(); final var info = determinePrimitiveProperty(result, uriInfo.getUriResourceParts()); final var options = PrimitiveValueSerializerOptions.with().build(); if (!info.property().isNull()) serializerResult = serializer.primitiveValue(edmPropertyType, info.property().getValue(), options); } return new JPAValueSerializerResult(serializerResult); } @Override public SerializerResult serialize(final Annotatable result, final EdmType entityType, final ODataRequest request) throws SerializerException, ODataJPASerializerException { final PrimitiveValueSerializerOptions options = PrimitiveValueSerializerOptions.with().build(); return new JPAValueSerializerResult(serializer.primitiveValue((EdmPrimitiveType) entityType, ((Property) result) .getValue(), options)); } private boolean isStream() { final UriResource successor = uriInfo.getUriResourceParts().get(uriInfo.getUriResourceParts().size() - 2); return (successor instanceof UriResourceEntitySet || successor instanceof final UriResourceNavigation resourceNavigation && resourceNavigation .getType() instanceof EdmEntityType); } private boolean isKey(final List<EdmKeyPropertyRef> keyList, final Property item) { for (final EdmKeyPropertyRef key : keyList) { if (key.getName().equals(item.getName())) return true; } return false; } @Override public ContentType getContentType() { return ContentType.TEXT_PLAIN; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPAValueSerializerResult.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPAValueSerializerResult.java
package com.sap.olingo.jpa.processor.core.serializer; import java.io.InputStream; import org.apache.olingo.server.api.serializer.SerializerResult; final class JPAValueSerializerResult implements SerializerResult { /** * */ private final InputStream result; public JPAValueSerializerResult(final InputStream inputStream) { this.result = inputStream; } @Override public InputStream getContent() { return result; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeCreate.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializeCreate.java
package com.sap.olingo.jpa.processor.core.serializer; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.edm.EdmBindingTarget; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.serializer.EntitySerializerOptions; import org.apache.olingo.server.api.serializer.ODataSerializer; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerResult; import org.apache.olingo.server.api.uri.UriInfoResource; import org.apache.olingo.server.api.uri.queryoption.ApplyOption; import org.apache.olingo.server.api.uri.queryoption.CountOption; import org.apache.olingo.server.api.uri.queryoption.ExpandItem; import org.apache.olingo.server.api.uri.queryoption.ExpandOption; import org.apache.olingo.server.api.uri.queryoption.FilterOption; import org.apache.olingo.server.api.uri.queryoption.LevelsExpandOption; import org.apache.olingo.server.api.uri.queryoption.OrderByOption; import org.apache.olingo.server.api.uri.queryoption.SearchOption; import org.apache.olingo.server.api.uri.queryoption.SelectOption; import org.apache.olingo.server.api.uri.queryoption.SkipOption; import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind; import org.apache.olingo.server.api.uri.queryoption.TopOption; import com.sap.olingo.jpa.processor.core.api.JPAODataSessionContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPASerializerException; import com.sap.olingo.jpa.processor.core.query.Utility; final class JPASerializeCreate implements JPASerializer { private final ServiceMetadata serviceMetadata; private final UriInfoResource uriInfo; private final ODataSerializer serializer; private final JPAODataSessionContextAccess serviceContext; public JPASerializeCreate(final ServiceMetadata serviceMetadata, final ODataSerializer serializer, final UriInfoResource uriInfo, final JPAODataSessionContextAccess serviceContext) { this.uriInfo = uriInfo; this.serializer = serializer; this.serviceMetadata = serviceMetadata; this.serviceContext = serviceContext; } @Override public ContentType getContentType() { return null; } @Override public SerializerResult serialize(final ODataRequest request, final JPAEntityCollectionExtension result) throws SerializerException, ODataJPASerializerException { final ExpandOption expandOption = new ExpandOptionWrapper(new ExpandItemWrapper()); final EdmBindingTarget targetEdmBindingTarget = Utility.determineBindingTarget(uriInfo.getUriResourceParts()); final EdmEntityType entityType = targetEdmBindingTarget.getEntityType(); try { final ContextURL contextUrl = ContextURL.with() .serviceRoot(buildServiceRoot(request, serviceContext)) .entitySetOrSingletonOrType(targetEdmBindingTarget.getName()) .build(); final EntitySerializerOptions options = EntitySerializerOptions.with() .contextURL(contextUrl) .expand(expandOption) .build(); return serializer.entity(serviceMetadata, entityType, result .getEntities() .get(0), options); } catch (final URISyntaxException e) { throw new ODataJPASerializerException(e, HttpStatusCode.BAD_REQUEST); } } private static class ExpandItemWrapper implements ExpandItem { @Override public ApplyOption getApplyOption() { return null; } @Override public CountOption getCountOption() { return null; } @Override public ExpandOption getExpandOption() { return null; } @Override public FilterOption getFilterOption() { return null; } @Override public LevelsExpandOption getLevelsOption() { return null; } @Override public OrderByOption getOrderByOption() { return null; } @Override public UriInfoResource getResourcePath() { return null; } @Override public SearchOption getSearchOption() { return null; } @Override public SelectOption getSelectOption() { return null; } @Override public SkipOption getSkipOption() { return null; } @Override public EdmType getStartTypeFilter() { return null; } @Override public TopOption getTopOption() { return null; } @Override public boolean hasCountPath() { return false; } @Override public boolean isRef() { return false; } @Override public boolean isStar() { return true; } } private static class ExpandOptionWrapper implements ExpandOption { private final List<ExpandItem> items = new ArrayList<>(1); public ExpandOptionWrapper(final ExpandItemWrapper expandItemWrapper) { items.add(expandItemWrapper); } @Override public List<ExpandItem> getExpandItems() { return items; } @Override public SystemQueryOptionKind getKind() { return SystemQueryOptionKind.EXPAND; } @Override public String getName() { return null; } @Override public String getText() { return null; } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPAEntityCollectionLazy.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPAEntityCollectionLazy.java
package com.sap.olingo.jpa.processor.core.serializer; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import java.util.Optional; import javax.annotation.Nonnull; import javax.annotation.Nullable; import jakarta.persistence.Tuple; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.server.api.ODataApplicationException; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.cache.InstanceCache; import com.sap.olingo.jpa.metadata.core.edm.mapper.cache.InstanceCacheSupplier; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.converter.JPAExpandResult; import com.sap.olingo.jpa.processor.core.converter.JPARowConverter; public class JPAEntityCollectionLazy extends EntityCollection implements JPAEntityCollectionExtension { private final JPAExpandResult jpaResult; private final JPAEntityType jpaEntity; private final JPARowConverter converter; private final InstanceCache<Entity> firstEntity; public JPAEntityCollectionLazy(final JPAExpandResult result, final JPARowConverter converter) { super(); this.jpaResult = result; this.jpaEntity = jpaResult.getEntityType(); this.converter = converter; this.firstEntity = new InstanceCacheSupplier<>(this::createFirstResult); } @Override public List<Entity> getEntities() { return List.of(); } @Override public Iterator<Entity> iterator() { return new EntityIterator(this.jpaResult.getResult(JPAExpandResult.ROOT_RESULT_KEY), converter, getFirstResult()); } @Override public boolean hasResults() { return !jpaResult.getResult(JPAExpandResult.ROOT_RESULT_KEY).isEmpty(); } @Override public boolean hasSingleResult() { return jpaResult.getResult(JPAExpandResult.ROOT_RESULT_KEY).size() == 1; } @Override public Entity getFirstResult() { try { return firstEntity.get().orElse(null); } catch (final ODataJPAModelException e) { throw new IllegalStateException(e); } } @Override public int hashCode() { return super.hashCode(); } @Override public boolean equals(final Object other) { return super.equals(other); } private Entity createFirstResult() { if (!jpaResult.getResult(JPAExpandResult.ROOT_RESULT_KEY).isEmpty()) { try { return converter.convertRow(jpaEntity, jpaResult.getResult(JPAExpandResult.ROOT_RESULT_KEY).set(0, null), jpaResult.getRequestedSelection(), List.of(), jpaResult); } catch (final ODataApplicationException e) { throw new IllegalStateException(e); } } return null; } private class EntityIterator implements Iterator<Entity> { private int cursor; // index of next element to return private final int size; private final List<Tuple> entities; private final JPARowConverter converter; private final Optional<Entity> firstResult; // prevent creating a synthetic constructor private EntityIterator(@Nonnull final List<Tuple> results, @Nonnull final JPARowConverter converter, @Nullable final Entity firstResult) { this.entities = results; this.size = results.size(); this.converter = converter; this.firstResult = Optional.ofNullable(firstResult); } @Override public boolean hasNext() { return firstResult.isPresent() && cursor != size; } @Override public Entity next() { final int i = cursor; if (i >= size) throw new NoSuchElementException(); cursor = i + 1; if (i == 0) return firstResult.get(); final var row = entities.set(i, null); try { return converter.convertRow(jpaEntity, row, jpaResult.getRequestedSelection(), List.of(), jpaResult); } catch (final ODataApplicationException e) { throw new IllegalStateException(e); } } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializer.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializer.java
package com.sap.olingo.jpa.processor.core.serializer; import java.net.URI; import java.net.URISyntaxException; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.serializer.SerializerResult; import com.sap.olingo.jpa.processor.core.api.JPAODataSessionContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPASerializerException; public interface JPASerializer { public SerializerResult serialize(final ODataRequest request, final JPAEntityCollectionExtension result) throws SerializerException, ODataJPASerializerException; public ContentType getContentType(); default URI buildServiceRoot(final ODataRequest request, final JPAODataSessionContextAccess serviceContext) throws URISyntaxException { final String pathSeparator = "/"; if (serviceContext.useAbsoluteContextURL()) { final String serviceRoot = request.getRawBaseUri(); if (serviceRoot == null) return null; return new URI(serviceRoot.endsWith(pathSeparator) ? serviceRoot : (serviceRoot + pathSeparator)); } return null; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializerFactory.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/serializer/JPASerializerFactory.java
package com.sap.olingo.jpa.processor.core.serializer; import java.util.Collections; import java.util.List; import java.util.Optional; import org.apache.olingo.commons.api.edm.constants.EdmTypeKind; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.serializer.ODataSerializer; import org.apache.olingo.server.api.serializer.SerializerException; import org.apache.olingo.server.api.uri.UriHelper; import org.apache.olingo.server.api.uri.UriInfoResource; import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourceKind; import org.apache.olingo.server.api.uri.UriResourcePartTyped; import com.sap.olingo.jpa.processor.core.api.JPAODataSessionContextAccess; import com.sap.olingo.jpa.processor.core.exception.ODataJPASerializerException; public final class JPASerializerFactory { private final ServiceMetadata serviceMetadata; private final OData odata; private final UriHelper uriHelper; private final JPAODataSessionContextAccess serviceContext; public JPASerializerFactory(final OData odata, final ServiceMetadata serviceMetadata, final JPAODataSessionContextAccess serviceContext) { this.odata = odata; this.serviceMetadata = serviceMetadata; this.uriHelper = odata.createUriHelper(); this.serviceContext = serviceContext; } public JPASerializer createCUDSerializer(final ContentType responseFormat, final UriInfoResource uriInfo, final Optional<List<String>> responseVersion) throws SerializerException { final ODataSerializer serializer = odata.createSerializer(responseFormat, responseVersion.orElse(Collections.emptyList())); return new JPASerializeCreate(serviceMetadata, serializer, uriInfo, serviceContext); } public JPASerializer createSerializer(final ContentType responseFormat, final UriInfoResource uriInfo, final Optional<List<String>> responseVersion) throws ODataApplicationException, SerializerException { // Assumption: Type of last resource path item rules the type of the response final List<UriResource> resourceParts = uriInfo.getUriResourceParts(); final UriResource lastItem = resourceParts.get(resourceParts.size() - 1); final boolean isCollection = determineIsCollection(lastItem); return createSerializer(responseFormat, uriInfo, lastItem.getKind(), isCollection, responseVersion); } public ServiceMetadata getServiceMetadata() { return serviceMetadata; } JPASerializer createSerializer(final ContentType responseFormat, final UriInfoResource uriInfo, final EdmTypeKind edmTypeKind, final boolean isCollection, final Optional<List<String>> responseVersion) throws SerializerException, ODataJPASerializerException { final ODataSerializer serializer = odata.createSerializer(responseFormat, responseVersion.orElse(Collections.emptyList())); switch (edmTypeKind) { case ENTITY: if (isCollection) return new JPASerializeEntityCollection(serviceMetadata, serializer, uriHelper, uriInfo, responseFormat, serviceContext); else return new JPASerializeEntity(serviceMetadata, serializer, uriHelper, uriInfo, responseFormat, serviceContext); case COMPLEX: if (isCollection) return new JPASerializeComplexCollection(serviceMetadata, serializer, responseFormat, serviceContext); else return new JPASerializeComplex(serviceMetadata, serializer, uriHelper, uriInfo, responseFormat, serviceContext); case PRIMITIVE: if (isCollection) return new JPASerializePrimitiveCollection(serviceMetadata, serializer, responseFormat, serviceContext); else return new JPASerializePrimitive(serviceMetadata, serializer, uriInfo, responseFormat, serviceContext); default: throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.NOT_SUPPORTED_RESOURCE_TYPE, HttpStatusCode.NOT_IMPLEMENTED, edmTypeKind.toString()); } } JPASerializer createSerializer(final ContentType responseFormat, final UriInfoResource uriInfo, final UriResourceKind uriResourceKind, final boolean isCollection, final Optional<List<String>> responseVersion) throws SerializerException, ODataJPASerializerException { switch (uriResourceKind) { case entitySet, navigationProperty, singleton: return createSerializerCollectionRequest(responseFormat, uriInfo, isCollection, responseVersion); case complexProperty: return createSerializerComplexPropertyRequest(responseFormat, uriInfo, responseVersion); case primitiveProperty: return createSerializerPrimitivePropertyRequest(responseFormat, uriInfo, responseVersion); case action, function: return new JPASerializeFunction(uriInfo, responseFormat, this, responseVersion); case count: return new JPASerializeCount(odata.createFixedFormatSerializer()); case value: return new JPASerializeValue(serviceMetadata, odata.createFixedFormatSerializer(), uriInfo); default: throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.NOT_SUPPORTED_RESOURCE_TYPE, HttpStatusCode.NOT_IMPLEMENTED, uriResourceKind.toString()); } } private JPASerializer createSerializerCollectionRequest(final ContentType responseFormat, final UriInfoResource uriInfo, final boolean isCollection, final Optional<List<String>> responseVersion) throws SerializerException { final ODataSerializer serializer = odata.createSerializer(responseFormat, responseVersion.orElse(Collections.emptyList())); if (isCollection) return new JPASerializeEntityCollection(serviceMetadata, serializer, uriHelper, uriInfo, responseFormat, serviceContext); else return new JPASerializeEntity(serviceMetadata, serializer, uriHelper, uriInfo, responseFormat, serviceContext); } private JPASerializer createSerializerComplexPropertyRequest(final ContentType responseFormat, final UriInfoResource uriInfo, final Optional<List<String>> responseVersion) throws SerializerException { final ODataSerializer serializer = odata.createSerializer(responseFormat, responseVersion.orElse(Collections.emptyList())); return new JPASerializeComplex(serviceMetadata, serializer, uriHelper, uriInfo, responseFormat, serviceContext); } private JPASerializer createSerializerPrimitivePropertyRequest(final ContentType responseFormat, final UriInfoResource uriInfo, final Optional<List<String>> responseVersion) throws SerializerException { final ODataSerializer serializer = odata.createSerializer(responseFormat, responseVersion.orElse(Collections.emptyList())); return new JPASerializePrimitive(serviceMetadata, serializer, uriInfo, responseFormat, serviceContext); } private boolean determineIsCollection(final UriResource lastItem) { if (lastItem instanceof final UriResourcePartTyped lastTyped) return lastTyped.isCollection(); return false; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/helper/AbstractWatchDog.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/helper/AbstractWatchDog.java
package com.sap.olingo.jpa.processor.core.helper; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlCollection; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlDynamicExpression; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlExpression; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlNavigationPropertyPath; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPropertyPath; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPropertyValue; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlRecord; public class AbstractWatchDog { public AbstractWatchDog() { super(); } protected Optional<String> determineConstantExpression(final Map<String, CsdlExpression> properties, final String propertyName) { return Optional.ofNullable(properties.get(propertyName)) .map(CsdlExpression::asConstant) .map(CsdlConstantExpression::getValue); } protected List<CsdlExpression> getItems(final Map<String, CsdlExpression> properties, final String property) { return Optional.ofNullable(properties.get(property)) .map(CsdlExpression::asDynamic) .map(CsdlDynamicExpression::asCollection) .map(CsdlCollection::getItems) .orElseGet(Collections::emptyList); } protected List<String> getPathItems(final Map<String, CsdlExpression> properties, final String property) { return getItems(properties, property) .stream() .map(CsdlExpression::asDynamic) .map(CsdlDynamicExpression::asPropertyPath) .map(CsdlPropertyPath::getValue) .toList(); } protected List<String> getNavigationPathItems(final Map<String, CsdlExpression> properties, final String property) { return getItems(properties, property) .stream() .map(CsdlExpression::asDynamic) .map(CsdlDynamicExpression::asNavigationPropertyPath) .map(CsdlNavigationPropertyPath::getValue) .toList(); } protected Map<String, CsdlExpression> getAnnotationProperties(final Optional<CsdlAnnotation> annotation) { return annotation .map(CsdlAnnotation::getExpression) .map(CsdlExpression::asDynamic) .map(CsdlDynamicExpression::asRecord) .map(CsdlRecord::getPropertyValues) .orElse(Collections.emptyList()) .stream() .collect(Collectors.toMap(CsdlPropertyValue::getProperty, CsdlPropertyValue::getValue)); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAAbstractDatabaseProcessor.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAAbstractDatabaseProcessor.java
package com.sap.olingo.jpa.processor.core.database; import static com.sap.olingo.jpa.processor.core.exception.ODataJPADBAdaptorException.MessageKeys.PARAMETER_CONVERSION_ERROR; import static com.sap.olingo.jpa.processor.core.exception.ODataJPADBAdaptorException.MessageKeys.PARAMETER_MISSING; import static com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException.MessageKeys.NOT_SUPPORTED_FUNC_WITH_NAVI; import static org.apache.olingo.commons.api.http.HttpStatusCode.BAD_REQUEST; import static org.apache.olingo.commons.api.http.HttpStatusCode.INTERNAL_SERVER_ERROR; import java.util.ArrayList; import java.util.List; import jakarta.persistence.EntityManager; import jakarta.persistence.Query; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.From; import org.apache.olingo.commons.api.edm.EdmElement; import org.apache.olingo.commons.api.edm.EdmFunction; import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.uri.UriParameter; import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourceEntitySet; import org.apache.olingo.server.api.uri.UriResourceFunction; import org.apache.olingo.server.api.uri.UriResourceKind; import org.apache.olingo.server.api.uri.queryoption.SearchOption; import com.sap.olingo.jpa.metadata.api.JPAHttpHeaderMap; import com.sap.olingo.jpa.metadata.api.JPARequestParameterMap; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPADataBaseFunction; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAParameter; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.processor.core.api.JPAODataDatabaseProcessor; import com.sap.olingo.jpa.processor.core.exception.ODataJPADBAdaptorException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; public abstract class JPAAbstractDatabaseProcessor implements JPAODataDatabaseProcessor { static final String FUNC_NAME_PLACEHOLDER = "$FUNCTIONNAME$"; static final String PARAMETER_PLACEHOLDER = "$PARAMETER$"; @Override public Expression<Boolean> createSearchWhereClause(final CriteriaBuilder cb, final CriteriaQuery<?> criteriaQuery, final From<?, ?> root, final JPAEntityType entityType, final SearchOption searchOption) throws ODataApplicationException { throw new ODataJPADBAdaptorException(ODataJPADBAdaptorException.MessageKeys.NOT_SUPPORTED_SEARCH, HttpStatusCode.NOT_IMPLEMENTED); } @Override public Object executeFunctionQuery(final List<UriResource> uriResourceParts, final JPADataBaseFunction jpaFunction, final EntityManager em, final JPAHttpHeaderMap headers, final JPARequestParameterMap parameters) throws ODataApplicationException { final UriResource last = uriResourceParts.get(uriResourceParts.size() - 1); if (last.getKind() == UriResourceKind.count) { final List<Long> countResult = new ArrayList<>(); countResult.add(executeCountQuery(uriResourceParts, jpaFunction, em, functionCountPattern())); return countResult; } if (last.getKind() == UriResourceKind.function) return executeQuery(uriResourceParts, jpaFunction, em, functionSelectPattern()); throw new ODataJPAProcessorException(NOT_SUPPORTED_FUNC_WITH_NAVI, HttpStatusCode.NOT_IMPLEMENTED); } protected String functionSelectPattern() { throw new IllegalAccessError(); } protected String functionCountPattern() { throw new IllegalAccessError(); } protected UriResourceEntitySet determineTargetEntitySet(final List<UriResource> uriParts) { for (int i = uriParts.size() - 1; i >= 0; i--) { if (uriParts.get(i).getKind() == UriResourceKind.entitySet) return (UriResourceEntitySet) uriParts.get(i); } return null; } @SuppressWarnings("unchecked") protected <T> List<T> executeQuery(final List<UriResource> uriParts, final JPADataBaseFunction jpaFunction, final EntityManager em, final String pattern) throws ODataApplicationException { final UriResourceFunction uriFunction = (UriResourceFunction) uriParts.get(uriParts.size() - 1); final String queryString = generateQueryString(pattern, jpaFunction); final Query functionQuery = em.createNativeQuery(queryString, jpaFunction.getResultParameter().getType()); fillParameter(determineTargetEntitySet(uriParts), jpaFunction, uriFunction, functionQuery); return functionQuery.getResultList(); } protected void fillParameter(final UriResourceEntitySet es, final JPADataBaseFunction jpaFunction, final UriResourceFunction uriResourceFunction, final Query functionQuery) throws ODataApplicationException { try { if (jpaFunction.isBound() && uriResourceFunction.getParameters().isEmpty()) fillParameterFromEntity(jpaFunction, es, functionQuery); else fillParameterFromFunction(jpaFunction, uriResourceFunction, functionQuery); } catch (final ODataJPAModelException e) { throw new ODataJPAProcessorException(e, INTERNAL_SERVER_ERROR); } } protected String generateQueryString(final String queryPattern, final JPADataBaseFunction jpaFunction) throws ODataJPAProcessorException { final StringBuilder parameterList = new StringBuilder(); final String queryString = queryPattern.replace(FUNC_NAME_PLACEHOLDER, jpaFunction.getDBName()); try { for (int i = 1; i <= jpaFunction.getParameter().size(); i++) { parameterList.append(','); parameterList.append('?'); parameterList.append(i); } } catch (final ODataJPAModelException e) { throw new ODataJPAProcessorException(e, INTERNAL_SERVER_ERROR); } parameterList.deleteCharAt(0); return queryString.replace(PARAMETER_PLACEHOLDER, parameterList.toString()); } protected UriParameter findParameterByExternalName(final JPAParameter parameter, final List<UriParameter> uriParameters) throws ODataApplicationException { for (final UriParameter uriParameter : uriParameters) { if (uriParameter.getName().equals(parameter.getName())) return uriParameter; } throw new ODataJPADBAdaptorException(PARAMETER_MISSING, BAD_REQUEST, parameter.getName()); } protected void fillParameterFromEntity(final JPADataBaseFunction jpaFunction, final UriResourceEntitySet es, final Query functionQuery) throws ODataApplicationException { int count = 1; try { for (final JPAParameter parameter : jpaFunction.getParameter()) { final UriParameter uriParameter = findParameterByExternalName(parameter, es.getKeyPredicates()); final Object value = getValue(es.getEntityType().getProperty(parameter.getName()), parameter, uriParameter .getText()); functionQuery.setParameter(count, value); count += 1; } } catch (final ODataJPAModelException e) { throw new ODataJPAProcessorException(e, INTERNAL_SERVER_ERROR); } } protected Long executeCountQuery(final List<UriResource> uriParts, final JPADataBaseFunction jpaFunction, final EntityManager em, final String pattern) throws ODataApplicationException { final UriResourceFunction uriFunction = (UriResourceFunction) uriParts.get(uriParts.size() - 2); final String queryString = generateQueryString(pattern, jpaFunction); final Query functionQuery = em.createNativeQuery(queryString); fillParameter(determineTargetEntitySet(uriParts), jpaFunction, uriFunction, functionQuery); return (Long) functionQuery.getSingleResult(); } protected void fillParameterFromFunction(final JPADataBaseFunction jpaFunction, final UriResourceFunction uriResourceFunction, final Query functionQuery) throws ODataApplicationException { final EdmFunction edmFunction = uriResourceFunction.getFunction(); int count = 1; try { for (final JPAParameter parameter : jpaFunction.getParameter()) { final UriParameter uriParameter = findParameterByExternalName(parameter, uriResourceFunction.getParameters()); final Object value = getValue(edmFunction.getParameter(parameter.getName()), parameter, uriParameter.getText()); functionQuery.setParameter(count, value); count += 1; } } catch (final ODataJPAModelException e) { throw new ODataJPAProcessorException(e, INTERNAL_SERVER_ERROR); } } private Object getValue(final EdmElement edmElement, final JPAParameter parameter, final String uriValue) throws ODataApplicationException { final String value = uriValue.replace("'", ""); try { return ((EdmPrimitiveType) edmElement.getType()).valueOfString(value, false, parameter.getMaxLength(), parameter.getPrecision(), parameter.getScale(), true, parameter.getType()); } catch (final EdmPrimitiveTypeException e) { // Unable to convert value %1$s of parameter %2$s throw new ODataJPADBAdaptorException(PARAMETER_CONVERSION_ERROR, INTERNAL_SERVER_ERROR, e, uriValue, parameter .getName()); } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPADerbySqlPatternProvider.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPADerbySqlPatternProvider.java
package com.sap.olingo.jpa.processor.core.database; import java.util.Arrays; import com.sap.olingo.jpa.processor.cb.ProcessorSqlFunction; import com.sap.olingo.jpa.processor.cb.ProcessorSqlOperator; import com.sap.olingo.jpa.processor.cb.ProcessorSqlParameter; import com.sap.olingo.jpa.processor.cb.ProcessorSqlPattern; import com.sap.olingo.jpa.processor.cb.ProcessorSqlPatternProvider; public class JPADerbySqlPatternProvider implements ProcessorSqlPatternProvider { static final String MAX_RESULTS_PATTERN = "FETCH NEXT " + VALUE_PLACEHOLDER + " ROWS ONLY"; static final String FIRST_RESULT_PATTERN = "OFFSET " + VALUE_PLACEHOLDER + " ROWS"; /** * <a href="https://db.apache.org/derby/docs/10.17/ref/rrefsqlj40899.html">Concatenation operator</a> */ @Override public ProcessorSqlPattern getConcatenatePattern() { return new ProcessorSqlOperator(Arrays.asList( new ProcessorSqlParameter(VALUE_PLACEHOLDER, false), new ProcessorSqlParameter(" || ", VALUE_PLACEHOLDER, false))); } /** * <a href="https://db.apache.org/derby/docs/10.17/ref/rrefsqlj93082.html">SUBSTR function</a> */ @Override public ProcessorSqlFunction getSubStringPattern() { return new ProcessorSqlFunction("SUBSTR", Arrays.asList( new ProcessorSqlParameter(VALUE_PLACEHOLDER, false), new ProcessorSqlParameter(START_PLACEHOLDER, false), new ProcessorSqlParameter(LENGTH_PLACEHOLDER, true))); } /** * <a href="https://db.apache.org/derby/docs/10.17/ref/rrefsqljoffsetfetch.html">Offset and fetch</a> */ @Override public String getMaxResultsPattern() { return MAX_RESULTS_PATTERN; } /** * <a href="https://db.apache.org/derby/docs/10.17/ref/rrefsqljoffsetfetch.html">Offset and fetch</a> */ @Override public String getFirstResultPattern() { return FIRST_RESULT_PATTERN; } @Override public boolean maxResultsFirst() { return false; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPADefaultDatabaseProcessor.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPADefaultDatabaseProcessor.java
package com.sap.olingo.jpa.processor.core.database; import static com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException.MessageKeys.NOT_SUPPORTED_FUNC_WITH_NAVI; import java.util.ArrayList; import java.util.List; import jakarta.persistence.EntityManager; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.From; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourceKind; import org.apache.olingo.server.api.uri.queryoption.SearchOption; import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind; import com.sap.olingo.jpa.metadata.api.JPAHttpHeaderMap; import com.sap.olingo.jpa.metadata.api.JPARequestParameterMap; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPADataBaseFunction; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.processor.core.exception.ODataJPADBAdaptorException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAFilterException; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; import com.sap.olingo.jpa.processor.core.filter.JPAAggregationOperation; import com.sap.olingo.jpa.processor.core.filter.JPAArithmeticOperator; import com.sap.olingo.jpa.processor.core.filter.JPABooleanOperator; import com.sap.olingo.jpa.processor.core.filter.JPAComparisonOperator; import com.sap.olingo.jpa.processor.core.filter.JPAEnumerationBasedOperator; import com.sap.olingo.jpa.processor.core.filter.JPAMethodCall; import com.sap.olingo.jpa.processor.core.filter.JPAUnaryBooleanOperator; public class JPADefaultDatabaseProcessor extends JPAAbstractDatabaseProcessor implements JPAODataDatabaseOperations { private static final String SELECT_BASE_PATTERN = "SELECT * FROM $FUNCTIONNAME$($PARAMETER$)"; private static final String SELECT_COUNT_PATTERN = "SELECT COUNT(*) FROM $FUNCTIONNAME$($PARAMETER$)"; private CriteriaBuilder cb; @Override public Expression<Long> convert(final JPAAggregationOperation jpaOperator) throws ODataApplicationException { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_OPERATOR, HttpStatusCode.NOT_IMPLEMENTED, jpaOperator.getName()); } @Override public <T extends Number> Expression<T> convert(final JPAArithmeticOperator jpaOperator) throws ODataApplicationException { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_OPERATOR, HttpStatusCode.NOT_IMPLEMENTED, jpaOperator.getName()); } @Override public Expression<Boolean> convert(final JPABooleanOperator jpaOperator) throws ODataApplicationException { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_OPERATOR, HttpStatusCode.NOT_IMPLEMENTED, jpaOperator.getName()); } @Override public Expression<Boolean> convert(@SuppressWarnings("rawtypes") final JPAComparisonOperator jpaOperator) throws ODataApplicationException { if (jpaOperator.getOperator().equals(BinaryOperatorKind.HAS)) { /* * HAS requires an bitwise AND. This is not part of SQL and so not part of the criterion builder. Different * databases have different ways to support this. One group uses a function, which is called BITAND e.g. H2, * HSQLDB, SAP HANA, DB2 or ORACLE, others have created an operator '&' like PostgesSQL or MySQL. * To provide a unique, but slightly slower, solution a workaround is used, see * https://stackoverflow.com/questions/20570481/jpa-oracle-bit-operations-using-criteriabuilder#25508741 */ final Number n = ((JPAEnumerationBasedOperator) jpaOperator.getRight()).getValue(); @SuppressWarnings("unchecked") final Expression<Integer> div = cb.quot(jpaOperator.getLeft(), n); final Expression<Integer> mod = cb.mod(div, 2); return cb.equal(mod, 1); } throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_OPERATOR, HttpStatusCode.NOT_IMPLEMENTED, jpaOperator.getName()); } @Override public <T> Expression<T> convert(final JPAMethodCall jpaFunction) throws ODataApplicationException { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_OPERATOR, HttpStatusCode.NOT_IMPLEMENTED, jpaFunction.getName()); } @Override public Expression<Boolean> convert(final JPAUnaryBooleanOperator jpaOperator) throws ODataApplicationException { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_OPERATOR, HttpStatusCode.NOT_IMPLEMENTED, jpaOperator.getName()); } @Override public Expression<Boolean> createSearchWhereClause(final CriteriaBuilder cb, final CriteriaQuery<?> cq, final From<?, ?> root, final JPAEntityType entityType, final SearchOption searchOption) throws ODataApplicationException { throw new ODataJPADBAdaptorException(ODataJPADBAdaptorException.MessageKeys.NOT_SUPPORTED_SEARCH, HttpStatusCode.NOT_IMPLEMENTED); } @Override public Object executeFunctionQuery(final List<UriResource> uriResourceParts, final JPADataBaseFunction jpaFunction, final EntityManager em, final JPAHttpHeaderMap headers, final JPARequestParameterMap parameters) throws ODataApplicationException { final UriResource last = uriResourceParts.get(uriResourceParts.size() - 1); if (last.getKind() == UriResourceKind.count) { final List<Long> countResult = new ArrayList<>(); countResult.add(executeCountQuery(uriResourceParts, jpaFunction, em, SELECT_COUNT_PATTERN)); return countResult; } if (last.getKind() == UriResourceKind.function) return executeQuery(uriResourceParts, jpaFunction, em, SELECT_BASE_PATTERN); throw new ODataJPAProcessorException(NOT_SUPPORTED_FUNC_WITH_NAVI, HttpStatusCode.NOT_IMPLEMENTED); } @Override public void setCriteriaBuilder(final CriteriaBuilder cb) { this.cb = cb; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAPostgresqlDatabaseProcessor.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAPostgresqlDatabaseProcessor.java
package com.sap.olingo.jpa.processor.core.database; /** * Sample implementation a database processor for PostgreSQL * * @author Oliver Grande * Created: 04.07.2019 * */ public class JPAPostgresqlDatabaseProcessor extends JPAAbstractDatabaseProcessor { // NOSONAR private static final String SELECT_BASE_PATTERN = "SELECT * FROM $FUNCTIONNAME$($PARAMETER$)"; private static final String SELECT_COUNT_PATTERN = "SELECT COUNT(*) FROM $FUNCTIONNAME$($PARAMETER$)"; public JPAPostgresqlDatabaseProcessor() { super(); } @Override protected String functionSelectPattern() { return SELECT_BASE_PATTERN; } @Override protected String functionCountPattern() { return SELECT_COUNT_PATTERN; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAODataDatabaseTableFunction.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAODataDatabaseTableFunction.java
package com.sap.olingo.jpa.processor.core.database; import java.util.Collections; import java.util.List; import jakarta.persistence.EntityManager; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.uri.UriResource; import com.sap.olingo.jpa.metadata.api.JPAHttpHeaderMap; import com.sap.olingo.jpa.metadata.api.JPARequestParameterMap; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPADataBaseFunction; public interface JPAODataDatabaseTableFunction { /** * * @param <T> * @param uriResourceParts * @param jpaFunction * @param em * @return * @throws ODataApplicationException * * @deprecated implement * {@link #executeFunctionQuery(List, JPADataBaseFunction, EntityManager, JPAHttpHeaderMap, JPARequestParameterMap)} * instead */ @Deprecated(since = "2.1.2", forRemoval = true) default <T> List<T> executeFunctionQuery(final List<UriResource> uriResourceParts, final JPADataBaseFunction jpaFunction, final EntityManager em) throws ODataApplicationException { return Collections.emptyList(); } /** * * @param <T> As of now only {@link java.util.List} is supported * @param uriResourceParts * @param jpaFunction * @param em * @param headers * @param parameters * @return A primitive type, a complex type, an entity type or a list of one of those. According to the defined return * type * @throws ODataApplicationException */ default Object executeFunctionQuery(final List<UriResource> uriResourceParts, final JPADataBaseFunction jpaFunction, final EntityManager em, final JPAHttpHeaderMap headers, final JPARequestParameterMap parameters) throws ODataApplicationException { return executeFunctionQuery(uriResourceParts, jpaFunction, em); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAPostgresqlSqlPatternProvider.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAPostgresqlSqlPatternProvider.java
package com.sap.olingo.jpa.processor.core.database; import java.util.Arrays; import com.sap.olingo.jpa.processor.cb.ProcessorSqlFunction; import com.sap.olingo.jpa.processor.cb.ProcessorSqlParameter; import com.sap.olingo.jpa.processor.cb.ProcessorSqlPatternProvider; public class JPAPostgresqlSqlPatternProvider implements ProcessorSqlPatternProvider { @Override public ProcessorSqlFunction getSubStringPattern() { // substring ( string text [ FROM start integer ] [ FOR count integer ] ) return new ProcessorSqlFunction("SUBSTRING", Arrays.asList( new ProcessorSqlParameter(VALUE_PLACEHOLDER, false), new ProcessorSqlParameter(" FROM ", START_PLACEHOLDER, false), new ProcessorSqlParameter(" FOR ", LENGTH_PLACEHOLDER, true))); } @Override public ProcessorSqlFunction getLocatePattern() { // position ( substring text IN string text ) return new ProcessorSqlFunction("POSITION", Arrays.asList( new ProcessorSqlParameter(SEARCH_STRING_PLACEHOLDER, false), new ProcessorSqlParameter(" IN ", VALUE_PLACEHOLDER, false))); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAODataDatabaseSearch.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAODataDatabaseSearch.java
package com.sap.olingo.jpa.processor.core.database; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.From; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.uri.queryoption.SearchOption; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; public interface JPAODataDatabaseSearch { /** * Search implemented differently in various databases, so a database specific implementation needs to be provided. * For details about search at OData see: * <p> * <a href= * "http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html#_Toc372793700"> * OData Version 4.0 Part 1 - 11.2.5.6 System Query Option $search</a> * <p> * <a href= * "http://docs.oasis-open.org/odata/odata/v4.0/os/part2-url-conventions/odata-v4.0-os-part2-url-conventions.html#_Toc372793865"> * OData Version 4.0 Part 2 - 5.1.7 System Query Option $search</a> * @param cb JPA Criteria Builder * @param cq Criteria Query * @param root From clause the search is related to * @param entityType Metadata of the entity type the search belongs to * @param searchOption Parsed search operations * @return * @throws ODataApplicationException */ Expression<Boolean> createSearchWhereClause(final CriteriaBuilder cb, final CriteriaQuery<?> cq, final From<?, ?> root, final JPAEntityType entityType, final SearchOption searchOption) throws ODataApplicationException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPA_HSQLDB_DatabaseProcessor.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPA_HSQLDB_DatabaseProcessor.java
package com.sap.olingo.jpa.processor.core.database; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.From; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.uri.queryoption.SearchOption; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.processor.core.exception.ODataJPADBAdaptorException; public class JPA_HSQLDB_DatabaseProcessor extends JPAAbstractDatabaseProcessor { // NOSONAR private static final String SELECT_BASE_PATTERN = "SELECT * FROM TABLE ($FUNCTIONNAME$($PARAMETER$))"; private static final String SELECT_COUNT_PATTERN = "SELECT COUNT(*) FROM TABLE ($FUNCTIONNAME$($PARAMETER$))"; @Override public Expression<Boolean> createSearchWhereClause(final CriteriaBuilder cb, final CriteriaQuery<?> cq, final From<?, ?> root, final JPAEntityType entityType, final SearchOption searchOption) throws ODataApplicationException { throw new ODataJPADBAdaptorException(ODataJPADBAdaptorException.MessageKeys.NOT_SUPPORTED_SEARCH, HttpStatusCode.NOT_IMPLEMENTED); } @Override protected String functionSelectPattern() { return SELECT_BASE_PATTERN; } @Override protected String functionCountPattern() { return SELECT_COUNT_PATTERN; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAODataDatabaseOperations.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAODataDatabaseOperations.java
package com.sap.olingo.jpa.processor.core.database; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.Expression; import org.apache.olingo.server.api.ODataApplicationException; import com.sap.olingo.jpa.processor.core.filter.JPAAggregationOperation; import com.sap.olingo.jpa.processor.core.filter.JPAArithmeticOperator; import com.sap.olingo.jpa.processor.core.filter.JPABooleanOperator; import com.sap.olingo.jpa.processor.core.filter.JPAComparisonOperator; import com.sap.olingo.jpa.processor.core.filter.JPAMethodCall; import com.sap.olingo.jpa.processor.core.filter.JPAUnaryBooleanOperator; public interface JPAODataDatabaseOperations { public void setCriteriaBuilder(final CriteriaBuilder cb); public <T extends Number> Expression<T> convert(final JPAArithmeticOperator jpaOperator) throws ODataApplicationException; public Expression<Boolean> convert(final JPABooleanOperator jpaOperator) throws ODataApplicationException; public <T extends Comparable<T>> Expression<Boolean> convert(final JPAComparisonOperator<T> jpaOperator) throws ODataApplicationException; public <T> Expression<T> convert(final JPAMethodCall jpaFunction) throws ODataApplicationException; public Expression<Boolean> convert(final JPAUnaryBooleanOperator jpaOperator) throws ODataApplicationException; public Expression<Long> convert(final JPAAggregationOperation jpaOperator) throws ODataApplicationException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPA_POSTSQL_DatabaseProcessor.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPA_POSTSQL_DatabaseProcessor.java
package com.sap.olingo.jpa.processor.core.database; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.From; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.uri.queryoption.SearchOption; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.processor.core.exception.ODataJPADBAdaptorException; /** * Sample implementation a database processor for PostgreSQL * * @author Oliver Grande * Created: 04.07.2019 * * @deprecated Use JPAPostgresqlDatabaseProcessor instead */ @Deprecated(since = "2.2.0", forRemoval = true) public class JPA_POSTSQL_DatabaseProcessor extends JPAAbstractDatabaseProcessor { // NOSONAR private static final String SELECT_BASE_PATTERN = "SELECT * FROM $FUNCTIONNAME$($PARAMETER$)"; private static final String SELECT_COUNT_PATTERN = "SELECT COUNT(*) FROM $FUNCTIONNAME$($PARAMETER$)"; @Override public Expression<Boolean> createSearchWhereClause(final CriteriaBuilder cb, final CriteriaQuery<?> cq, final From<?, ?> root, final JPAEntityType entityType, final SearchOption searchOption) throws ODataApplicationException { /* * Even so PostgesSQL has text search, as of know no generic implementation made for search */ throw new ODataJPADBAdaptorException(ODataJPADBAdaptorException.MessageKeys.NOT_SUPPORTED_SEARCH, HttpStatusCode.NOT_IMPLEMENTED); } @Override protected String functionSelectPattern() { return SELECT_BASE_PATTERN; } @Override protected String functionCountPattern() { return SELECT_COUNT_PATTERN; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPA_DERBY_DatabaseProcessor.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPA_DERBY_DatabaseProcessor.java
package com.sap.olingo.jpa.processor.core.database; public class JPA_DERBY_DatabaseProcessor extends JPAAbstractDatabaseProcessor { // NOSONAR /** * See: <a href="https://db.apache.org/derby/docs/10.15/ref/rrefsqljtfinvoke.html">Derby: Function Invocation</a> */ private static final String SELECT_BASE_PATTERN = "SELECT * FROM TABLE ($FUNCTIONNAME$($PARAMETER$))"; private static final String SELECT_COUNT_PATTERN = "SELECT COUNT(*) FROM TABLE ($FUNCTIONNAME$($PARAMETER$))"; public JPA_DERBY_DatabaseProcessor() { super(); } @Override protected String functionSelectPattern() { return SELECT_BASE_PATTERN; } @Override protected String functionCountPattern() { return SELECT_COUNT_PATTERN; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAODataDatabaseProcessorFactory.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAODataDatabaseProcessorFactory.java
package com.sap.olingo.jpa.processor.core.database; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.SQLException; import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.sap.olingo.jpa.processor.core.api.JPAODataDatabaseProcessor; public class JPAODataDatabaseProcessorFactory { private static final Log LOGGER = LogFactory.getLog(JPAODataDatabaseProcessorFactory.class); private static final String PRODUCT_NAME_H2 = "H2"; private static final String PRODUCT_NAME_HSQLDB = "HSQL Database Engine"; private static final String PRODUCT_NAME_POSTGRESQL = "PostgreSQL"; public JPAODataDatabaseProcessor create(final DataSource dataSource) throws SQLException { if (dataSource != null) { try (Connection connection = dataSource.getConnection()) { final DatabaseMetaData dbMetadata = connection.getMetaData(); if (dbMetadata.getDatabaseProductName().equals(PRODUCT_NAME_POSTGRESQL)) { LOGGER.trace("Create database-processor for PostgreSQL"); return new JPAPostgresqlDatabaseProcessor(); } else if (dbMetadata.getDatabaseProductName().equals(PRODUCT_NAME_HSQLDB)) { LOGGER.trace("Create database-processor for HSQLDB"); return new JPA_HSQLDB_DatabaseProcessor(); } else if (dbMetadata.getDatabaseProductName().equals(PRODUCT_NAME_H2)) { LOGGER.trace("Create database-processor for H2"); return new JPA_HSQLDB_DatabaseProcessor(); } else { LOGGER.trace("Create default database-processor"); return new JPADefaultDatabaseProcessor(); } } } else { LOGGER.trace("Create default database-processor"); return new JPADefaultDatabaseProcessor(); } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAHanaDatabaseProcessor.java
jpa/odata-jpa-processor/src/main/java/com/sap/olingo/jpa/processor/core/database/JPAHanaDatabaseProcessor.java
package com.sap.olingo.jpa.processor.core.database; import static com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException.MessageKeys.NOT_SUPPORTED_FUNC_WITH_NAVI; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import jakarta.persistence.EntityManager; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourceKind; import com.sap.olingo.jpa.metadata.api.JPAHttpHeaderMap; import com.sap.olingo.jpa.metadata.api.JPARequestParameterMap; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPADataBaseFunction; import com.sap.olingo.jpa.processor.cb.ProcessorSqlFunction; import com.sap.olingo.jpa.processor.cb.ProcessorSqlParameter; import com.sap.olingo.jpa.processor.cb.ProcessorSqlPatternProvider; import com.sap.olingo.jpa.processor.core.exception.ODataJPAProcessorException; /** * Sample implementation a database processor for SAP HANA * * @author Oliver Grande * Created: 04.07.2024 * @since */ public class JPAHanaDatabaseProcessor extends JPAAbstractDatabaseProcessor implements ProcessorSqlPatternProvider { // NOSONAR private static final String SELECT_BASE_PATTERN = "SELECT * FROM $FUNCTIONNAME$($PARAMETER$)"; private static final String SELECT_COUNT_PATTERN = "SELECT COUNT(*) FROM $FUNCTIONNAME$($PARAMETER$)"; public JPAHanaDatabaseProcessor() { super(); } @Override public Object executeFunctionQuery(final List<UriResource> uriResourceParts, final JPADataBaseFunction jpaFunction, final EntityManager em, final JPAHttpHeaderMap headers, final JPARequestParameterMap parameters) throws ODataApplicationException { final UriResource last = uriResourceParts.get(uriResourceParts.size() - 1); if (last.getKind() == UriResourceKind.count) { final List<Long> countResult = new ArrayList<>(); countResult.add(executeCountQuery(uriResourceParts, jpaFunction, em, SELECT_COUNT_PATTERN)); return countResult; } if (last.getKind() == UriResourceKind.function) return executeQuery(uriResourceParts, jpaFunction, em, SELECT_BASE_PATTERN); throw new ODataJPAProcessorException(NOT_SUPPORTED_FUNC_WITH_NAVI, HttpStatusCode.NOT_IMPLEMENTED); } @Override public ProcessorSqlFunction getLocatePattern() { // INSTR: Returns the position of the first occurrence of the second string within the first string (>= 1) or 0, if // the second string is not contained in the first. return new ProcessorSqlFunction("INSTR", Arrays.asList( new ProcessorSqlParameter(VALUE_PLACEHOLDER, false), new ProcessorSqlParameter(COMMA_SEPARATOR, SEARCH_STRING_PLACEHOLDER, false))); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataVocabularyReadExceptionTest.java
jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataVocabularyReadExceptionTest.java
/** * */ package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.net.URI; import java.net.URISyntaxException; import org.junit.jupiter.api.Test; /** * @author Oliver Grande * @since 1.1.1 * 15.02.2023 */ class ODataVocabularyReadExceptionTest { @Test void checkCreatesWithItemAndPath() { final Exception e = new NullPointerException(); final ODataVocabularyReadException cut = new ODataVocabularyReadException("Test", "Dummy", e); assertTrue(cut.getMessage().contains("Test")); assertTrue(cut.getMessage().contains("Dummy")); assertEquals(e, cut.getCause()); } @Test void checkCreatesWithPath() throws URISyntaxException { final URI uri = new URI("http://example.org:8080"); final Exception e = new NullPointerException(); final ODataVocabularyReadException cut = new ODataVocabularyReadException(uri, "Test", e); assertTrue(cut.getMessage().contains("Test")); assertTrue(cut.getMessage().contains(uri.toString())); assertEquals(e, cut.getCause()); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataPathNotFoundExceptionTest.java
jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataPathNotFoundExceptionTest.java
/** * */ package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; /** * @author Oliver Grande * @since 1.1.1 * 15.02.2023 */ class ODataPathNotFoundExceptionTest { @Test void checkCreatesWithItemAndPath() { final ODataPathNotFoundException cut = new ODataPathNotFoundException("Test", "Dummy"); assertTrue(cut.getMessage().contains("Test")); assertTrue(cut.getMessage().contains("Dummy")); } @Test void checkCreatesWithPath() { final Exception e = new NullPointerException(); final ODataPathNotFoundException cut = new ODataPathNotFoundException("Test", e); assertTrue(cut.getMessage().contains("Test")); assertEquals(e, cut.getCause()); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/ODataJPAVocabulariesExceptionTest.java
jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/ODataJPAVocabulariesExceptionTest.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; import com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies.ODataJPAVocabulariesException.MessageKeys; class ODataJPAVocabulariesExceptionTest { private ODataJPAVocabulariesException cut; @Test void checkReturnsStandardMessageWithoutKey() { cut = new ODataJPAVocabulariesException(null, "Test"); assertNotNull(cut.getMessage()); } @Test void checkReturnsStandardMessageWithCauseWithoutKey() { final Exception e = new NullPointerException("Null"); cut = new ODataJPAVocabulariesException(null, e, "Test"); assertNotNull(cut.getMessage()); } @Test void checkReturnsMessageWithKey() { cut = new ODataJPAVocabulariesException(MessageKeys.FILE_NOT_FOUND, "Test"); assertNotNull(cut.getMessage()); assertTrue(cut.getMessage().contains("Test")); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/ApplicabilityTest.java
jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/ApplicabilityTest.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.DynamicTest.dynamicTest; import java.util.stream.Stream; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.Applicability; class ApplicabilityTest { @TestFactory Stream<DynamicTest> checkEnumHasValue() { return Stream.of(Applicability.values()) .map(a -> dynamicTest(a.name(), () -> { assertNotNull(a.value()); assertFalse(a.value().isEmpty()); })); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/TestAnnotationPOJO.java
jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/TestAnnotationPOJO.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; import java.util.List; import org.junit.jupiter.api.Test; import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; import com.fasterxml.jackson.dataformat.xml.XmlMapper; class TestAnnotationPOJO { private final String terms = """ <edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">\ <edmx:Reference Uri="http://docs.oasis-open.org/odata/odata/v4.0/os/vocabularies/Org.OData.Core.V1.xml">\ <edmx:Include Alias="Core" Namespace="Org.OData.Core.V1" />\ </edmx:Reference>\ <edmx:DataServices>\ <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Org.OData.Measures.V1" Alias="Measures"> \ <Annotation Term="Core.Description"> \ <String>Terms describing monetary amounts and measured quantities</String> \ </Annotation> \ <Term Name="ISOCurrency" Type="Edm.String" AppliesTo="Property"> \ <Annotation Term="Core.Description" String="The currency for this monetary amount as an ISO 4217 currency code" /> \ </Term> \ <Term Name="Scale" Type="Edm.Byte" AppliesTo="Property"> \ <Annotation Term="Core.Description" \ String="The number of significant decimal places in the scale part (less than or equal to the number declared in the Scale facet)" /> \ <Annotation Term="Core.RequiresType" String="Edm.Decimal" /> \ </Term> \ <Term Name="Unit" Type="Edm.String" AppliesTo="Property"> \ <Annotation Term="Core.Description" String="The unit of measure for this measured quantity, e.g. cm for centimeters or % for percentages" /> \ </Term> \ </Schema> \ </edmx:DataServices>\ </edmx:Edmx>"""; @Test void TestSimpleXMLConverted() throws IOException { final JacksonXmlModule module = new JacksonXmlModule(); module.setDefaultUseWrapper(false); final XmlMapper xmlMapper = new XmlMapper(module); final CsdlDocument act = xmlMapper.readValue(terms, CsdlDocument.class); assertNotNull(act.getDataService()); final List<Schema> actSchemas = act.getDataService().getSchemas(); assertEquals(1, actSchemas.size()); final List<Term> actTerms = actSchemas.get(0).getTerms(); assertEquals(3, actTerms.size()); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/TestAnnotationSchema.java
jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/TestAnnotationSchema.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.nio.charset.Charset; import java.util.List; import java.util.Map; import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.api.edm.provider.CsdlAction; import org.apache.olingo.commons.api.edm.provider.CsdlComplexType; import org.apache.olingo.commons.api.edm.provider.CsdlEnumMember; import org.apache.olingo.commons.api.edm.provider.CsdlEnumType; import org.apache.olingo.commons.api.edm.provider.CsdlFunction; import org.apache.olingo.commons.api.edm.provider.CsdlParameter; import org.apache.olingo.commons.api.edm.provider.CsdlProperty; import org.apache.olingo.commons.api.edm.provider.CsdlReturnType; import org.apache.olingo.commons.api.edm.provider.CsdlSchema; import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class TestAnnotationSchema { private static final String AGGREGATION_ANNOTATIONS = "annotations/Org.OData.Aggregation.V1.xml"; private static final String CAPABILITIES_ANNOTATIONS = "annotations/Org.OData.Capabilities.V1.xml"; private static final String TEST_ANNOTATIONS = "annotations/Org.Olingo.Test.V1.xml"; private static final String CORE_ANNOTATIONS = "annotations/Org.OData.Core.V1.xml"; private CsdlDocument cutCore; private CsdlDocument cutTest; private CsdlDocument cutCapabilities; private CsdlDocument cutAggregation; private Charset charset; @BeforeEach void setup() throws ODataJPAVocabulariesException, IOException { final CsdlDocumentReader reader = new CsdlDocumentReader(); charset = Charset.defaultCharset(); cutCore = reader.readFromResource(CORE_ANNOTATIONS, charset); cutTest = reader.readFromResource(TEST_ANNOTATIONS, charset); cutCapabilities = reader.readFromResource(CAPABILITIES_ANNOTATIONS, charset); cutAggregation = reader.readFromResource(AGGREGATION_ANNOTATIONS, charset); } @Test void testGetAliasFromPath() { final Map<String, ? extends CsdlSchema> act = cutCore.getSchemas(); assertNotNull(act.get("Org.OData.Core.V1")); final CsdlSchema schema = act.get("Org.OData.Core.V1"); assertEquals("Core", schema.getAlias()); } @Test void testGetTermsFromPath() { final Map<String, ? extends CsdlSchema> act = cutCore.getSchemas(); assertNotNull(act.get("Org.OData.Core.V1")); final CsdlSchema schema = act.get("Org.OData.Core.V1"); assertEquals(40, schema.getTerms().size()); } @Test void testGetTypeDefinitionFromPath() { final Map<String, ? extends CsdlSchema> act = cutCore.getSchemas(); assertNotNull(act.get("Org.OData.Core.V1")); final CsdlSchema schema = act.get("Org.OData.Core.V1"); assertEquals(7, schema.getTypeDefinitions().size()); assertNotNull(schema.getTypeDefinition("Tag")); assertEquals("Edm.Boolean", schema.getTypeDefinition("Tag").getUnderlyingType()); } @Test void testGetTypeDefinitions() { final CsdlSchema act = cutTest.getSchemas().get("Org.OData.Capabilities.V1"); assertEquals(3, act.getTypeDefinitions().size()); assertNotNull(act.getTypeDefinition("TestTypeDecimal")); CsdlTypeDefinition actType = act.getTypeDefinition("TestTypeDecimal"); assertEquals(10, actType.getPrecision()); assertEquals(5, actType.getScale()); assertNull(actType.getSrid()); assertNull(actType.getMaxLength()); actType = act.getTypeDefinition("TestTypeGeo"); assertNull(actType.getPrecision()); assertNull(actType.getScale()); assertEquals(SRID.valueOf("variable"), actType.getSrid()); assertNull(actType.getMaxLength()); assertTrue(actType.isUnicode()); actType = act.getTypeDefinition("TestTypeString"); assertNull(actType.getPrecision()); assertNull(actType.getScale()); assertNull(actType.getSrid()); assertEquals(256, actType.getMaxLength()); assertFalse(actType.isUnicode()); } @Test void testGetEnumSchemaFromPath() { final Map<String, ? extends CsdlSchema> act = cutCore.getSchemas(); assertNotNull(act.get("Org.OData.Core.V1")); final CsdlSchema schema = act.get("Org.OData.Core.V1"); assertEquals(3, schema.getEnumTypes().size()); assertNotNull(schema.getEnumType("Permission")); assertEquals(5, schema.getEnumType("Permission").getMembers().size()); assertEquals("3", schema.getEnumType("Permission").getMember("ReadWrite").getValue()); } @Test void testGetSimpleComplexTypes() { final Map<String, ? extends CsdlSchema> act = cutTest.getSchemas(); assertEquals(2, act.size()); assertTrue(act.containsKey("Org.OData.Capabilities.V1")); final CsdlSchema actSchema = act.get("Org.OData.Capabilities.V1"); final CsdlComplexType actCt = actSchema.getComplexType("UpdateRestrictionsType"); assertNotNull(actCt); assertNull(actCt.getBaseType()); assertNull(actCt.getBaseTypeFQN()); assertFalse(actCt.isAbstract()); assertFalse(actCt.isOpenType()); assertEquals("UpdateRestrictionsType", actCt.getName()); assertEquals(2, actCt.getProperties().size()); assertEquals(0, actCt.getNavigationProperties().size()); assertEquals(0, actCt.getAnnotations().size()); } @Test void testGetDeepComplexTypes() { final CsdlComplexType actCt = cutTest.getSchemas() .get("Org.OData.Capabilities.V1").getComplexType("TestType"); assertNotNull(actCt); assertEquals(5, actCt.getProperties().size()); assertTrue(actCt.isAbstract()); assertTrue(actCt.isOpenType()); assertNotNull(actCt.getBaseType()); assertEquals("Core.Unknown", actCt.getBaseType()); assertEquals("Core.Unknown", actCt.getBaseTypeFQN().getFullQualifiedNameAsString()); assertEquals(0, actCt.getAnnotations().size()); // Annotations are ignored } @Test void testGetSimpleProperty() { final CsdlComplexType actCt = cutTest.getSchemas() .get("Org.OData.Capabilities.V1").getComplexType("TestType"); final CsdlProperty actProperty = actCt.getProperty("Deletable"); assertNotNull(actProperty); assertEquals("Deletable", actProperty.getName()); assertEquals("Edm.Boolean", actProperty.getType()); assertEquals("true", actProperty.getDefaultValue()); assertNull(actProperty.getMaxLength()); assertNull(actProperty.getScale()); assertNull(actProperty.getSrid()); assertNull(actProperty.getPrecision()); assertTrue(actProperty.isUnicode()); } @Test void testGetDecimalProperty() { final CsdlComplexType actCt = cutTest.getSchemas() .get("Org.OData.Capabilities.V1").getComplexType("TestType"); final CsdlProperty actProperty = actCt.getProperty("TestDecimals"); assertNotNull(actProperty); assertEquals("TestDecimals", actProperty.getName()); assertEquals("Edm.Decimal", actProperty.getType()); assertNull(actProperty.getDefaultValue()); assertNull(actProperty.getMaxLength()); assertEquals(5, actProperty.getScale()); assertNull(actProperty.getSrid()); assertEquals(10, actProperty.getPrecision()); assertTrue(actProperty.isUnicode()); } @Test void testGetStringProperty() { final CsdlComplexType actCt = cutTest.getSchemas() .get("Org.OData.Capabilities.V1").getComplexType("TestType"); final CsdlProperty actProperty = actCt.getProperty("TestString"); assertNotNull(actProperty); assertEquals("TestString", actProperty.getName()); assertEquals("Edm.String", actProperty.getType()); assertNull(actProperty.getDefaultValue()); assertEquals(256, actProperty.getMaxLength()); assertNull(actProperty.getScale()); assertNull(actProperty.getSrid()); assertNull(actProperty.getPrecision()); assertFalse(actProperty.isUnicode()); } @Test void testGetGeoProperty() { final CsdlComplexType actCt = cutTest.getSchemas() .get("Org.OData.Capabilities.V1").getComplexType("TestType"); final CsdlProperty actProperty = actCt.getProperty("TestGeo"); assertNotNull(actProperty); assertEquals("TestGeo", actProperty.getName()); assertEquals("Edm.GeometryPoint", actProperty.getType()); assertNull(actProperty.getDefaultValue()); assertNull(actProperty.getMaxLength()); assertNull(actProperty.getScale()); assertEquals(SRID.valueOf("3857"), actProperty.getSrid()); assertNull(actProperty.getPrecision()); assertTrue(actProperty.isUnicode()); assertFalse(actProperty.isCollection()); } @Test void testGetCollectionProperty() { final CsdlComplexType actCt = cutTest.getSchemas() .get("Org.OData.Capabilities.V1").getComplexType("TestType"); final CsdlProperty actProperty = actCt.getProperty("NonDeletableNavigationProperties"); assertNotNull(actProperty); assertEquals("NonDeletableNavigationProperties", actProperty.getName()); assertEquals("Edm.NavigationPropertyPath", actProperty.getType()); assertTrue(actProperty.isCollection()); } @Test void testGetEnum() { final CsdlSchema act = cutCapabilities.getSchemas() .get("Org.OData.Capabilities.V1"); assertEquals(5, act.getEnumTypes().size()); } @Test void testGetEnumNotAsFlags() { final CsdlEnumType actEnum = cutAggregation.getSchemas() .get("Org.OData.Aggregation.V1").getEnumType("RollupType"); assertNotNull(actEnum); assertEquals(3, actEnum.getMembers().size()); assertNotNull(actEnum.getMember("MultipleHierarchies")); assertNull(actEnum.getUnderlyingType()); assertFalse(actEnum.isFlags()); } @Test void testGetEnumAsFlags() { final CsdlEnumType actEnum = cutCapabilities.getSchemas() .get("Org.OData.Capabilities.V1").getEnumType("IsolationLevel"); assertNotNull(actEnum); assertEquals(1, actEnum.getMembers().size()); assertNotNull(actEnum.getMember(1)); assertNull(actEnum.getUnderlyingType()); assertTrue(actEnum.isFlags()); final CsdlEnumMember actMember = actEnum.getMember(1); assertEquals("Snapshot", actMember.getName()); assertEquals("1", actMember.getValue()); } @Test void testGetFunctions() { final CsdlSchema act = cutAggregation.getSchemas() .get("Org.OData.Aggregation.V1"); assertEquals(5, act.getFunctions().size()); } @Test void testGetFunctionAttributes() { final List<CsdlFunction> act = cutAggregation.getSchemas() .get("Org.OData.Aggregation.V1").getFunctions("isleaf"); assertEquals(1, act.size()); final CsdlFunction actFunc = act.get(0); assertEquals("isleaf", actFunc.getName()); assertEquals(2, actFunc.getParameters().size()); assertTrue(actFunc.isBound()); assertFalse(actFunc.isComposable()); assertNotNull(actFunc.getReturnType()); } @Test void testGetFunctionParameter() { final List<CsdlFunction> act = cutAggregation.getSchemas() .get("Org.OData.Aggregation.V1").getFunctions("isancestor"); final CsdlFunction actFunc = act.get(0); assertEquals(4, actFunc.getParameters().size()); final CsdlParameter actMandatory = actFunc.getParameter("Entity"); assertNotNull(actMandatory); assertEquals("Entity", actMandatory.getName()); assertEquals("Edm.EntityType", actMandatory.getType()); assertFalse(actMandatory.isNullable()); final CsdlParameter actNullable = actFunc.getParameter("MaxDistance"); assertTrue(actNullable.isNullable()); } @Test void testGetFunctionParameterFacet() { final List<CsdlFunction> act = cutTest.getSchemas() .get("Org.OData.Capabilities.V1").getFunctions("TestTheRest1"); final CsdlFunction actFunc = act.get(0); final CsdlParameter actDecimal = actFunc.getParameter("Dec"); assertEquals("Edm.Decimal", actDecimal.getTypeFQN().getFullQualifiedNameAsString()); assertEquals(10, actDecimal.getPrecision()); assertEquals(5, actDecimal.getScale()); assertTrue(actDecimal.isNullable()); final CsdlParameter actGeo = actFunc.getParameter("Geo"); assertEquals(SRID.valueOf("3857"), actGeo.getSrid()); assertTrue(actGeo.isNullable()); assertFalse(actGeo.isCollection()); final CsdlParameter actString = actFunc.getParameter("Text"); assertEquals("Edm.String", actString.getType()); assertTrue(actString.isCollection()); assertEquals(512, actString.getMaxLength()); } @Test void testGetFunctionReturnType() { final List<CsdlFunction> act = cutAggregation.getSchemas() .get("Org.OData.Aggregation.V1").getFunctions("isancestor"); final CsdlFunction actFunc = act.get(0); final CsdlReturnType actReturn = actFunc.getReturnType(); assertNotNull(actReturn); assertEquals("Edm.Boolean", actReturn.getType()); assertFalse(actReturn.isNullable()); assertNull(actReturn.getMaxLength()); assertNull(actReturn.getScale()); assertNull(actReturn.getSrid()); assertNull(actReturn.getPrecision()); assertFalse(actReturn.isCollection()); } @Test void testGetFunctionReturnTypeFacet() { final List<CsdlFunction> act = cutTest.getSchemas() .get("Org.OData.Capabilities.V1").getFunctions("TestTheRest1"); final CsdlFunction actFunc = act.get(0); assertEquals("timeslices", actFunc.getEntitySetPath()); final CsdlReturnType actReturn = actFunc.getReturnType(); assertNotNull(actReturn); assertEquals("Edm.Decimal", actReturn.getTypeFQN().getFullQualifiedNameAsString()); assertEquals(10, actReturn.getPrecision()); assertEquals(5, actReturn.getScale()); assertTrue(actReturn.isNullable()); assertTrue(actReturn.isCollection()); assertEquals(20, actReturn.getMaxLength()); assertEquals(SRID.valueOf("3857"), actReturn.getSrid()); } @Test void testGetActions() { final List<CsdlAction> act = cutTest.getSchemas() .get("Org.OData.Capabilities.V1").getActions(); assertEquals(2, act.size()); } @Test void testGetActionParameter() { final List<CsdlAction> act = cutTest.getSchemas() .get("Org.OData.Capabilities.V1").getActions("UpsertTimeExample"); final CsdlAction actAction = act.get(0); assertEquals(3, actAction.getParameters().size()); assertTrue(actAction.isBound()); assertEquals("UpsertTimeExample", actAction.getName()); assertEquals("timeslices", actAction.getEntitySetPath()); final CsdlParameter actParam = actAction.getParameter("timeslices"); assertEquals("Edm.EntityType", actParam.getTypeFQN().getFullQualifiedNameAsString()); assertTrue(actParam.isCollection()); assertFalse(actParam.isNullable()); } @Test void testGetActionReturnType() { final List<CsdlAction> act = cutTest.getSchemas() .get("Org.OData.Capabilities.V1").getActions("UpsertTimeExample"); final CsdlAction actAction = act.get(0); assertNotNull(actAction.getReturnType()); final CsdlReturnType actReturn = actAction.getReturnType(); assertFalse(actReturn.isNullable()); assertTrue(actReturn.isCollection()); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/TermTest.java
jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/TermTest.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.nio.charset.Charset; import java.util.Map; import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.api.edm.provider.CsdlTerm; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class TermTest { private static final String TEST_ANNOTATIONS = "annotations/Org.Olingo.Test.V1.xml"; private static final String CORE_ANNOTATIONS = "annotations/Org.OData.Core.V1.xml"; private CsdlDocument cutCore; private CsdlDocument cutTest; private Charset charset; @BeforeEach void setup() throws ODataJPAVocabulariesException, IOException { final CsdlDocumentReader reader = new CsdlDocumentReader(); charset = Charset.defaultCharset(); cutCore = reader.readFromResource(CORE_ANNOTATIONS, charset); cutTest = reader.readFromResource(TEST_ANNOTATIONS, charset); } @Test void testGetTermsOneSchemaFromPath() { final Map<String, Map<String, CsdlTerm>> act = cutCore.getTerms(); assertNotNull(act.get("Org.OData.Core.V1")); final Map<String, CsdlTerm> terms = act.get("Org.OData.Core.V1"); assertEquals(40, terms.size()); } @Test void testGetAppliesTo() { final Map<String, Map<String, CsdlTerm>> act = cutCore.getTerms(); assertNotNull(act.get("Org.OData.Core.V1")); final Map<String, CsdlTerm> terms = act.get("Org.OData.Core.V1"); final CsdlTerm term = terms.get("IsLanguageDependent"); assertEquals(2, term.getAppliesTo().size()); assertTrue("Term".equals(term.getAppliesTo().get(0)) || "Term".equals(term.getAppliesTo().get(1))); assertTrue("Property".equals(term.getAppliesTo().get(0)) || "Property".equals(term.getAppliesTo().get(1))); assertEquals("true", term.getDefaultValue()); } @Test void testGetTermsTwoSchemaFromPath() { final Map<String, Map<String, CsdlTerm>> act = cutTest.getTerms(); assertNotNull(act.get("Org.OData.Measures.V1")); assertNotNull(act.get("Org.OData.Capabilities.V1")); } @Test void testGetTermWithScalePrecision() { final Map<String, Map<String, CsdlTerm>> act = cutTest.getTerms(); final Map<String, CsdlTerm> terms = act.get("Org.OData.Measures.V1"); final CsdlTerm term = terms.get("MultipleOf"); assertNotNull(term); assertEquals(10, term.getScale()); assertEquals(5, term.getPrecision()); } @Test void testGetTermWithBaseTypeMaxLength() { final Map<String, Map<String, CsdlTerm>> act = cutTest.getTerms(); final Map<String, CsdlTerm> terms = act.get("Org.OData.Measures.V1"); final CsdlTerm term = terms.get("Unit2"); assertNotNull(term); assertEquals("Unit", term.getBaseTerm()); assertEquals(2, term.getMaxLength()); } @Test void testGetTermWithSrid() { final Map<String, Map<String, CsdlTerm>> act = cutTest.getTerms(); final Map<String, CsdlTerm> terms = act.get("Org.OData.Measures.V1"); final CsdlTerm term = terms.get("Geo"); assertNotNull(term); assertEquals(SRID.valueOf("1234"), term.getSrid()); } @Test void testGetTermWithSridVariableNotSupported() { final Term cut = new Term(); cut.setSrid("variable"); assertTrue(cut.getSrid().toString().contains("variable")); } @Test void testGetTermWithScaleVariableNotSupported() { final Term cut = new Term(); assertThrows(ODataJPAVocabulariesException.class, () -> cut.setScale("variable")); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/TestCsdlDocumentReader.java
jpa/odata-jpa-vocabularies/src/test/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/TestCsdlDocumentReader.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Charset; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; class TestCsdlDocumentReader { private static final String CORE_ANNOTATIONS = "annotations/Org.OData.Core.V1.xml"; private CsdlDocumentReader cut; private Charset charset; @BeforeEach void setup() { cut = new CsdlDocumentReader(); charset = Charset.defaultCharset(); } @Test void testReadFromURIThrowsNullPointerOnNull() throws ODataJPAVocabulariesException, IOException { assertThrows(NullPointerException.class, () -> cut.readFromURI(null)); } @Test void testReadFromResourceThrowsNullPointerOnNull() throws ODataJPAVocabulariesException, IOException { assertThrows(NullPointerException.class, () -> cut.readFromResource(null, charset)); assertThrows(NullPointerException.class, () -> cut.readFromResource(CORE_ANNOTATIONS, null)); } @Test void testReadFromResourceReturnsNullOnEmptyPath() throws ODataJPAVocabulariesException, IOException { assertNull(cut.readFromResource("", charset)); } @Test void testReadFromResourceReturnsVocabulary() throws IOException, ODataJPAVocabulariesException { final CsdlDocument act = cut.readFromResource(CORE_ANNOTATIONS, charset); assertNotNull(act); assertFalse(act.getSchemas().isEmpty()); assertNotNull(act.getSchemas().get("Org.OData.Core.V1")); } @Test void testReadFromResourceThrowsExceptionOnUnknownPath() throws IOException { assertThrows(ODataJPAVocabulariesException.class, () -> { cut.readFromResource("annotations/Org.OData.Core.V2.xml", charset); }); } @Test void testReadFromResourceThrowsExceptionOnEmptyXML() throws IOException, ODataJPAVocabulariesException { assertThrows(IOException.class, () -> { cut.readFromResource("annotations/empty.xml", charset); }); } @Test void testReadDocumentContainsReferences() throws IOException, ODataJPAVocabulariesException { // <edmx:Reference Uri="http://docs.oasis-open.org/odata/odata-vocabularies/v4.0/vocabularies/Org.OData.Validation.V1.xml"> // <edmx:Include Alias="Validation" Namespace="Org.OData.Validation.V1" /> // </edmx:Reference> final CsdlDocument act = cut.readFromResource(CORE_ANNOTATIONS, charset); assertNotNull(act.getReference()); assertEquals(1, act.getReference().size()); final EdmxReference ref = act.getReference().get(0); assertNotNull(ref.getIncludes()); assertEquals(1, ref.getIncludes().size()); final EdmxReferenceInclude include = ref.getIncludes().get(0); assertEquals("Validation", include.getAlias()); assertEquals("Org.OData.Validation.V1", include.getNamespace()); } @Disabled("This test may not run because of proxy setting problems!! -> find alternative for Integration tests") @Test void testReadFromURI() throws URISyntaxException, JsonParseException, JsonMappingException, MalformedURLException, IOException { final URI uri = new URI("http://docs.oasis-open.org/odata/odata/v4.0/os/vocabularies/Org.OData.Core.V1.xml"); final CsdlDocument actVocabulary = cut.readFromURI(uri); assertNotNull(actVocabulary); assertNotNull(actVocabulary.getDataService()); final List<Schema> actSchemas = actVocabulary.getDataService().getSchemas(); assertEquals(1, actSchemas.size()); assertEquals("Org.OData.Core.V1", actSchemas.get(0).getNamespace()); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataPropertyPath.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataPropertyPath.java
/** * */ package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; /** * @author Oliver Grande * @since 1.1.1 * 13.02.2023 */ public interface ODataPropertyPath { /** * @return */ String getPathAsString(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataNavigationPath.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataNavigationPath.java
/** * */ package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; /** * @author Oliver Grande * @since 1.1.1 * 13.02.2023 */ public interface ODataNavigationPath { /** * @return */ String getPathAsString(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/AnnotationProvider.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/AnnotationProvider.java
package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; import java.util.Collection; import javax.annotation.Nonnull; import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation; public interface AnnotationProvider { Collection<CsdlAnnotation> getAnnotations(@Nonnull final Applicability appliesTo, @Nonnull ODataAnnotatable annotatable, @Nonnull JPAReferences references); void addReferences(@Nonnull ReferenceList references) throws ODataVocabularyReadException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataPathNotFoundException.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataPathNotFoundException.java
/** * */ package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; import org.apache.olingo.commons.api.ex.ODataException; /** * @author Oliver Grande * @since 1.1.1 * 13.02.2023 */ public class ODataPathNotFoundException extends ODataException { /** * */ private static final long serialVersionUID = 5003835145918311048L; private static final String MESSAGE = "Path ''0'' could not completly converted. Unknown part: ''1''."; private static final String EXCEPTION = "An exception occured during converation of path ''0''."; /** * @param pathElementNotFound * @param pathItem * @param internalPath */ public ODataPathNotFoundException(final String pathItem, final String path) { super(MESSAGE.replaceFirst("'0'", path).replaceFirst("'1'", pathItem)); } /** * @param internalPath * @param e */ public ODataPathNotFoundException(final String path, final Exception e) { super(EXCEPTION.replaceFirst("'0'", path), e); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/PropertyAccess.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/PropertyAccess.java
package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; public interface PropertyAccess { String property(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/TermAccess.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/TermAccess.java
package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; public interface TermAccess { String term(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/JPAReferences.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/JPAReferences.java
package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; import java.util.List; import java.util.Optional; import javax.annotation.Nonnull; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.provider.CsdlNamed; import org.apache.olingo.commons.api.edm.provider.CsdlTerm; public interface JPAReferences { public String convertAlias(@Nonnull final String alias); public Optional<CsdlTerm> getTerm(@Nonnull final FullQualifiedName termName); public <T extends CsdlNamed> Optional<T> getType(@Nonnull final FullQualifiedName fqn); public List<CsdlTerm> getTerms(@Nonnull String schemaAlias, @Nonnull Applicability appliesTo); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataVocabularyReadException.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataVocabularyReadException.java
/** * */ package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; import java.net.URI; import org.apache.olingo.commons.api.ex.ODataException; /** * @author Oliver Grande * @since 1.1.1 * 15.02.2023 */ public class ODataVocabularyReadException extends ODataException { /** * */ private static final long serialVersionUID = 7101416958465873109L; private static final String EXCEPTION = "Could not import vocabulary ''0'' from ''1''."; /** * @param uri * @param e */ public ODataVocabularyReadException(final URI uri, final String path, final Exception e) { super(EXCEPTION.replaceFirst("'0'", uri.toString()).replaceFirst("'1'", path), e); } /** * @param capabilitiesAlias * @param capabilitiesPath * @param e */ public ODataVocabularyReadException(final String alias, final String path, final Exception e) { super(EXCEPTION.replaceFirst("'0'", alias).replaceFirst("'1'", path), e); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ReferenceList.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ReferenceList.java
/** * */ package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; import java.net.URI; import javax.annotation.Nonnull; /** * @author Oliver Grande * @since 1.1.1 * 13.02.2023 */ public interface ReferenceList { /** * @param uri URI of the vocabulary e.g. * "http://docs.oasisopen.org/odata/odata/v4.0/os/vocabularies/Org.OData.Capabilities.V1.xml" * @param sub-path the vocabulary is stored within a resource folder * @return */ ReferenceAccess addReference(@Nonnull final URI uri, @Nonnull final String path) throws ODataVocabularyReadException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataAnnotatable.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ODataAnnotatable.java
package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; import java.lang.annotation.Annotation; import java.util.Map; import javax.annotation.CheckForNull; public interface ODataAnnotatable { /** * Converts a path given as a string of internal (Java) attribute names into a JPAPath. * @param internalPath * @return * @throws ODataJPAModelException */ default ODataPropertyPath convertStringToPath(final String internalPath) throws ODataPathNotFoundException { return null; } /** * * @param internalPath * @return * @throws ODataJPAModelException */ default ODataNavigationPath convertStringToNavigationPath(final String internalPath) throws ODataPathNotFoundException { return null; } /** * Searches for a java annotation at an OData annotatable element. In case no annotation is found, Null is returned; * @param name of the annotation, as it would be returned by {@link Class#getName()} * @deprecated Make use of {@link #javaAnnotations(String)} instead * @return */ @Deprecated(forRemoval = true, since = "2.1.0") @CheckForNull default Annotation javaAnnotation(final String name) { return null; } /** * Provide all java annotation at the annotatable that come from the given package. * @param packageName * @return A map with <i>key</i> simple name {@link Class#getSimpleName()}) of the annotation and <i>value</i> the * annotation * instance */ Map<String, Annotation> javaAnnotations(String packageName); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ReferenceAccess.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/ReferenceAccess.java
/** * */ package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; /** * @author Oliver Grande * @since 1.1.1 * 13.02.2023 */ public interface ReferenceAccess { /** * See: <a * href= * "http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part3-csdl/odata-v4.0-errata03-os-part3-csdl-complete.html#_Toc453752506">3.4 * Element edmx:Include</a> * @param namespace Namespace of a schema defined in the referenced CSDL document to be included. The same namespace * MUST NOT be included more than once. * @param alias Alias for the given namespace. The alias must be unique. */ void addInclude(String namespace, String alias); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/Vocabulary.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/Vocabulary.java
/** * */ package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; import static java.lang.annotation.ElementType.ANNOTATION_TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Retention(RUNTIME) @Target(ANNOTATION_TYPE) /** * @author Oliver Grande * @since 1.1.1 * 02.01.2023 */ public @interface Vocabulary { /** * Alias given in the vocabulary definition. E.g. <em>Capabilities</em> for * <a href= * "https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/Org.OData.Capabilities.V1.xml">Org.OData.Capabilities.V1</a> */ String alias(); /** * Supported applicability. This could be a subset of the defined applicability. */ Applicability[] appliesTo(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/AliasAccess.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/AliasAccess.java
package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; public interface AliasAccess { String alias(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/NullAsDefault.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/NullAsDefault.java
package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; /** * Meta annotation to marks a field of an annotation that the real default value shall be null instead of the given one. * This is necessary as null as default is not supported by Java */ @Retention(RUNTIME) public @interface NullAsDefault { }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/Applicability.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/extension/vocabularies/Applicability.java
/** * */ package com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies; /** * <p> * Java enumeration for TAppliesTo. * See: <a href="https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#_Toc38530401">14.1.2 * Applicability</a> * * @author Oliver Grande * @since 1.1.1 * 04.01.2023 */ public enum Applicability { /** * Action */ ACTION("Action"), /** * Action Import */ ACTION_IMPORT("ActionImport"), /** * Annotation */ ANNOTATION("Annotation"), /** * Application of a client-side function in an annotation */ APPLY("Apply"), /** * Type Cast annotation expression */ CAST("Cast"), /** * Entity Set or collection-valued Property or Navigation Property */ COLLECTION("Collection"), /** * Complex Type */ COMPLEX_TYPE("ComplexType"), /** * Entity Container */ ENTITY_CONTAINER("EntityContainer"), /** * Entity Set */ ENTITY_SET("EntitySet"), /** * Entity Type */ ENTITY_TYPE("EntityType"), /** * Enumeration Type */ ENUM_TYPE("EnumType"), /** * Function */ FUNCTION("Function"), /** * Function Import */ FUNCTION_IMPORT("FunctionImport"), /** * Conditional annotation expression */ IF("If"), /** * Reference to an Included Schema */ INCLUDE("Include"), /** * Type Check annotation expression */ IS_OF("IsOf"), /** * Labeled Element expression */ LABELD_ELEMENT("LabeledElement"), /** * Enumeration Member */ MEMBER("Member"), /** * Navigation Property */ NAVIGATION_PROPERTY("NavigationProperty"), /** * Null annotation expression */ NULL("Null"), /** * On-Delete Action of a navigation property */ ON_DELETE("OnDelete"), /** * Action of Function Parameter */ PARAMETER("Parameter"), /** * Property of a structured type */ PROPERTY("Property"), /** * Property value of a Record annotation expression */ PROPERTY_VALUE("PropertyValue"), /** * Record annotation expression */ RECORD("Record"), /** * Reference to another CSDL document */ REFERENCE("Reference"), /** * Referential Constraint of a navigation property */ REFERENTIAL_CONSTRAINT("ReferentialConstraint"), /** * Return Type of an Action or Function */ RETURN_TYPE("ReturnType"), /** * Schema */ SCHEMA("Schema"), /** * Singleton */ SINGLETON("Singleton"), /** * Term */ TERM("Term"), /** * Type Definition */ TYPE_DEFINITION("TypeDefinition"), /** * UrlRef annotation expression */ URL_REF("UrlRef"); private String odataApplicability; /** * @param odataApplicability */ Applicability(final String odataApplicability) { this.odataApplicability = odataApplicability; } public String getOdataApplicability() { return odataApplicability; } public String value() { return odataApplicability; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Parameter.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Parameter.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.util.Objects; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.api.edm.provider.CsdlParameter; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class Parameter extends CsdlParameter { @Override @JacksonXmlProperty(localName = "Name") public CsdlParameter setName(final String name) { Objects.requireNonNull(name, "Name is a required attribute of parameter"); return super.setName(name); } @Override @JacksonXmlProperty(localName = "Type") public CsdlParameter setType(final String type) { Objects.requireNonNull(type, "Type is a required attribute of parameters"); if (type.startsWith("Collection")) { setCollection(true); return super.setType(new FullQualifiedName(type.split("[()]")[1])); } return super.setType(new FullQualifiedName(type)); } @Override @JacksonXmlProperty(localName = "Nullable") public CsdlParameter setNullable(final boolean nullable) { return super.setNullable(nullable); } @Override @JacksonXmlProperty(localName = "MaxLength", isAttribute = true) public CsdlParameter setMaxLength(Integer maxLength) { return super.setMaxLength(maxLength); } @Override @JacksonXmlProperty(localName = "Precision", isAttribute = true) public CsdlParameter setPrecision(final Integer precision) { return super.setPrecision(precision); } @Override @JacksonXmlProperty(localName = "Scale", isAttribute = true) public CsdlParameter setScale(final Integer scale) { return super.setScale(scale); } @JacksonXmlProperty(localName = "SRID", isAttribute = true) void setSrid(final String srid) { Objects.requireNonNull(srid); super.setSrid(SRID.valueOf(srid)); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Property.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Property.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.util.Objects; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.api.edm.provider.CsdlProperty; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class Property extends CsdlProperty { @Override @JacksonXmlProperty(localName = "Name", isAttribute = true) public CsdlProperty setName(final String name) { Objects.requireNonNull(name); return super.setName(name); } @Override @JacksonXmlProperty(localName = "Type", isAttribute = true) public CsdlProperty setType(final String type) { Objects.requireNonNull(type); if (type.startsWith("Collection")) { setCollection(true); return super.setType(new FullQualifiedName(type.split("[()]")[1])); } return super.setType(new FullQualifiedName(type)); } @Override @JacksonXmlProperty(localName = "DefaultValue", isAttribute = true) public CsdlProperty setDefaultValue(final String defaultValue) { return super.setDefaultValue(defaultValue); } @Override @JacksonXmlProperty(localName = "Nullable", isAttribute = true) public CsdlProperty setNullable(final boolean nullable) { return super.setNullable(nullable); } @Override @JacksonXmlProperty(localName = "MaxLength", isAttribute = true) public CsdlProperty setMaxLength(final Integer maxLength) { return super.setMaxLength(maxLength); } @Override @JacksonXmlProperty(localName = "Precision", isAttribute = true) public CsdlProperty setPrecision(final Integer precision) { return super.setPrecision(precision); } @Override @JacksonXmlProperty(localName = "Scale", isAttribute = true) public CsdlProperty setScale(final Integer scale) { return super.setScale(scale); } @Override @JacksonXmlProperty(localName = "Unicode", isAttribute = true) public CsdlProperty setUnicode(final boolean unicode) { return super.setUnicode(unicode); } @JacksonXmlProperty(localName = "SRID", isAttribute = true) void setSrid(final String srid) { Objects.requireNonNull(srid); super.setSrid(SRID.valueOf(srid)); } @Override public String toString() { return "Property [name=" + getName() + ", type=" + getType() + "]"; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/EdmxDataServices.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/EdmxDataServices.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.util.Arrays; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; @JsonIgnoreProperties(ignoreUnknown = true) @JacksonXmlRootElement(localName = "DataServices", namespace = "edmx") public class EdmxDataServices { @JacksonXmlProperty(localName = "Schema") private Schema[] schemas; List<Schema> getSchemas() { return Arrays.asList(schemas); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Function.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Function.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.util.Arrays; import java.util.Objects; import org.apache.olingo.commons.api.edm.provider.CsdlFunction; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; /** * Function as part of a OData vocabulary. <br> * @author Oliver Grande * */ @JsonIgnoreProperties(ignoreUnknown = true) public class Function extends CsdlFunction { @Override @JacksonXmlProperty(localName = "IsBound") public CsdlFunction setBound(final boolean isBound) { return super.setBound(isBound); } @Override @JacksonXmlProperty(localName = "IsComposable") public CsdlFunction setComposable(final boolean isComposable) { return super.setComposable(isComposable); } @Override @JacksonXmlProperty(localName = "EntitySetPath") public CsdlFunction setEntitySetPath(String entitySetPath) { return super.setEntitySetPath(entitySetPath); } @Override @JacksonXmlProperty(localName = "Name") public CsdlFunction setName(final String name) { Objects.requireNonNull(name, "Name is a required attribute of functions"); return super.setName(name); } @JacksonXmlProperty(localName = "Parameter") public void setParameters(final Parameter[] parameters) { this.parameters.addAll(Arrays.asList(parameters)); } @JacksonXmlProperty(localName = "ReturnType") public void setReturnType(final ReturnType returnType) { super.setReturnType(returnType); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Term.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Term.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.api.edm.provider.CsdlTerm; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies.ODataJPAVocabulariesException.MessageKeys; /** * <xs:complexType name="TTerm"> * <xs:sequence> * <xs:element ref="edm:Annotation" minOccurs="0" maxOccurs="unbounded" /> * </xs:sequence> * <xs:attribute name="Name" type="edm:TSimpleIdentifier" use="required" /> * <xs:attribute name="Type" type="edm:TTypeName" use="required" /> * <xs:attribute name="BaseTerm" type="edm:TQualifiedName" use="optional" /> * <xs:attribute name="Nullable" type="xs:boolean" use="optional" /> * <xs:attribute name="DefaultValue" type="xs:string" use="optional" /> * <xs:attribute name="AppliesTo" type="edm:TAppliesTo" use="optional" /> * <xs:attributeGroup ref="edm:TFacetAttributes" /> * </xs:complexType> * <xs:attributeGroup name="TFacetAttributes"> * <xs:attribute name="MaxLength" type="edm:TMaxLengthFacet" use="optional" /> * <xs:attribute name="Precision" type="edm:TPrecisionFacet" use="optional" /> * <xs:attribute name="Scale" type="edm:TScaleFacet" use="optional" /> * <xs:attribute name="SRID" type="edm:TSridFacet" use="optional" /> * <xs:attribute name="Unicode" type="edm:TUnicodeFacet" use="optional" /> * </xs:attributeGroup>} */ @JsonIgnoreProperties(ignoreUnknown = true) class Term extends CsdlTerm implements Named { @JacksonXmlProperty(localName = "AppliesTo", isAttribute = true) void setAppliesTo(final String appliesTo) { final List<String> result = new ArrayList<>(); if (appliesTo != null) { final String[] list = appliesTo.split(" "); result.addAll(Arrays.asList(list)); } super.setAppliesTo(result); } @Override @JacksonXmlProperty(localName = "Name", isAttribute = true) public CsdlTerm setName(final String name) { return super.setName(name); } @Override @JacksonXmlProperty(localName = "Type", isAttribute = true) public CsdlTerm setType(final String type) { return super.setType(type); } @Override @JacksonXmlProperty(localName = "BaseTerm", isAttribute = true) public CsdlTerm setBaseTerm(final String baseTerm) { return super.setBaseTerm(baseTerm); } @Override @JacksonXmlProperty(localName = "DefaultValue", isAttribute = true) public CsdlTerm setDefaultValue(final String defaultValue) { return super.setDefaultValue(defaultValue); } @Override @JacksonXmlProperty(localName = "Nullable", isAttribute = true) public CsdlTerm setNullable(final boolean nullable) { return super.setNullable(nullable); } @Override @JacksonXmlProperty(localName = "MaxLength", isAttribute = true) public CsdlTerm setMaxLength(final Integer maxLength) { return super.setMaxLength(maxLength); } /** * MUST be a positive integer. */ @Override @JacksonXmlProperty(localName = "Precision", isAttribute = true) public CsdlTerm setPrecision(final Integer precision) { return super.setPrecision(precision); } /** * A non negative integer or floating or variable. * </p> * The value <b>floating</b> means that the decimal property represents a decimal floating-point number whose number * of * significant digits is the value of the Precision facet. OData 4.0 responses MUST NOT specify the value floating. * </p> * The value <b>variable</b> means that the number of digits to the right of the decimal point may vary from zero to * the value of the Precision facet. * {@link https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_Scale} * @throws ODataJPAVocabulariesException * @throws ODataJPAModelException */ @JacksonXmlProperty(localName = "Scale", isAttribute = true) public CsdlTerm setScale(final String scaleValue) throws ODataJPAVocabulariesException { try { final Integer scale = Integer.valueOf(scaleValue); return super.setScale(scale); } catch (final NumberFormatException e) { throw new ODataJPAVocabulariesException(MessageKeys.VARIABLE_NOT_SUPPORTED, e, "Scale"); } } /** * For a geometry or geography property the SRID facet identifies which spatial reference system is applied to values * of the property on type instances. * </p> * The value of the SRID facet MUST be a non-negative integer or the special value variable. If no value is specified, * the attribute defaults to 0 for Geometry types or 4326 for Geography types. * </p> * The valid values of the SRID facet and their meanings are as defined by the European Petroleum Survey Group [EPSG]. * @param srid */ @JacksonXmlProperty(localName = "SRID", isAttribute = true) void setSrid(final String srid) { super.setSrid(SRID.valueOf(srid)); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/CsdlDocumentReader.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/CsdlDocumentReader.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URI; import java.nio.charset.Charset; import java.util.Objects; import java.util.Optional; import javax.annotation.Nonnull; import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies.ODataJPAVocabulariesException.MessageKeys; /** * * @author Oliver Grande * @since 15.12.2019 * @version 0.3.8 * */ public class CsdlDocumentReader { final JacksonXmlModule module; final XmlMapper xmlMapper; /** * */ public CsdlDocumentReader() { super(); module = new JacksonXmlModule(); module.setDefaultUseWrapper(false); xmlMapper = new XmlMapper(module); } //vocabularies String loadXML(@Nonnull final String path, @Nonnull final Charset charset) throws IOException, ODataJPAVocabulariesException { final Optional<InputStream> reader = Optional.ofNullable(this.getClass().getClassLoader() .getResourceAsStream(path)); final StringBuilder content = new StringBuilder(); try ( final InputStreamReader input = new InputStreamReader(reader.orElseThrow( () -> new ODataJPAVocabulariesException(MessageKeys.FILE_NOT_FOUND, path)), charset); final BufferedReader br = new BufferedReader(input)) { String line; while ((line = br.readLine()) != null) { content.append(line); } return content.toString(); } } /** * * @param path * @param charset * @return * @throws IOException * @throws ODataJPAVocabulariesException * @throws ODataJPAModelException * @throws NullPointerException */ public CsdlDocument readFromResource(@Nonnull final String path, @Nonnull final Charset charset) throws IOException, ODataJPAVocabulariesException { if (Objects.requireNonNull(path).isEmpty()) return null; return xmlMapper.readValue(loadXML(path, Objects.requireNonNull(charset)), CsdlDocument.class); } /** * * @param uri * @return * @throws IOException * @throws NullPointerException */ public CsdlDocument readFromURI(@Nonnull final URI uri) throws IOException { return xmlMapper.readValue(Objects.requireNonNull(uri).toURL(), CsdlDocument.class); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/EnumType.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/EnumType.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import org.apache.olingo.commons.api.edm.provider.CsdlEnumType; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class EnumType extends CsdlEnumType { @Override @JacksonXmlProperty(localName = "Name", isAttribute = true) public CsdlEnumType setName(final String name) { return super.setName(name); } @Override @JacksonXmlProperty(localName = "IsFlags", isAttribute = true) public CsdlEnumType setFlags(final boolean isFlags) { return super.setFlags(isFlags); } @Override @JacksonXmlProperty(localName = "UnderlyingType") public CsdlEnumType setUnderlyingType(final String underlyingType) { return super.setUnderlyingType(underlyingType); } @JacksonXmlProperty(localName = "Member") public void setMembers(final Member[] members) { for (final Member m : members) { this.getMembers().add(m); } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/ODataJPAVocabulariesException.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/ODataJPAVocabulariesException.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.util.Formatter; import java.util.Locale; import java.util.ResourceBundle; import java.util.ResourceBundle.Control; import org.apache.olingo.commons.api.ex.ODataException; public class ODataJPAVocabulariesException extends ODataException { private static final long serialVersionUID = 8367415692431546611L; private static final String BUNDLE_NAME = "vocabularies-exceptions-i18n"; private static final String UNKNOWN_MESSAGE = "No message text found"; private static final ResourceBundle BUNDLE = getResourceBundle(); private final MessageKeys id; private final String[] parameters; public enum MessageKeys { FILE_NOT_FOUND, VARIABLE_NOT_SUPPORTED; public String getKey() { return name(); } } public ODataJPAVocabulariesException(final MessageKeys id, final String... params) { super(""); this.id = id; this.parameters = params; } public ODataJPAVocabulariesException(final MessageKeys id, final Exception cause, final String... params) { super("", cause); this.id = id; this.parameters = params; } private static ResourceBundle getResourceBundle() { return ResourceBundle.getBundle(BUNDLE_NAME, Locale.ENGLISH, Control.getNoFallbackControl( Control.FORMAT_PROPERTIES)); } @Override public String getMessage() { if (id != null) { return getText(); } else if (getCause() != null) { return getCause().getLocalizedMessage(); } else return UNKNOWN_MESSAGE; } private String getText() { final String message = BUNDLE.getString(getClass().getSimpleName() + "." + id.getKey()); final StringBuilder builder = new StringBuilder(); final Formatter f = new Formatter(builder, Locale.ENGLISH); f.format(message, (Object[]) parameters); f.close(); return builder.toString(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Schema.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Schema.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import org.apache.olingo.commons.api.edm.provider.CsdlAction; import org.apache.olingo.commons.api.edm.provider.CsdlComplexType; import org.apache.olingo.commons.api.edm.provider.CsdlEnumType; import org.apache.olingo.commons.api.edm.provider.CsdlFunction; import org.apache.olingo.commons.api.edm.provider.CsdlSchema; import org.apache.olingo.commons.api.edm.provider.CsdlTerm; import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; /** * http://docs.oasis-open.org/odata/ns/edmx * @author Oliver Grande * */ @JsonIgnoreProperties(ignoreUnknown = true) class Schema { @JacksonXmlProperty(isAttribute = true) private String xmlns; @JacksonXmlProperty(isAttribute = true, localName = "Namespace") private String namespace; @JacksonXmlProperty(isAttribute = true, localName = "Alias") private String alias; @JacksonXmlProperty(localName = "EnumType") private final List<EnumType> enumerations = new ArrayList<>(); @JacksonXmlProperty(localName = "TypeDefinition") private final List<TypeDefinition> typeDefinitions = new ArrayList<>(); @JacksonXmlProperty(localName = "ComplexType") private final List<ComplexType> complexTypes = new ArrayList<>(); @JacksonXmlProperty(localName = "Term") private final List<Term> terms = new ArrayList<>(); @JacksonXmlProperty(localName = "Function") private final List<Function> functions = new ArrayList<>(); @JacksonXmlProperty(localName = "Action") private final List<Action> actions = new ArrayList<>(); CsdlSchema asCsdlSchema() { final CsdlSchema csdlSchema = new CsdlSchema(); csdlSchema.setAlias(alias); csdlSchema.setNamespace(namespace); csdlSchema.setTerms(asCsdlTerms()); csdlSchema.setEnumTypes(asEnumTypes()); csdlSchema.setComplexTypes(asComplexTypes()); csdlSchema.setTypeDefinitions(asTypeDefinitions()); csdlSchema.setFunctions(asFunctions()); csdlSchema.setActions(asActions()); return csdlSchema; } String getNamespace() { return namespace; } List<Term> getTerms() { return Collections.unmodifiableList(terms); } void setAlias(final String alias) { this.alias = alias; } @JsonSetter void setComplexTypes(final ComplexType[] newComplexTypes) { complexTypes.addAll(Arrays.asList(newComplexTypes)); } @JsonSetter void setEnumerations(final EnumType enumeration) { this.enumerations.add(enumeration); } @JsonSetter void setFunctions(final Function[] newFunctions) { functions.addAll(Arrays.asList(newFunctions)); } void setNamespace(final String namespace) { this.namespace = namespace; } @JsonSetter void setTerms(final Term[] newTerms) { terms.addAll(Arrays.asList(newTerms)); } @JsonSetter void setTypeDefinitions(final TypeDefinition typeDefinition) { this.typeDefinitions.add(typeDefinition); } private List<CsdlAction> asActions() { return Collections.unmodifiableList(actions); } private List<CsdlComplexType> asComplexTypes() { return Collections.unmodifiableList(complexTypes); } private List<CsdlTerm> asCsdlTerms() { return Collections.unmodifiableList(terms); } private List<CsdlEnumType> asEnumTypes() { return Collections.unmodifiableList(enumerations); } private List<CsdlFunction> asFunctions() { return Collections.unmodifiableList(functions); } private List<CsdlTypeDefinition> asTypeDefinitions() { return Collections.unmodifiableList(typeDefinitions); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/ComplexType.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/ComplexType.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import org.apache.olingo.commons.api.edm.provider.CsdlComplexType; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; /** * Complex Type for vocabulary definitions<br> * Not supported: <code>NavigationProperty</code>, no use case known * @author Oliver Grande * */ @JsonIgnoreProperties(ignoreUnknown = true) class ComplexType extends CsdlComplexType implements Named { @Override @JacksonXmlProperty(localName = "Name", isAttribute = true) public CsdlComplexType setName(final String name) { return super.setName(name); } @Override @JacksonXmlProperty(localName = "OpenType", isAttribute = true) public CsdlComplexType setOpenType(final boolean isOpenType) { return super.setOpenType(isOpenType); } @Override @JacksonXmlProperty(localName = "BaseType", isAttribute = true) public CsdlComplexType setBaseType(final String baseType) { return super.setBaseType(baseType); } @Override @JacksonXmlProperty(localName = "Abstract", isAttribute = true) public CsdlComplexType setAbstract(final boolean isAbstract) { return super.setAbstract(isAbstract); } @JacksonXmlProperty(localName = "Property") public void setProperties(final Property[] properties) { for (final Property p : properties) { this.properties.add(p); } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/ReturnType.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/ReturnType.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.util.Objects; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.api.edm.provider.CsdlReturnType; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class ReturnType extends CsdlReturnType { @Override @JacksonXmlProperty(localName = "Type") public CsdlReturnType setType(final String type) { Objects.requireNonNull(type, "Type is a required attribute of return type"); if (type.startsWith("Collection")) { setCollection(true); return super.setType(new FullQualifiedName(type.split("[()]")[1])); } return super.setType(new FullQualifiedName(type)); } @Override @JacksonXmlProperty(localName = "Nullable") public CsdlReturnType setNullable(final boolean nullable) { return super.setNullable(nullable); } @Override @JacksonXmlProperty(localName = "MaxLength", isAttribute = true) public CsdlReturnType setMaxLength(final Integer maxLength) { return super.setMaxLength(maxLength); } @Override @JacksonXmlProperty(localName = "Precision", isAttribute = true) public CsdlReturnType setPrecision(final Integer precision) { return super.setPrecision(precision); } @Override @JacksonXmlProperty(localName = "Scale", isAttribute = true) public CsdlReturnType setScale(final Integer scale) { return super.setScale(scale); } @JacksonXmlProperty(localName = "SRID", isAttribute = true) void setSrid(final String srid) { Objects.requireNonNull(srid); super.setSrid(SRID.valueOf(srid)); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/EdmxReferenceInclude.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/EdmxReferenceInclude.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; @JsonIgnoreProperties(ignoreUnknown = true) @JacksonXmlRootElement(localName = "Reference", namespace = "edmx") public class EdmxReferenceInclude { @JacksonXmlProperty(localName = "Namespace") private String namespace; @JacksonXmlProperty(localName = "Alias") private String alias; public String getNamespace() { return namespace; } public String getAlias() { return alias; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Member.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Member.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import org.apache.olingo.commons.api.edm.provider.CsdlEnumMember; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class Member extends CsdlEnumMember { @Override @JacksonXmlProperty(localName = "Name", isAttribute = true) public CsdlEnumMember setName(final String name) { return super.setName(name); } @Override @JacksonXmlProperty(localName = "Value", isAttribute = true) public CsdlEnumMember setValue(final String value) { return super.setValue(value); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Action.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Action.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.util.Arrays; import java.util.Objects; import org.apache.olingo.commons.api.edm.provider.CsdlAction; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class Action extends CsdlAction { @Override @JacksonXmlProperty(localName = "Name") public CsdlAction setName(final String name) { Objects.requireNonNull(name, "Name is a required attribute of actions"); return super.setName(name); } @Override @JacksonXmlProperty(localName = "IsBound") public CsdlAction setBound(final boolean isBound) { return super.setBound(isBound); } @Override @JacksonXmlProperty(localName = "EntitySetPath") public CsdlAction setEntitySetPath(String entitySetPath) { return super.setEntitySetPath(entitySetPath); } @JacksonXmlProperty(localName = "Parameter") public void setParameters(final Parameter[] parameters) { this.parameters.addAll(Arrays.asList(parameters)); } @JacksonXmlProperty(localName = "ReturnType") public void setReturnType(final ReturnType returnType) { super.setReturnType(returnType); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Named.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/Named.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import org.apache.olingo.commons.api.edm.provider.CsdlNamed; interface Named { public String getName(); public CsdlNamed setName(final String name); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/EdmxReference.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/EdmxReference.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.net.URI; import java.util.Arrays; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; @JsonIgnoreProperties(ignoreUnknown = true) @JacksonXmlRootElement(localName = "Reference", namespace = "edmx") public class EdmxReference { @JacksonXmlProperty(localName = "Uri") private String uri; @JacksonXmlProperty(localName = "Include") private EdmxReferenceInclude[] includes; public URI getUri() { return URI.create(uri); } public List<EdmxReferenceInclude> getIncludes() { return Arrays.asList(includes); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/CsdlDocument.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/CsdlDocument.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.apache.olingo.commons.api.edm.provider.CsdlSchema; import org.apache.olingo.commons.api.edm.provider.CsdlTerm; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; @JsonIgnoreProperties(ignoreUnknown = true) @JacksonXmlRootElement(localName = "Edmx", namespace = "edmx") public class CsdlDocument { @JacksonXmlProperty(localName = "Reference") private EdmxReference[] reference; @JacksonXmlProperty(localName = "DataServices") private EdmxDataServices service; EdmxDataServices getDataService() { return service; } List<EdmxReference> getReference() { return Arrays.asList(reference); } public Map<String, CsdlSchema> getSchemas() { if (service != null) return service.getSchemas().stream() .collect(Collectors.toMap(Schema::getNamespace, Schema::asCsdlSchema)); return Collections.emptyMap(); } public Map<String, Map<String, CsdlTerm>> getTerms() { if (service != null) return service.getSchemas().stream() .collect(Collectors.toMap( Schema::getNamespace, schema -> schema.getTerms().stream() .collect(Collectors.toMap(CsdlTerm::getName, t -> t)))); return Collections.emptyMap(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/TypeDefinition.java
jpa/odata-jpa-vocabularies/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/vocabularies/TypeDefinition.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.vocabularies; import java.util.Objects; import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; @JsonIgnoreProperties(ignoreUnknown = true) class TypeDefinition extends CsdlTypeDefinition { @Override @JacksonXmlProperty(localName = "Name", isAttribute = true) public CsdlTypeDefinition setName(final String name) { return super.setName(name); } @Override @JacksonXmlProperty(localName = "UnderlyingType", isAttribute = true) public CsdlTypeDefinition setUnderlyingType(final String underlyingType) { return super.setUnderlyingType(underlyingType); } @Override @JacksonXmlProperty(localName = "MaxLength", isAttribute = true) public CsdlTypeDefinition setMaxLength(final Integer maxLength) { return super.setMaxLength(maxLength); } @Override @JacksonXmlProperty(localName = "Precision", isAttribute = true) public CsdlTypeDefinition setPrecision(final Integer precision) { return super.setPrecision(precision); } @Override @JacksonXmlProperty(localName = "Scale", isAttribute = true) public CsdlTypeDefinition setScale(final Integer scale) { return super.setScale(scale); } @Override @JacksonXmlProperty(localName = "Unicode", isAttribute = true) public CsdlTypeDefinition setUnicode(final boolean unicode) { return super.setUnicode(unicode); } @JacksonXmlProperty(localName = "SRID", isAttribute = true) void setSrid(final String srid) { Objects.requireNonNull(srid); super.setSrid(SRID.valueOf(srid)); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
alkarn/sslengine.example
https://github.com/alkarn/sslengine.example/blob/13a9e6cb04713213a8ac3fc7ced06e5ef8cdf720/src/test/java/alkarn/github/io/sslengine/example/ServerRunnable.java
src/test/java/alkarn/github/io/sslengine/example/ServerRunnable.java
package alkarn.github.io.sslengine.example; /** * This class provides a runnable that can be used to initialize a {@link NioSslServer} thread. * <p/> * Run starts the server, which will start listening to the configured IP address and port for * new SSL/TLS connections and serve the ones already connected to it. * <p/> * Also a stop method is provided in order to gracefully close the server and stop the thread. * * @author <a href="mailto:alex.a.karnezis@gmail.com">Alex Karnezis</a> */ public class ServerRunnable implements Runnable { NioSslServer server; @Override public void run() { try { server = new NioSslServer("TLSv1.2", "localhost", 9222); server.start(); } catch (Exception e) { e.printStackTrace(); } } /** * Should be called in order to gracefully stop the server. */ public void stop() { server.stop(); } }
java
MIT
13a9e6cb04713213a8ac3fc7ced06e5ef8cdf720
2026-01-05T02:42:05.260857Z
false
alkarn/sslengine.example
https://github.com/alkarn/sslengine.example/blob/13a9e6cb04713213a8ac3fc7ced06e5ef8cdf720/src/test/java/alkarn/github/io/sslengine/example/Demo.java
src/test/java/alkarn/github/io/sslengine/example/Demo.java
package alkarn.github.io.sslengine.example; public class Demo { ServerRunnable serverRunnable; public Demo() { serverRunnable = new ServerRunnable(); Thread server = new Thread(serverRunnable); server.start(); } public void runDemo() throws Exception { // System.setProperty("javax.net.debug", "all"); NioSslClient client = new NioSslClient("TLSv1.2", "localhost", 9222); client.connect(); client.write("Hello! I am a client!"); client.read(); client.shutdown(); NioSslClient client2 = new NioSslClient("TLSv1.2", "localhost", 9222); NioSslClient client3 = new NioSslClient("TLSv1.2", "localhost", 9222); NioSslClient client4 = new NioSslClient("TLSv1.2", "localhost", 9222); client2.connect(); client2.write("Hello! I am another client!"); client2.read(); client2.shutdown(); client3.connect(); client4.connect(); client3.write("Hello from client3!!!"); client4.write("Hello from client4!!!"); client3.read(); client4.read(); client3.shutdown(); client4.shutdown(); serverRunnable.stop(); } public static void main(String[] args) throws Exception { Demo demo = new Demo(); Thread.sleep(1000); // Give the server some time to start. demo.runDemo(); } }
java
MIT
13a9e6cb04713213a8ac3fc7ced06e5ef8cdf720
2026-01-05T02:42:05.260857Z
false
alkarn/sslengine.example
https://github.com/alkarn/sslengine.example/blob/13a9e6cb04713213a8ac3fc7ced06e5ef8cdf720/src/main/java/alkarn/github/io/sslengine/example/NioSslClient.java
src/main/java/alkarn/github/io/sslengine/example/NioSslClient.java
package alkarn.github.io.sslengine.example; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.security.SecureRandom; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLException; import javax.net.ssl.SSLSession; /** * An SSL/TLS client that connects to a server using its IP address and port. * <p/> * After initialization of a {@link NioSslClient} object, {@link NioSslClient#connect()} should be called, * in order to establish connection with the server. * <p/> * When the connection between the client and the object is established, {@link NioSslClient} provides * a public write and read method, in order to communicate with its peer. * * @author <a href="mailto:alex.a.karnezis@gmail.com">Alex Karnezis</a> */ public class NioSslClient extends NioSslPeer { /** * The remote address of the server this client is configured to connect to. */ private String remoteAddress; /** * The port of the server this client is configured to connect to. */ private int port; /** * The engine that will be used to encrypt/decrypt data between this client and the server. */ private SSLEngine engine; /** * The socket channel that will be used as the transport link between this client and the server. */ private SocketChannel socketChannel; /** * Initiates the engine to run as a client using peer information, and allocates space for the * buffers that will be used by the engine. * * @param protocol The SSL/TLS protocol to be used. Java 1.6 will only run with up to TLSv1 protocol. Java 1.7 or higher also supports TLSv1.1 and TLSv1.2 protocols. * @param remoteAddress The IP address of the peer. * @param port The peer's port that will be used. * @throws Exception */ public NioSslClient(String protocol, String remoteAddress, int port) throws Exception { this.remoteAddress = remoteAddress; this.port = port; SSLContext context = SSLContext.getInstance(protocol); context.init(createKeyManagers("./src/main/resources/client.jks", "storepass", "keypass"), createTrustManagers("./src/main/resources/trustedCerts.jks", "storepass"), new SecureRandom()); engine = context.createSSLEngine(remoteAddress, port); engine.setUseClientMode(true); SSLSession session = engine.getSession(); myAppData = ByteBuffer.allocate(1024); myNetData = ByteBuffer.allocate(session.getPacketBufferSize()); peerAppData = ByteBuffer.allocate(1024); peerNetData = ByteBuffer.allocate(session.getPacketBufferSize()); } /** * Opens a socket channel to communicate with the configured server and tries to complete the handshake protocol. * * @return True if client established a connection with the server, false otherwise. * @throws Exception */ public boolean connect() throws Exception { socketChannel = SocketChannel.open(); socketChannel.configureBlocking(false); socketChannel.connect(new InetSocketAddress(remoteAddress, port)); while (!socketChannel.finishConnect()) { // can do something here... } engine.beginHandshake(); return doHandshake(socketChannel, engine); } /** * Public method to send a message to the server. * * @param message - message to be sent to the server. * @throws IOException if an I/O error occurs to the socket channel. */ public void write(String message) throws IOException { write(socketChannel, engine, message); } /** * Implements the write method that sends a message to the server the client is connected to, * but should not be called by the user, since socket channel and engine are inner class' variables. * {@link NioSslClient#write(String)} should be called instead. * * @param message - message to be sent to the server. * @param engine - the engine used for encryption/decryption of the data exchanged between the two peers. * @throws IOException if an I/O error occurs to the socket channel. */ @Override protected void write(SocketChannel socketChannel, SSLEngine engine, String message) throws IOException { log.debug("About to write to the server..."); myAppData.clear(); myAppData.put(message.getBytes()); myAppData.flip(); while (myAppData.hasRemaining()) { // The loop has a meaning for (outgoing) messages larger than 16KB. // Every wrap call will remove 16KB from the original message and send it to the remote peer. myNetData.clear(); SSLEngineResult result = engine.wrap(myAppData, myNetData); switch (result.getStatus()) { case OK: myNetData.flip(); while (myNetData.hasRemaining()) { socketChannel.write(myNetData); } log.debug("Message sent to the server: " + message); break; case BUFFER_OVERFLOW: myNetData = enlargePacketBuffer(engine, myNetData); break; case BUFFER_UNDERFLOW: throw new SSLException("Buffer underflow occured after a wrap. I don't think we should ever get here."); case CLOSED: closeConnection(socketChannel, engine); return; default: throw new IllegalStateException("Invalid SSL status: " + result.getStatus()); } } } /** * Public method to try to read from the server. * * @throws Exception */ public void read() throws Exception { read(socketChannel, engine); } /** * Will wait for response from the remote peer, until it actually gets something. * Uses {@link SocketChannel#read(ByteBuffer)}, which is non-blocking, and if * it gets nothing from the peer, waits for {@code waitToReadMillis} and tries again. * <p/> * Just like {@link NioSslClient#read(SocketChannel, SSLEngine)} it uses inner class' socket channel * and engine and should not be used by the client. {@link NioSslClient#read()} should be called instead. * * @param message - message to be sent to the server. * @param engine - the engine used for encryption/decryption of the data exchanged between the two peers. * @throws Exception */ @Override protected void read(SocketChannel socketChannel, SSLEngine engine) throws Exception { log.debug("About to read from the server..."); peerNetData.clear(); int waitToReadMillis = 50; boolean exitReadLoop = false; while (!exitReadLoop) { int bytesRead = socketChannel.read(peerNetData); if (bytesRead > 0) { peerNetData.flip(); while (peerNetData.hasRemaining()) { peerAppData.clear(); SSLEngineResult result = engine.unwrap(peerNetData, peerAppData); switch (result.getStatus()) { case OK: peerAppData.flip(); log.debug("Server response: " + new String(peerAppData.array())); exitReadLoop = true; break; case BUFFER_OVERFLOW: peerAppData = enlargeApplicationBuffer(engine, peerAppData); break; case BUFFER_UNDERFLOW: peerNetData = handleBufferUnderflow(engine, peerNetData); break; case CLOSED: closeConnection(socketChannel, engine); return; default: throw new IllegalStateException("Invalid SSL status: " + result.getStatus()); } } } else if (bytesRead < 0) { handleEndOfStream(socketChannel, engine); return; } Thread.sleep(waitToReadMillis); } } /** * Should be called when the client wants to explicitly close the connection to the server. * * @throws IOException if an I/O error occurs to the socket channel. */ public void shutdown() throws IOException { log.debug("About to close connection with the server..."); closeConnection(socketChannel, engine); executor.shutdown(); log.debug("Goodbye!"); } }
java
MIT
13a9e6cb04713213a8ac3fc7ced06e5ef8cdf720
2026-01-05T02:42:05.260857Z
false