/** * Process a legacy V1 request (single item) * * @param hyperionContext The context */ protected void processLegacyRequest(HyperionContext hyperionContext) { EndpointRequest request = hyperionContext.getEndpointRequest(); EndpointResponse response = hyperionContext.getEndpointResponse(); ApiVersionPlugin<ApiObject<Serializable>, PersistentObject<Serializable>, Serializable> apiVersionPlugin = hyperionContext.getVersionPlugin(); EntityPlugin plugin = hyperionContext.getEntityPlugin(); ApiObject clientObject = null; try { clientObject = marshaller.unmarshall(request.getInputStream(), apiVersionPlugin.getApiClass()); } catch (MarshallingException e) { throw new BadRequestException( messageSource.getErrorMessage( ERROR_READING_REQUEST, hyperionContext.getLocale(), e.getMessage()), e); } clientObject.setId(null); PersistenceContext persistenceContext = buildPersistenceContext(hyperionContext); Set<String> fieldSet = persistenceContext.getRequestedFields(); if (fieldSet != null) fieldSet.add("id"); ApiObject saved = (ApiObject) plugin .getPersistenceOperations() .createOrUpdateItems(Collections.singletonList(clientObject), persistenceContext) .get(0); processChangeEvents(hyperionContext, persistenceContext); response.setResponseCode(200); hyperionContext.setResult(saved); }
protected void processChangeEvents( HyperionContext phaseContext, PersistenceContext persistenceContext) { EntityPlugin entityPlugin = phaseContext.getEntityPlugin(); if (!entityPlugin.hasEntityChangeListeners()) return; List<EntityChangeListener> entityChangeListeners = entityPlugin.getEntityChangeListeners(); for (EntityChangeListener entityChangeListener : entityChangeListeners) { for (EntityChangeEvent event : persistenceContext.getEntityChangeEvents()) { entityChangeListener.processEntityChange(event); } } }
protected List convertIds(HyperionContext phaseContext, EntityPlugin plugin) { try { return plugin.getKeyConverter().covertKeys(phaseContext.getId()); } catch (KeyConverterException e) { throw new BadParameterException( messageSource.getErrorMessage(INVALID_ID, phaseContext.getLocale(), e.getValue())); } }
/** * Process a multi-item request * * @param hyperionContext The context */ protected void processCollectionRequest(HyperionContext hyperionContext) { EndpointRequest request = hyperionContext.getEndpointRequest(); EndpointResponse response = hyperionContext.getEndpointResponse(); ApiVersionPlugin<ApiObject<Serializable>, PersistentObject<Serializable>, Serializable> apiVersionPlugin = hyperionContext.getVersionPlugin(); EntityPlugin plugin = hyperionContext.getEntityPlugin(); List<ApiObject<Serializable>> clientObjects = null; try { clientObjects = marshaller.unmarshallCollection(request.getInputStream(), apiVersionPlugin.getApiClass()); } catch (WriteLimitException e) { throw new BadRequestException( messageSource.getErrorMessage( ERROR_WRITE_LIMIT, hyperionContext.getLocale(), e.getWriteLimit()), e); } catch (MarshallingException e) { throw new BadRequestException( messageSource.getErrorMessage( ERROR_READING_REQUEST, hyperionContext.getLocale(), e.getMessage()), e); } PersistenceContext persistenceContext = buildPersistenceContext(hyperionContext); Set<String> fieldSet = persistenceContext.getRequestedFields(); if (fieldSet != null) fieldSet.add("id"); List<ApiObject> saved = plugin.getPersistenceOperations().createOrUpdateItems(clientObjects, persistenceContext); processChangeEvents(hyperionContext, persistenceContext); response.setResponseCode(200); EntityList<ApiObject> entityResponse = new EntityList<>(); entityResponse.setEntries(saved); hyperionContext.setResult(entityResponse); }
protected PersistenceContext buildPersistenceContext(HyperionContext context) { EntityPlugin entityPlugin = context.getEntityPlugin(); HyperionRequest endpointRequest = context.getEndpointRequest(); PersistenceContext persistenceContext = new PersistenceContext(); persistenceContext.setEntityPlugin(entityPlugin); persistenceContext.setEntity(entityPlugin.getEndpointName()); persistenceContext.setHttpMethod(context.getEffectiveMethod()); persistenceContext.setApiVersionPlugin(context.getVersionPlugin()); persistenceContext.setUserContext(context.getAuthorizationContext().getUserContext()); persistenceContext.setRequestedFields( buildFieldSet(endpointRequest.getFirstParameter("fields"))); persistenceContext.setAuthorizationContext(context.getAuthorizationContext()); persistenceContext.setLocale(context.getLocale()); persistenceContext.setMessageSource(messageSource); Set<String> additionalParameters = entityPlugin.getAdditionalParameters(); if (additionalParameters != null && additionalParameters.size() > 0) persistenceContext.setAdditionalParameters( endpointRequest.getParameterMap(additionalParameters)); return persistenceContext; }