Example usage for com.fasterxml.jackson.databind.node ArrayNode add

List of usage examples for com.fasterxml.jackson.databind.node ArrayNode add

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ArrayNode add.

Prototype

public ArrayNode add(JsonNode paramJsonNode) 

Source Link

Usage

From source file:mobile.service.RNSService.java

/**
 * ?/* w w  w.  j a  v a2  s .c  o m*/
 *
 * @param title      
 * @param industryId Id
 * @param info       ??
 * @param price      
 * @param skillsTags 
 * @param attachs    ?Id??
 * @return
 */
public static ServiceVOResult<CommonVO> createService(String title, Long industryId, String info, String price,
        List<String> skillsTags, List<Long> attachs) {
    if (StringUtils.isBlank(title)) {
        return ServiceVOResult.error("100005", "?");
    }
    SkillTag tag = SkillTag.getTagById(industryId);
    if (null == tag || tag.getTagType() != SkillTag.TagType.CATEGORY) {
        return ServiceVOResult.error("100005", "Id" + industryId);
    }
    if (!Pattern.matches("^\\d{0,8}(\\.\\d)?$", price) && !"-1".equals(price)) {
        return ServiceVOResult.error("100005", "??8?1??");
    }
    if (null != attachs && attachs.size() > 5) {
        return ServiceVOResult.error("1005", "???");
    }

    ObjectNode data = Json.newObject();
    data.put("title", title);
    data.put("info", info);
    data.put("price", price);
    data.put("industry", industryId);
    data.set("tags", Json.toJson(skillsTags));
    if (null != attachs) {
        ArrayNode attachsNode = Json.newObject().arrayNode();
        for (Long attachId : attachs) {
            ObjectNode attachNode = Json.newObject();
            attachNode.put("attachId", attachId);
            attachsNode.add(attachNode);
        }
        data.set("attachs", attachsNode);
    }

    ObjectNodeResult objectNodeResult = new ObjectNodeResult();
    ServiceResult createResult = createOrUpdateService(data, objectNodeResult);
    if (!createResult.isSuccess()) {
        return ServiceVOResult.create(createResult);
    }

    if (!objectNodeResult.isSuccess()) {
        if ("800002".equals(objectNodeResult.getErrorCode())) {
            return ServiceVOResult.error("1002", objectNodeResult.getError());
        }
        Logger.error(objectNodeResult.getObjectNode().toString());
        return ServiceVOResult.error("100001", "");
    }

    CommonVO vo = CommonVO.create();
    vo.set("serviceId", objectNodeResult.getObjectNode().path("serviceId").asLong(-1));

    return ServiceVOResult.success(vo);
}

From source file:mobile.service.RNSService.java

/**
 * /* w ww .  j a  va2 s  .  co  m*/
 *
 * @param requireId  Id
 * @param title      ?
 * @param industryId Id?
 * @param info       ??
 * @param budget     ?
 * @param skillsTags ?
 * @return
 */
public static ServiceResult updateRequire(Long requireId, String title, Long industryId, String info,
        String budget, List<String> skillsTags, List<Long> attachs) {
    if (null == requireId) {
        throw new IllegalArgumentException("requireId can not be null");
    }

    ObjectNode data = Json.newObject();
    data.put("id", requireId);

    if (null != title) {
        if (StringUtils.isBlank(title)) {
            return ServiceResult.error("100005", "?");
        } else {
            data.put("title", title);
        }
    }
    if (null != industryId) {
        SkillTag tag = SkillTag.getTagById(industryId);
        if (null == tag || tag.getTagType() != SkillTag.TagType.CATEGORY) {
            return ServiceResult.error("100005", "Id" + industryId);
        } else {
            data.put("industry", industryId);
        }
    }
    if (null != info) {
        data.put("info", info);
    }
    if (null != budget) {
        if (!Pattern.matches("^\\d{0,8}(\\.\\d)?$", budget) && !"-1".equals(budget)) {
            return ServiceResult.error("100005", "??8?1??");
        } else {
            data.put("budget", budget);
        }
    }
    if (null != skillsTags) {
        data.set("tags", Json.toJson(skillsTags));
    }
    if (null != attachs) {
        if (attachs.size() > 5) {
            return ServiceResult.error("1006", "??");
        }
        ArrayNode attachsNode = Json.newObject().arrayNode();
        for (Long attachId : attachs) {
            ObjectNode attachNode = Json.newObject();
            attachNode.put("attachId", attachId);
            attachsNode.add(attachNode);
        }
        data.set("attachs", attachsNode);
    }

    ServiceResult updateResult = createOrUpdateRequire(data, null);
    if (!updateResult.isSuccess()) {
        return updateResult;
    }

    return ServiceResult.success();
}

From source file:mobile.service.RNSService.java

/**
 * //  w  w  w.  j  a va 2 s. c  om
 *
 * @param serviceId  Id
 * @param title      
 * @param industryId Id
 * @param info       ??
 * @param budget     
 * @param skillsTags 
 * @return
 */
