Exemple #1
0
  /**
   * 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);
  }
Exemple #2
0
  /**
   * 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);
  }