@Override public ODataResponse writeFunctionImport(final EdmFunctionImport functionImport, final Object data, final EntityProviderWriteProperties properties) throws EntityProviderException { try { if (functionImport.getReturnType().getType().getKind() == EdmTypeKind.ENTITY) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) data; return writeEntry(functionImport.getEntitySet(), map, properties); } final EntityPropertyInfo info = EntityInfoAggregator.create(functionImport); if (functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY) { return writeCollection(info, (List<?>) data); } else { return writeSingleTypedElement(info, data); } } catch (final EdmException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }
private String getFunctionFqn( EdmFunctionImport functionImport) throws EdmException { String functionFqn; if(functionImport.getEntitySet()!=null) //If the function import returns Collection of Entities, then only it has EntitySet specified in Edmx functionFqn = functionImport.getEntitySet().getEntityType().getNamespace()+"."+functionImport.getName(); else{ functionFqn = this.service.getServiceName()+"."+functionImport.getName(); } return functionFqn; }
private Class<?>[] getParameterTypes() throws EdmException { Class<?>[] parameterTypes = new Class<?>[functionImport.getParameterNames().size()]; int i = 0; for (String parameterName : functionImport.getParameterNames()) { EdmParameter parameter = functionImport.getParameter(parameterName); parameterTypes[i++] = ((JPAEdmMapping) parameter.getMapping()).getJPAType(); } return parameterTypes; }
private static String getFunctionImportKey(EdmFunctionImport functionImport) throws EdmException { return /* schema.getNamespace() + "~" + */functionImport.getEntityContainer().getName() + "~" + functionImport.getName(); }
/** * Create an {@link EntityPropertyInfo} based on given {@link EdmFunctionImport} * * @param functionImport * for which the {@link EntityPropertyInfo} is created. * @return created {@link EntityPropertyInfo} * @throws EntityProviderException * if create of {@link EntityPropertyInfo} something goes wrong (e.g. exceptions during * access of {@link EdmFunctionImport}). */ public static EntityPropertyInfo create(final EdmFunctionImport functionImport) throws EntityProviderException { try { EntityInfoAggregator eia = new EntityInfoAggregator(); return eia.createEntityPropertyInfo(functionImport, functionImport.getReturnType().getType()); } catch (EdmException e) { throw new EntityProviderException(EntityProviderException.COMMON, e); } }
try { if (functionParameters.isEmpty()) { Collection<String> params = function.getEntityContainer().getFunctionImport(function.getName()) .getParameterNames(); if (!(params == null || params.isEmpty())) { ErrorResponseImpl errorResp = new ErrorResponseImpl(400, "", "Invalid Function Import Parameter", String key = iterator.next(); EdmLiteral literal = functionParameters.get(key); EdmParameter param = function.getParameter(key); EntityMetadata entityMetadata = function.getEntitySet() == null ? null : new EntityMetadataV2(function.getEntitySet()); OperationRequest operationRequest = new OperationRequestImpl(null, function.getName(), entityMetadata, context.getRequestHeaders(), funcParams, function.getHttpMethod()); String operation = operationRequest.getHttpMethod().equals("POST") ? Action : Function; operationResponse = (OperationResponseImpl) ProcessorHelper.invokeOperation(operationRequest, serviceName,
@Override public EdmURIBuilder appendFunctionImportSegment(EdmFunctionImport functionImport) { try { state = functionImport.getReturnType() != null ? (functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY && functionImport.getReturnType().getType().getKind() == EdmTypeKind.ENTITY ? SegmentType.FUNCTIONIMPORT_MANY : SegmentType.FUNCTIONIMPORT) : SegmentType.FUNCTIONIMPORT; segments.add(new Segment(state, functionImport.getName())); } catch (EdmException e) { throw new RuntimeException("Unexpected EDM Exception: ", e);//NOSONAR } return this; }
if (uriInfo.getFunctionImport().getEntitySet() != null) { List<String> propertNames = uriInfo.getFunctionImport().getEntitySet().getEntityType().getPropertyNames(); for (String propertyName : propertNames) { if (uriInfo.getFunctionImport().getEntitySet().getEntityType().getProperty(propertyName) .getType() instanceof EdmGuid) { coloumnNames.add(propertyName); String functionName = uriInfo.getFunctionImport().getName(); ExtensionHolder holder = null; boolean withinChangeSet = extensionMethodForTransaction != null; if (uriInfo.getFunctionImport().getHttpMethod().compareTo("GET") == 0) { } else if (uriInfo.getFunctionImport().getHttpMethod().compareTo("POST") == 0) {
private List<KeyPredicate> getKeysFromFunctionImportParams(GetFunctionImportUriInfo uriInfo, boolean removeIsActiveEntity) throws EdmException { List<KeyPredicate> allKeys = new ArrayList<>(); Map<String, EdmLiteral> parameters = uriInfo.getFunctionImportParameters(); List<EdmProperty> keyList = uriInfo.getFunctionImport().getEntitySet().getEntityType().getKeyProperties(); Iterator<EdmProperty> keysPropItr = keyList.iterator(); while(keysPropItr.hasNext()){ EdmProperty property = keysPropItr.next(); if(removeIsActiveEntity && DraftUtilsV2.DRAFTS_ISACTIVE_ENTITY.equalsIgnoreCase(property.getName())){ continue; } String literal = parameters.get(property.getName()).getLiteral(); allKeys.add(new KeyPredicateImpl(literal, property)); } return allKeys; }
@Override public EdmFunctionImport getFunctionImport(final String name) throws EdmException { for (EdmFunctionImport edmFunctionImport : edmFunctionImports) { if (edmFunctionImport.getName().equalsIgnoreCase(name)) { return edmFunctionImport; } } return null; }
private static void checkFunctionImport(final ODataHttpMethod method, final UriInfoImpl uriInfo) throws ODataException { if (uriInfo.getFunctionImport() != null && uriInfo.getFunctionImport().getHttpMethod() != null && !uriInfo.getFunctionImport().getHttpMethod().equals(method.toString())) { throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH); } }
/** * Create an {@link EntityPropertyInfo} based on given {@link EdmFunctionImport} * * @param functionImport * for which the {@link EntityPropertyInfo} is created. * @return created {@link EntityPropertyInfo} * @throws EntityProviderException * if create of {@link EntityPropertyInfo} something goes wrong (e.g. exceptions during * access of {@link EdmFunctionImport}). */ public static EntityPropertyInfo create(final EdmFunctionImport functionImport) throws EntityProviderException { try { EntityInfoAggregator eia = new EntityInfoAggregator(); return eia.createEntityPropertyInfo(functionImport, functionImport.getReturnType().getType()); } catch (EdmException e) { throw new EntityProviderException(EntityProviderException.COMMON, e); } }
private void validateFunctionImport() throws EntityProviderException, EdmException { for (EdmFunctionImport functionImport : edmFunctionImportList) { EdmTyped returnType = functionImport.getReturnType(); if (returnType != null) { FullQualifiedName fqn = extractFQName(returnType.toString()); String entitySet = ((EdmFunctionImportImpl)functionImport).getEntitySetName(); if (returnType.getMultiplicity() == EdmMultiplicity.MANY && entitySet == null && entityTypesMap.get( fqn) != null) { throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE.addContent("EntitySet = " + entitySet, XmlMetadataConstants.EDM_FUNCTION_IMPORT + " = " + functionImport.getName())); } else if (returnType.getMultiplicity() != EdmMultiplicity.MANY && entitySet != null && entityTypesMap.get( fqn) == null) { throw new EntityProviderException(EntityProviderException.INVALID_ATTRIBUTE.addContent("EntitySet = " + entitySet, XmlMetadataConstants.EDM_FUNCTION_IMPORT + " = " + functionImport.getName())); } } } }
private Object retrieveData(final EdmEntitySet startEntitySet, final List<KeyPredicate> keyPredicates, final EdmFunctionImport functionImport, final Map<String, Object> functionImportParameters, final List<NavigationSegment> navigationSegments) throws ODataException { Object data; final Map<String, Object> keys = mapKey(keyPredicates); ODataContext context = getContext(); final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "retrieveData"); try { data = functionImport == null ? keys.isEmpty() ? dataSource.readData(startEntitySet) : dataSource.readData(startEntitySet, keys) : dataSource.readData(functionImport, functionImportParameters, keys); EdmEntitySet currentEntitySet = functionImport == null ? startEntitySet : functionImport.getEntitySet(); for (NavigationSegment navigationSegment : navigationSegments) { data = dataSource.readRelatedData( currentEntitySet, data, navigationSegment.getEntitySet(), mapKey(navigationSegment.getKeyPredicates())); currentEntitySet = navigationSegment.getEntitySet(); } } finally { context.stopRuntimeMeasurement(timingHandle); } return data; }
public static String getFunctionImportLog(EdmFunctionImport functionImport) { StringBuffer sb = new StringBuffer(); sb.append("function import = "); if (functionImport == null) { sb.append("<null>"); } else { try { String name = functionImport.getName(); sb.append(name == null ? "<null>" : name); } catch (EdmException e) { sb.append("<error>"); } } return sb.toString(); }
private static void checkFunctionImport(final ODataHttpMethod method, final UriInfoImpl uriInfo) throws ODataException { if (uriInfo.getFunctionImport() != null && uriInfo.getFunctionImport().getHttpMethod() != null && !uriInfo.getFunctionImport().getHttpMethod().equals(method.toString())) { throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH); } }
@Override public ODataResponse writeFunctionImport(final EdmFunctionImport functionImport, final Object data, final EntityProviderWriteProperties properties) throws EntityProviderException { try { final EdmType type = functionImport.getReturnType().getType(); final boolean isCollection = functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY; if (type.getKind() == EdmTypeKind.ENTITY) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) data; return writeEntry(functionImport.getEntitySet(), map, properties); } final EntityPropertyInfo info = EntityInfoAggregator.create(functionImport); if (isCollection) { return writeCollection(info, (List<?>) data); } else { return writeSingleTypedElement(info, data); } } catch (EdmException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }
/** * Create an {@link EntityPropertyInfo} based on given {@link EdmFunctionImport} * * @param functionImport * for which the {@link EntityPropertyInfo} is created. * @return created {@link EntityPropertyInfo} * @throws EntityProviderException * if create of {@link EntityPropertyInfo} something goes wrong (e.g. exceptions during * access of {@link EdmFunctionImport}). */ public static EntityPropertyInfo create(final EdmFunctionImport functionImport) throws EntityProviderException { try { EntityInfoAggregator eia = new EntityInfoAggregator(); return eia.createEntityPropertyInfo(functionImport, functionImport.getReturnType().getType()); } catch (EdmException e) { throw new EntityProviderException(EntityProviderException.COMMON, e); } }
@Override public IDataProviderResponse executeFunctionImport(GetFunctionImportUriInfo uriInfo, ODataContext context) throws ODataException { String functionName = uriInfo.getFunctionImport().getName(); String draftActivate = ""; String draftEdit = ""; String draftPrepare = ""; if(uriInfo.getFunctionImport() != null && uriInfo.getFunctionImport().getEntitySet() != null){ //V2 metadata function imports are embedded with entityset name. draftActivate = uriInfo.getFunctionImport().getEntitySet().getName() + "_" + "draftActivate"; draftEdit = uriInfo.getFunctionImport().getEntitySet().getName() + "_" + "draftEdit"; draftPrepare = uriInfo.getFunctionImport().getEntitySet().getName() + "_" + "draftPrepare"; } if(draftActivate.equals(functionName)){ return handleActionForDraftActivate(uriInfo, context); }else if(draftEdit.equals(functionName)){ return handleActionForDraftEdit(uriInfo, context); }else if(draftPrepare.equals(functionName)){ return handleActionForDraftPrepare(uriInfo, context); }else{ return handleFunctionGenericNormalFlow(uriInfo, context); } }
private Class<?>[] getParameterTypes() throws EdmException { Class<?>[] parameterTypes = new Class<?>[functionImport.getParameterNames().size()]; int i = 0; for (String parameterName : functionImport.getParameterNames()) { EdmParameter parameter = functionImport.getParameter(parameterName); parameterTypes[i++] = ((JPAEdmMapping) parameter.getMapping()).getJPAType(); } return parameterTypes; }