public static ServiceResult updateService(Long serviceId, String title, Long industryId, String info,
        String price, List<String> skillsTags, List<Long> attachs) {
    if (null == serviceId) {
        throw new IllegalArgumentException("serviceId can not be null");
    }

    ObjectNode data = Json.newObject();
    data.put("id", serviceId);

    if (null != title) {
        if (StringUtils.isBlank(title)) {
            return ServiceResult.error("100005", "?");
        } else {
            data.put("title", title);
        }
    }
    if (null != industryId) {
        SkillTag tag = SkillTag.getTagById(industryId);
        if (null == tag || tag.getTagType() != SkillTag.TagType.CATEGORY) {
            return ServiceResult.error("100005", "Id" + industryId);
        } else {
            data.put("industry", industryId);
        }
    }
    if (null != info) {
        data.put("info", info);
    }
    if (null != price) {
        if (!Pattern.matches("^\\d{0,8}(\\.\\d)?$", price) && !"-1".equals(price)) {
            return ServiceResult.error("100005", "??8?1??");
        } else {
            data.put("price", price);
        }
    }
    if (null != skillsTags) {
        data.set("tags", Json.toJson(skillsTags));
    }
    if (null != attachs) {
        if (attachs.size() > 5) {
            return ServiceResult.error("1005", "???");
        }
        ArrayNode attachsNode = Json.newObject().arrayNode();
        for (Long attachId : attachs) {
            ObjectNode attachNode = Json.newObject();
            attachNode.put("attachId", attachId);
            attachsNode.add(attachNode);
        }
        data.set("attachs", attachsNode);
    }

    ServiceResult updateResult = createOrUpdateService(data, null);
    if (!updateResult.isSuccess()) {
        return updateResult;
    }

    return ServiceResult.success();
}

From source file:com.joyent.manta.client.multipart.ServerSideMultipartManager.java

/**
 * Creates the JSON request body used to commit all of the parts of a multipart
 * upload request./*from   w  w  w .  java  2 s  . c  om*/
 *
 * @param parts stream of tuples - this is a terminal operation that will close the stream
 * @return byte array containing JSON data
 */
static ImmutablePair<byte[], Integer> createCommitRequestBody(
        final Stream<? extends MantaMultipartUploadTuple> parts) {
    final JsonNodeFactory nodeFactory = MantaObjectMapper.NODE_FACTORY_INSTANCE;
    final ObjectNode objectNode = new ObjectNode(nodeFactory);

    final ArrayNode partsArrayNode = new ArrayNode(nodeFactory);
    objectNode.set("parts", partsArrayNode);

    try (Stream<? extends MantaMultipartUploadTuple> sorted = parts.sorted()) {
        sorted.forEach(tuple -> partsArrayNode.add(tuple.getEtag()));
    }

    Validate.isTrue(partsArrayNode.size() > 0, "Can't commit multipart upload with no parts");

    try {
        return ImmutablePair.of(MantaObjectMapper.INSTANCE.writeValueAsBytes(objectNode),
                partsArrayNode.size());
    } catch (IOException e) {
        String msg = "Error serializing JSON for commit MPU request body";
        throw new MantaMultipartException(msg, e);
    }
}

From source file:mobile.service.RNSService.java

/**
 * ?/*from w  w  w  .j ava  2 s .com*/
 *
 * @param serviceId ?Id??Idnull???
 * @param file      ??5
 * @param pos       ?1 - 5
 * @return
 */
public static ServiceVOResult<CommonVO> uploadServicePic(Long serviceId, File file) {
    Service service = null;
    if (null != serviceId) {
        service = Service.queryServiceById(serviceId);
        if (null == service) {
            return ServiceVOResult.error("1008", "??");
        }
        if (!service.getOwner().getId().equals(MobileUtil.getCurrentUser().getId())) {
            return ServiceVOResult.error("1004", "???");
        }
        if (service.getCaseAttachs().size() >= 5) {
            return ServiceVOResult.error("1005", "???");
        }
    }

    ServiceVOResult<CommonVO> uploadResult = FileService.uploadAttatch(file, "mobile.jpg",
            FileService.AttatchType.SERVICE);
    if (!uploadResult.isSuccess()) {
        return ServiceVOResult.error(uploadResult.getErrorCode(), uploadResult.getErrorContent());
    }

    if (null != service) {
        synchronized (uploadServicePicLock) {
            JPA.em().refresh(service);
            Set<AttachOfService> caseAttachs = service.getCaseAttachs();
            if (caseAttachs.size() >= 5) {
                return ServiceVOResult.error("1005", "???");
            }

            // ?Json
            ArrayNode attachArray = Json.newObject().arrayNode();
            for (AttachOfService attachOfService : caseAttachs) {
                ObjectNode attachNode = Json.newObject();
                attachNode.put("attachId", attachOfService.id);
                attachArray.add(attachNode);
            }
            ObjectNode attachNode = Json.newObject();
            attachNode.put("attachId", uploadResult.getVo().getLong("attachId"));
            attachArray.add(attachNode);

            ObjectNode data = Json.newObject();
            data.put("id", serviceId);
            data.set("attachs", attachArray);

            ServiceResult updateResult = createOrUpdateService(data, null);
            if (!updateResult.isSuccess()) {
                return ServiceVOResult.create(updateResult);
            }
        }
    }

    CommonVO vo = CommonVO.create();
    vo.set("url", uploadResult.getVo().getString("url"));
    vo.set("attachId", uploadResult.getVo().getLong("attachId"));

    return ServiceVOResult.success(vo);
}

