Пример #1
0
 @POST
 @Path("/create/product")
 @Produces(MediaType.APPLICATION_JSON)
 @ApiOperation(
     value = "Creates a product Metdata object and store in database",
     notes = "Created by: Roberto Mejia",
     response = Metadata.class)
 @ApiResponses(
     value = {
       @ApiResponse(code = 200, message = "Able to store metadata class in database"),
       @ApiResponse(code = 500, message = "Unable to store in database")
     })
 public Response createProductMetadata() {
   /*Create metadata for Product class using metadata class*/
   Metadata meta = new Metadata(Product.class);
   /*Get repo from application context and store the generic metadata for product.
    * Note can edit by getting the ArrayList<HashMap> if needed.*/
   try {
     ApplicationContext ctx = new AnnotationConfigApplicationContext(MongoConfig.class);
     MetadataRepo repo = (MetadataRepo) ctx.getBean(MetadataRepo.class);
     repo.save(meta);
     return Response.status(201).entity(meta).build();
   } catch (Exception e) {
     e.printStackTrace();
     return Response.status(500).build();
   }
 }
Пример #2
0
 @GET
 @Path("/product")
 @Produces(MediaType.APPLICATION_JSON)
 @ApiOperation(
     value = "Get product metadata from metadataa collection",
     notes = "Created by: Roberto Mejia",
     response = Metadata.class)
 @ApiResponses(
     value = {
       @ApiResponse(code = 200, message = "Able to get product metadata"),
       @ApiResponse(code = 500, message = "Unable to get product metadata")
     })
 public Response getProductMetadata() {
   /*Get repo from application context and get metadata for farm. */
   ApplicationContext ctx = new AnnotationConfigApplicationContext(MongoConfig.class);
   MetadataRepo repo = (MetadataRepo) ctx.getBean(MetadataRepo.class);
   try {
     Metadata meta = repo.findByTitle("Product");
     return Response.status(200).entity(meta).build();
   } catch (Exception e) {
     e.printStackTrace();
     return Response.status(500).build();
   }
 }