示例#1
0
  @RequestMapping(
      value = ADD_DOCUMENT_REQUEST,
      method = {RequestMethod.POST})
  public void addDocument(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam(value = "api", required = false) boolean api)
      throws IOException {

    if (apiRequested(response, api, ADD_DOCUMENT_REQUEST)) return;

    com.c9a.buffers.CatalogServiceRequestProtocalBuffer.AddDocumentRequest addNewDocumentRequest =
        com.c9a.buffers.CatalogServiceRequestProtocalBuffer.AddDocumentRequest.parseFrom(
            GoogleProtoclBufferRequestContentUtils.getContentForRequest(request));

    try {

      Reference ref =
          catalogService.addDocument(
              addNewDocumentRequest.getUserId(),
              addNewDocumentRequest.getPartitionId(),
              addNewDocumentRequest.getDocument().getName(),
              addNewDocumentRequest.getParentCatalogCollectionId(),
              addNewDocumentRequest.getDocument().getContent().toByteArray(),
              createPermissionListFromProtoBufEnumList(addNewDocumentRequest.getPermissionsList()),
              createNewMap(addNewDocumentRequest.getAttributesList()));

      CatalogGPBUtils.generateReferenceResponseProtoBuf(
              ref, com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode.SUCCESS, "")
          .build()
          .writeTo(response.getOutputStream());
      return;

    } catch (CollectionNotFoundException e) {
      CatalogGPBUtils.generateCatalogCollectionResponseProtoBufError(
              com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode
                  .COLLECTION_NOT_FOUND,
              "The collection can not be found with unique id : "
                  + addNewDocumentRequest.getParentCatalogCollectionId())
          .build()
          .writeTo(response.getOutputStream());
      return;
    } catch (CollectionModificationException e) {
      CatalogGPBUtils.generateCatalogCollectionResponseProtoBufError(
              com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode
                  .COLLECTION_CAN_NOT_BE_MODIFIED,
              "The parent collection can not be modified : "
                  + addNewDocumentRequest.getParentCatalogCollectionId())
          .build()
          .writeTo(response.getOutputStream());
      return;
    }
  }
示例#2
0
  @RequestMapping(
      value = GET_REFERENCE_REQUEST,
      method = {RequestMethod.POST})
  public void getReference(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam(value = "api", required = false) boolean api)
      throws IOException {

    if (apiRequested(response, api, GET_REFERENCE_REQUEST)) return;

    com.c9a.buffers.CatalogServiceRequestProtocalBuffer.GetReferenceRequest getReferenceRequest =
        com.c9a.buffers.CatalogServiceRequestProtocalBuffer.GetReferenceRequest.parseFrom(
            GoogleProtoclBufferRequestContentUtils.getContentForRequest(request));

    try {
      Reference ref =
          catalogService.getReference(
              getReferenceRequest.getUserId(),
              getReferenceRequest.getPartitionId(),
              getReferenceRequest.getUniqueId());
      CatalogGPBUtils.generateReferenceResponseProtoBuf(
              ref, com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode.SUCCESS, "")
          .build()
          .writeTo(response.getOutputStream());
      return;
    } catch (ReferenceNotFoundException e) {
      CatalogGPBUtils.generateCatalogCollectionResponseProtoBufError(
              com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode.REFERENCE_NOT_FOUND,
              "The reference can not be found with unique id : "
                  + getReferenceRequest.getUniqueId())
          .build()
          .writeTo(response.getOutputStream());
      return;
    }
  }
示例#3
0
  @RequestMapping(
      value = MODIFY_REFERENCE_REQUEST,
      method = {RequestMethod.POST})
  public void modifyREFERENCE(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam(value = "api", required = false) boolean api)
      throws IOException {

    if (apiRequested(response, api, MODIFY_REFERENCE_REQUEST)) return;

    com.c9a.buffers.CatalogServiceRequestProtocalBuffer.ModifyReferenceRequest
        modifyReferenceRequest =
            com.c9a.buffers.CatalogServiceRequestProtocalBuffer.ModifyReferenceRequest.parseFrom(
                GoogleProtoclBufferRequestContentUtils.getContentForRequest(request));

    try {
      Reference ref =
          catalogService.modifyReference(
              modifyReferenceRequest.getUserId(),
              modifyReferenceRequest.getPartitionId(),
              modifyReferenceRequest.getReferenceUniqueId(),
              modifyReferenceRequest.getReferenceName(),
              createPermissionListFromProtoBufEnumList(modifyReferenceRequest.getPermissionsList()),
              createNewMap(modifyReferenceRequest.getAttributesList()));

      CatalogGPBUtils.generateReferenceResponseProtoBuf(
              ref, com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode.SUCCESS, "")
          .build()
          .writeTo(response.getOutputStream());
      return;
    } catch (CollectionNotFoundException e) {
      CatalogGPBUtils.generateResponseProtoBuf(
              com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode
                  .COLLECTION_NOT_FOUND,
              "The collection can not be found with unique id : "
                  + modifyReferenceRequest.getParentCollectionUniqueId())
          .build()
          .writeTo(response.getOutputStream());
      return;
    } catch (ReferenceModificationException e) {
      CatalogGPBUtils.generateResponseProtoBuf(
              com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode
                  .REFERENCE_CAN_NOT_BE_MODIFIED,
              "You do not have the needed permissions to modify this reference.")
          .build()
          .writeTo(response.getOutputStream());
      return;
    } catch (ReferenceNotFoundException e) {
      CatalogGPBUtils.generateResponseProtoBuf(
              com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode.REFERENCE_NOT_FOUND,
              "The reference can not be found with unique id : "
                  + modifyReferenceRequest.getReferenceUniqueId())
          .build()
          .writeTo(response.getOutputStream());
      return;
    } catch (InvalidCatalogNameException e) {
      CatalogGPBUtils.generateResponseProtoBuf(
              com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode
                  .CATALOG_NAME_INVALID,
              "You can not store the name \""
                  + modifyReferenceRequest.getReferenceName()
                  + "\" int he catalog.")
          .build()
          .writeTo(response.getOutputStream());
      return;
    }
  }