@RequestMapping( value = ROOT_APPLICATION_COLLECTION_FOR_USER_REQUEST, method = {RequestMethod.POST}) public void rootApplicationCollectionRequest( HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "api", required = false) boolean api) throws IOException { if (apiRequested(response, api, ROOT_APPLICATION_COLLECTION_FOR_USER_REQUEST)) return; com.c9a.buffers.CatalogServiceRequestProtocalBuffer.GetRootApplicationCollectionForUserRequest rootApplicationCollectionForUserRequest = com.c9a.buffers.CatalogServiceRequestProtocalBuffer .GetRootApplicationCollectionForUserRequest.parseFrom( GoogleProtoclBufferRequestContentUtils.getContentForRequest(request)); CatalogCollection rootAplicationCollection = catalogService.getRootApplicationCollectionForUser( rootApplicationCollectionForUserRequest.getUserId(), rootApplicationCollectionForUserRequest.getPartitionId(), rootApplicationCollectionForUserRequest.getApplicationName()); CatalogGPBUtils.generateCatalogCollectionResponseProtoBuf( com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode.SUCCESS, "", rootAplicationCollection) .build() .writeTo(response.getOutputStream()); return; }
@RequestMapping( value = GET_COLLECTION_REQUEST, method = {RequestMethod.POST}) public void getCollection( HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "api", required = false) boolean api) throws IOException { if (apiRequested(response, api, GET_COLLECTION_REQUEST)) return; com.c9a.buffers.CatalogServiceRequestProtocalBuffer.GetCollectionRequest collectionRequest = com.c9a.buffers.CatalogServiceRequestProtocalBuffer.GetCollectionRequest.parseFrom( GoogleProtoclBufferRequestContentUtils.getContentForRequest(request)); try { CatalogCollection catalogCollection = catalogService.getCollection( collectionRequest.getUserId(), collectionRequest.getPartitionId(), collectionRequest.getUniqueId()); CatalogGPBUtils.generateCatalogCollectionResponseProtoBuf( com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode.SUCCESS, "", catalogCollection) .build() .writeTo(response.getOutputStream()); return; } catch (CollectionNotFoundException e) { CatalogGPBUtils.generateCatalogCollectionResponseProtoBufError( com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode .COLLECTION_NOT_FOUND, "The collection was not found with the give unique id : " + collectionRequest.getUniqueId()) .build() .writeTo(response.getOutputStream()); return; } }
@RequestMapping( value = MODIFY_COLLECTION_REQUEST, method = {RequestMethod.POST}) public void modifyCollection( HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "api", required = false) boolean api) throws IOException { if (apiRequested(response, api, MODIFY_COLLECTION_REQUEST)) return; com.c9a.buffers.CatalogServiceRequestProtocalBuffer.ModifyCatalogCollectionRequest modifyCollectionRequest = com.c9a.buffers.CatalogServiceRequestProtocalBuffer.ModifyCatalogCollectionRequest .parseFrom(GoogleProtoclBufferRequestContentUtils.getContentForRequest(request)); try { CatalogCollection catalogCollection = catalogService.modifyCollection( modifyCollectionRequest.getUserId(), modifyCollectionRequest.getPartitionId(), modifyCollectionRequest.getCollectionUniqueId(), modifyCollectionRequest.getCollectionName(), modifyCollectionRequest.getParentCollectionUniqueId(), createPermissionListFromProtoBufEnumList( modifyCollectionRequest.getPermissionsList()), createNewMap(modifyCollectionRequest.getAttributesList())); CatalogGPBUtils.generateCatalogCollectionResponseProtoBuf( com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode.SUCCESS, "", catalogCollection) .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 : " + modifyCollectionRequest.getCollectionUniqueId()) .build() .writeTo(response.getOutputStream()); return; } catch (CollectionModificationException e) { CatalogGPBUtils.generateResponseProtoBuf( com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode .COLLECTION_CAN_NOT_BE_MODIFIED, "You do not have the needed permissions to modify this collection.") .build() .writeTo(response.getOutputStream()); return; } catch (InvalidCatalogNameException e) { CatalogGPBUtils.generateResponseProtoBuf( com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode .CATALOG_NAME_INVALID, "You can not store the name \"" + modifyCollectionRequest.getCollectionName() + "\" in the catalog.") .build() .writeTo(response.getOutputStream()); return; } }
@RequestMapping( value = ADD_COLLECTION_REQUEST, method = {RequestMethod.POST}) public void addCollection( HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "api", required = false) boolean api) throws IOException { if (apiRequested(response, api, ADD_COLLECTION_REQUEST)) return; com.c9a.buffers.CatalogServiceRequestProtocalBuffer.AddCollectionRequest addNewCollectionRequest = com.c9a.buffers.CatalogServiceRequestProtocalBuffer.AddCollectionRequest.parseFrom( GoogleProtoclBufferRequestContentUtils.getContentForRequest(request)); try { Set<Long> permissions = createPermissionListFromProtoBufEnumList(addNewCollectionRequest.getPermissionsList()); Map<String, String> attributes = createNewMap(addNewCollectionRequest.getAttributesList()); CatalogCollection catalogCollection = catalogService.addCollection( addNewCollectionRequest.getUserId(), addNewCollectionRequest.getPartitionId(), addNewCollectionRequest.getCollectionName(), addNewCollectionRequest.getParentCatalogCollectionId(), permissions, attributes); CatalogGPBUtils.generateCatalogCollectionResponseProtoBuf( com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode.SUCCESS, "", catalogCollection) .build() .writeTo(response.getOutputStream()); return; } catch (CollectionNotFoundException e) { CatalogGPBUtils.generateCatalogCollectionResponseProtoBufError( com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode .COLLECTION_NOT_FOUND, "The parent collection was not found with the give unique id : " + addNewCollectionRequest.getParentCatalogCollectionId()) .build() .writeTo(response.getOutputStream()); return; } catch (CollectionModificationException e) { CatalogGPBUtils.generateCatalogCollectionResponseProtoBufError( com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode .COLLECTION_CAN_NOT_BE_MODIFIED, "The parent collection with unique id : " + addNewCollectionRequest.getParentCatalogCollectionId() + " can not be modified : ") .build() .writeTo(response.getOutputStream()); return; } catch (InvalidCatalogNameException e) { CatalogGPBUtils.generateCatalogCollectionResponseProtoBufError( com.c9a.buffers.CatalogServiceResponseProtocalBuffer.ResponseCode .CATALOG_NAME_INVALID, "The supplied name is not valid for the catalog") .build() .writeTo(response.getOutputStream()); return; } }