From source file:mobile.service.RNSService.java

/**
 * /*from  w ww  .  jav a2  s  .  c  o m*/
 *
 * @param requireId Id
 * @param file      
 * @param filename  ??
 * @return
 */
public static ServiceVOResult<CommonVO> updateRequireAttachment(Long requireId, File file, String filename) {
    if (StringUtils.isBlank(filename)) {
        throw new IllegalArgumentException("filename can not be blank.");
    }

    Require require = null;
    if (null != requireId) {
        require = Require.queryRequireById(requireId);
        if (null == require) {
            return ServiceVOResult.error("1007", "?");
        }
        if (!require.getOwner().getId().equals(MobileUtil.getCurrentUser().getId())) {
            return ServiceVOResult.error("1003", "??");
        }
        if (require.getCaseAttachs().size() >= 5) {
            return ServiceVOResult.error("1006", "??");
        }
    }

    ServiceVOResult<CommonVO> uploadResult = FileService.uploadAttatch(file, filename,
            FileService.AttatchType.REQUIRE);
    if (!uploadResult.isSuccess()) {
        return ServiceVOResult.error(uploadResult.getErrorCode(), uploadResult.getErrorContent());
    }

    if (null != require) {
        synchronized (updateRequireAttachmentLock) {
            JPA.em().refresh(require);

            Set<AttachOfRequire> caseAttachs = require.getCaseAttachs();
            if (caseAttachs.size() >= 5) {
                return ServiceVOResult.error("1006", "??");
            }

            // ?Json
            ArrayNode attachArray = Json.newObject().arrayNode();
            for (AttachOfRequire attachOfRequire : caseAttachs) {
                ObjectNode attachNode = Json.newObject();
                attachNode.put("attachId", attachOfRequire.id);
                attachArray.add(attachNode);
            }
            ObjectNode attachNode = Json.newObject();
            attachNode.put("attachId", uploadResult.getVo().getLong("attachId"));
            attachArray.add(attachNode);

            ObjectNode data = Json.newObject();
            data.put("id", requireId);
            data.set("attachs", attachArray);

            ServiceResult updateResult = createOrUpdateRequire(data, null);
            if (!updateResult.isSuccess()) {
                return ServiceVOResult.create(updateResult);
            }

        }
    }

    CommonVO vo = CommonVO.create();
    vo.set("url", uploadResult.getVo().getString("url"));
    vo.set("attachId", uploadResult.getVo().getLong("attachId"));

    return ServiceVOResult.success(vo);
}

From source file:com.zero_x_baadf00d.partialize.converter.DefaultConverter.java

@Override
public void convert(final String fieldName, final Object data, final ArrayNode node) {
    node.add(data.toString());
}

From source file:com.collective.celos.servlet.JSONWorkflowListServletTest.java

@Test
public void jsonCorrectlyProduced() throws Exception {
    WorkflowConfiguration cfg = WorkflowConfigurationParserTest.parseDir("json-workflow-list-servlet-test");
    ArrayNode list = Util.MAPPER.createArrayNode();
    list.add(new String("workflow-1"));
    list.add(new String("workflow-2"));
    ObjectNode obj = Util.MAPPER.createObjectNode();
    obj.put("ids", list);
    Assert.assertEquals(obj, new JSONWorkflowListServlet().createJSONObject(cfg));
}

From source file:com.redhat.lightblue.query.ArrayRangeProjection.java

@Override
public JsonNode toJson() {
    ArrayNode arr = getFactory().arrayNode();
    arr.add(getFactory().numberNode(from)).add(getFactory().numberNode(to));
    return ((ObjectNode) super.toJson()).set("range", arr);
}

From source file:com.evrythng.java.wrapper.mapping.ActionsDeserializer.java

@Override
public Actions deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {

    ObjectMapper mapper = JSONUtils.OBJECT_MAPPER;
    JsonNode node = mapper.readTree(jp);
    if (node.isArray()) {
        return mapper.readValue(node.toString(), ActionsImpl.class);
    } else {//ww w  . j  a v  a2  s  .  c o m
        ArrayNode array = mapper.createArrayNode();
        array.add(node);
        return mapper.readValue(array.toString(), ActionsImpl.class);
    }
}