Example usage for com.fasterxml.jackson.databind MappingJsonFactory createJsonParser

List of usage examples for com.fasterxml.jackson.databind MappingJsonFactory createJsonParser

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind MappingJsonFactory createJsonParser.

Prototype

@Deprecated
public JsonParser createJsonParser(File f) throws IOException, JsonParseException 

Source Link

Document

Method for constructing JSON parser instance to parse contents of specified file.

Usage

From source file:portal.api.PortalRepositoryIT.java

public List<PortalUser> getUsers() throws Exception {

    logger.info("Executing TEST = testGetUsers");

    Response r = execGETonURL(endpointUrl + "/services/api/repo/admin/users", cookieJSESSIONID);
    assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());

    String portalAPIVersionListHeaders = (String) r.getHeaders().getFirst("X-Portal-API-Version");
    assertEquals("1.0.0", portalAPIVersionListHeaders);

    MappingJsonFactory factory = new MappingJsonFactory();
    JsonParser parser = factory.createJsonParser((InputStream) r.getEntity());

    JsonNode node = parser.readValueAsTree();
    ObjectMapper mapper = new ObjectMapper();
    TypeReference<List<PortalUser>> typeRef = new TypeReference<List<PortalUser>>() {
    };//from  w  w  w.j a  v a2  s  .c  o m
    List<PortalUser> portalUsersList = mapper.readValue(node.traverse(), typeRef);
    for (PortalUser f : portalUsersList) {
        logger.info("user = " + f.getName() + ", ID = " + f.getId());
    }

    return portalUsersList;
}

From source file:portal.api.repo.PortalRepositoryAPIImpl.java

@POST
@Path("/admin/vxfs/")
@Consumes("multipart/form-data")
public Response addVxFMetadata(List<Attachment> ats) {

    PortalUser u = portalRepositoryRef.getUserBySessionID(ws.getHttpServletRequest().getSession().getId());

    if (u == null) {
        ResponseBuilder builder = Response.status(Status.NOT_FOUND);
        builder.entity("User not found in portal registry or not logged in ");
        throw new WebApplicationException(builder.build());
    }/*from  w w  w  .j  a  v a 2 s .  c om*/

    VxFMetadata vxf = new VxFMetadata();

    try {
        MappingJsonFactory factory = new MappingJsonFactory();
        JsonParser parser = factory.createJsonParser(getAttachmentStringValue("vxf", ats));
        vxf = parser.readValueAs(VxFMetadata.class);

        logger.info("Received @POST for vxf : " + vxf.getName());
        logger.info("Received @POST for vxf.extensions : " + vxf.getExtensions());

    } catch (JsonProcessingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    vxf = (VxFMetadata) addNewProductData(vxf,

            getAttachmentByName("prodIcon", ats), getAttachmentByName("prodFile", ats),
            getListOfAttachmentsByName("screenshots", ats));

    if (vxf != null) {
        return Response.ok().entity(vxf).build();
    } else {
        ResponseBuilder builder = Response.status(Status.INTERNAL_SERVER_ERROR);
        builder.entity("Requested entity cannot be installed");
        throw new WebApplicationException(builder.build());
    }

}

From source file:portal.api.repo.PortalRepositoryAPIImpl.java

@PUT
@Path("/admin/vxfs/{bid}")
@Consumes("multipart/form-data")
public Response updateVxFMetadata(@PathParam("bid") int bid, List<Attachment> ats) {

    VxFMetadata vxf = new VxFMetadata();

    try {/*  w ww. java 2  s  .c o m*/
        MappingJsonFactory factory = new MappingJsonFactory();
        JsonParser parser = factory.createJsonParser(getAttachmentStringValue("vxf", ats));
        vxf = parser.readValueAs(VxFMetadata.class);

        logger.info("Received @POST for vxf : " + vxf.getName());
        logger.info("Received @POST for vxf.extensions : " + vxf.getExtensions());

    } catch (JsonProcessingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // VxFMetadata sm = (VxFMetadata)
    // portalRepositoryRef.getProductByID(bid);

    for (VxFOnBoardedDescriptor vxFOnBoardedDescriptor : vxf.getVxfOnBoardedDescriptors()) {
        vxFOnBoardedDescriptor.setVxf(vxf);
    }

    vxf = (VxFMetadata) updateProductMetadata(vxf, getAttachmentByName("prodIcon", ats),
            getAttachmentByName("prodFile", ats), getListOfAttachmentsByName("screenshots", ats));

    return Response.ok().entity(vxf).build();

}

From source file:portal.api.repo.PortalRepositoryAPIImpl.java

@POST
@Path("/admin/experiments/")
@Consumes("multipart/form-data")
public Response addExperimentMetadata(List<Attachment> ats) {

    PortalUser u = portalRepositoryRef.getUserBySessionID(ws.getHttpServletRequest().getSession().getId());

    if (u == null) {
        ResponseBuilder builder = Response.status(Status.NOT_FOUND);
        builder.entity("User not found in portal registry or not logged in ");
        throw new WebApplicationException(builder.build());
    }//from  w  w w .  j  a va 2  s.  co  m

    ExperimentMetadata experiment = new ExperimentMetadata();

    try {
        MappingJsonFactory factory = new MappingJsonFactory();
        JsonParser parser = factory.createJsonParser(getAttachmentStringValue("exprm", ats));
        experiment = parser.readValueAs(ExperimentMetadata.class);

        logger.info("Received @POST for experiment : " + experiment.getName());

    } catch (JsonProcessingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // ExperimentMetadata sm = new ExperimentMetadata();
    experiment = (ExperimentMetadata) addNewProductData(experiment, getAttachmentByName("prodIcon", ats),
            getAttachmentByName("prodFile", ats), getListOfAttachmentsByName("screenshots", ats));
    if (experiment != null) {
        return Response.ok().entity(experiment).build();
    } else {
        ResponseBuilder builder = Response.status(Status.INTERNAL_SERVER_ERROR);
        builder.entity("Requested entity cannot be installed");
        throw new WebApplicationException(builder.build());
    }

}

From source file:portal.api.repo.PortalRepositoryAPIImpl.java

@PUT
@Path("/admin/experiments/{aid}")
@Consumes("multipart/form-data")
public Response updateAppMetadata(@PathParam("aid") int aid, List<Attachment> ats) {

    ExperimentMetadata appmeta = new ExperimentMetadata();

    try {//w  ww.ja  va  2  s.  c o m
        MappingJsonFactory factory = new MappingJsonFactory();
        JsonParser parser = factory.createJsonParser(getAttachmentStringValue("exprm", ats));
        appmeta = parser.readValueAs(ExperimentMetadata.class);

        logger.info("Received @POST for experiment : " + appmeta.getName());
        // logger.info("Received @POST for app.containers : " +
        // appmeta.getContainers().size());

    } catch (JsonProcessingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // ExperimentMetadata appmeta = (ExperimentMetadata)
    // portalRepositoryRef.getProductByID(aid);

    for (ExperimentOnBoardDescriptor veDescriptor : appmeta.getExperimentOnBoardDescriptors()) {
        veDescriptor.setExperiment(appmeta);
    }

    appmeta = (ExperimentMetadata) updateProductMetadata(appmeta, getAttachmentByName("prodIcon", ats),
            getAttachmentByName("prodFile", ats), getListOfAttachmentsByName("screenshots", ats));

    return Response.ok().entity(appmeta).build();
}