Example usage for com.fasterxml.jackson.databind.node ObjectNode put

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode put

Introduction

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

Prototype

public ObjectNode put(String paramString1, String paramString2) 

Source Link

Usage

From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java

private static ObjectNode createSlot(final ObjectMapper objectMapper, final Prototype prototype,
        final String slotName) {

    final ProtoSlot protoSlot = prototype.getProtoSlot(slotName);
    final SchemaLoader schemaLoader = prototype.getSchemaLoader();
    final Context context = schemaLoader.getContext();
    final SyntaxLoader syntaxLoader = context.getSyntaxLoader();

    final ValueType valueType = protoSlot.getValueType();
    if (valueType == ValueType.Link) {
        return null;
    }/*from w  w  w  . j  a  v a2  s .  c  om*/

    final Type heapValueType = protoSlot.getHeapValueType();

    final URI declaringSchemaUri = protoSlot.getDeclaringSchemaUri();

    final ObjectNode slotNode = objectMapper.createObjectNode();
    slotNode.put(PropertyName.name.name(), slotName);
    slotNode.put(PropertyName.title.name(), protoSlot.getTitle());
    slotNode.put(PropertyName.type.name(), valueType.name());
    slotNode.put(PropertyName.description.name(), protoSlot.getDescription());
    slotNode.put(PropertyName.declaringSchemaUri.name(), syntaxLoader.formatSyntaxValue(declaringSchemaUri));

    if (protoSlot instanceof PropertyProtoSlot) {
        final PropertyProtoSlot propertyProtoSlot = (PropertyProtoSlot) protoSlot;
        final Object defaultValue = propertyProtoSlot.getDefaultValue();
        if (defaultValue != null) {
            slotNode.put(PropertyName.defaultValue.name(), syntaxLoader.formatSyntaxValue(defaultValue));
        }
    }

    switch (valueType) {
    case Text: {

        final ObjectNode syntaxNode = buildSyntaxNode(objectMapper, heapValueType, syntaxLoader);
        slotNode.put(PropertyName.syntax.name(), syntaxNode);

        final PropertyProtoSlot textPropertyProtoSlot = (PropertyProtoSlot) protoSlot;
        final boolean isMultiline = textPropertyProtoSlot.isMultiline();
        if (isMultiline) {
            slotNode.put(PropertyName.multiline.name(), isMultiline);
        }

        break;
    }
    case List: {
        final PropertyProtoSlot listPropertyProtoSlot = (PropertyProtoSlot) protoSlot;

        final ObjectNode elementNode = objectMapper.createObjectNode();
        slotNode.put(PropertyName.element.name(), elementNode);

        final Type elementType = listPropertyProtoSlot.getListElementType();
        final ValueType elementValueType = schemaLoader.getValueType(elementType);
        elementNode.put(PropertyName.type.name(), elementValueType.name());

        if (elementValueType == ValueType.Model) {
            final URI elementSchemaUri = listPropertyProtoSlot.getListElementSchemaUri();
            if (elementSchemaUri != null) {
                final ObjectNode schemaNode = buildSchemaNode(objectMapper, elementSchemaUri, schemaLoader,
                        null);
                elementNode.put(PropertyName.schema.name(), schemaNode);
            }
        } else if (elementValueType == ValueType.Text) {
            final ObjectNode syntaxNode = buildSyntaxNode(objectMapper, elementType, syntaxLoader);
            elementNode.put(PropertyName.syntax.name(), syntaxNode);

        }

        break;
    }
    case Model: {
        final ObjectNode schemaNode = buildSchemaNode(objectMapper,
                ((PropertyProtoSlot) protoSlot).getModelSchemaUri(), schemaLoader, null);
        slotNode.put(PropertyName.schema.name(), schemaNode);
        break;
    }
    case SingleSelect: {
        final ObjectNode choicesNode = buildChoicesNode(objectMapper, heapValueType, schemaLoader);
        slotNode.put(PropertyName.choices.name(), choicesNode);
        break;
    }
    }

    return slotNode;
}

From source file:de.thingweb.desc.ThingDescriptionParser.java

public static ObjectNode toJsonObject(Thing thing) {

    ObjectNode td = factory.objectNode();
    if (thing.getMetadata().get("@context") == null
            || thing.getMetadata().get("@context").getNodeType() == JsonNodeType.NULL) {
        td.put("@context", factory.textNode(WOT_TD_CONTEXT));
    } else {//from   w w  w. j a  v a 2s . co  m
        td.put("@context", thing.getMetadata().get("@context"));
    }
    td.put("name", thing.getName());
    if (thing.getMetadata().contains("@type")) {
        td.put("@type", thing.getMetadata().get("@type"));
    }

    if (thing.getMetadata().contains("security")) {
        td.put("security", thing.getMetadata().get("security"));
    }

    if (thing.getMetadata().contains("encodings")) {
        // ArrayNode encodings = factory.arrayNode();
        // for (String e : thing.getMetadata().getAll("encodings")) {
        // encodings.add(e);
        // }
        td.put("encodings", thing.getMetadata().get("encodings"));
    }

    if (thing.getMetadata().contains("uris")) {
        //          ArrayNode uris = factory.arrayNode();
        //          for (JsonNode uri : thing.getMetadata().getAll("uris")) {
        //             uris.add(uri);
        //          }
        // // TODO array even if single value?
        // td.put("uris", uris);
        td.put("uris", thing.getMetadata().get("uris"));
    }

    ArrayNode properties = factory.arrayNode();
    for (Property prop : thing.getProperties()) {
        ObjectNode p = factory.objectNode();
        if (prop.getPropertyType() != null && prop.getPropertyType().length() > 0) {
            p.put("@type", prop.getPropertyType());
        }
        p.put("name", prop.getName());
        p.put("writable", prop.isWritable());
        p.put("valueType", prop.getValueType());

        if (prop.getHrefs().size() > 1) {
            ArrayNode hrefs = factory.arrayNode();
            for (String href : prop.getHrefs()) {
                hrefs.add(href);
            }
            p.put("hrefs", hrefs);
        } else if (prop.getHrefs().size() == 1) {
            p.put("hrefs", factory.textNode(prop.getHrefs().get(0)));
        }
        if (prop.getStability() != null) {
            p.put("stability", prop.getStability());
        }

        properties.add(p);
    }
    td.put("properties", properties);

    ArrayNode actions = factory.arrayNode();
    for (Action action : thing.getActions()) {
        ObjectNode a = factory.objectNode();
        if (action.getActionType() != null && action.getActionType().length() > 0) {
            a.put("@type", action.getActionType());
        }
        a.put("name", action.getName());

        if (action.getInputType() != null) {
            ObjectNode in = factory.objectNode();
            in.put("valueType", action.getInputType());
            a.put("inputData", in);
        }

        if (action.getOutputType() != null) {
            ObjectNode out = factory.objectNode();
            out.put("valueType", action.getOutputType());
            a.put("outputData", out);
        }

        if (action.getHrefs().size() > 1) {
            ArrayNode hrefs = factory.arrayNode();
            for (String href : action.getHrefs()) {
                hrefs.add(href);
            }
            a.put("hrefs", hrefs);
        } else if (action.getHrefs().size() == 1) {
            a.put("hrefs", factory.textNode(action.getHrefs().get(0)));
        }

        actions.add(a);
    }
    td.put("actions", actions);

    ArrayNode events = factory.arrayNode();
    for (Event event : thing.getEvents()) {
        ObjectNode a = factory.objectNode();
        if (event.getEventType() != null && event.getEventType().length() > 0) {
            a.put("@type", event.getEventType());
        }
        a.put("name", event.getName());

        if (event.getValueType() != null) {
            a.put("valueType", event.getValueType());
        }

        if (event.getHrefs().size() > 1) {
            ArrayNode hrefs = factory.arrayNode();
            for (String href : event.getHrefs()) {
                hrefs.add(href);
            }
            a.put("hrefs", hrefs);
        } else if (event.getHrefs().size() == 1) {
            a.put("hrefs", factory.textNode(event.getHrefs().get(0)));
        }

        events.add(a);
    }
    td.put("events", events);

    return td;
}

From source file:com.github.fge.jsonschema.servlets.SyntaxValidateServlet.java

@VisibleForTesting
static JsonNode buildResult(final String rawSchema) throws IOException, ProcessingException {
    final ObjectNode ret = JsonNodeFactory.instance.objectNode();

    final boolean invalidSchema = fillWithData(ret, Response.SCHEMA, Response.INVALID_SCHEMA, rawSchema);

    final JsonNode schemaNode = ret.remove(Response.SCHEMA);

    if (invalidSchema)
        return ret;

    final SchemaTree tree = new CanonicalSchemaTree(schemaNode);
    final SchemaHolder holder = new SchemaHolder(tree);
    final ListProcessingReport report = new ListProcessingReport();

    PROCESSOR.process(report, holder);//from  w  w  w.j  a v a2s.  c  o  m
    final boolean success = report.isSuccess();

    ret.put(Response.VALID, success);
    ret.put(Response.RESULTS, report.asJson());
    return ret;
}

From source file:json_cmp.Comparer.java

private static void changeMetaThumbnail(ObjectNode metaObj) {
    if (metaObj.hasNonNull("thumbnail")) {
        String[] temp;// w ww .j  a  v a 2 s.  c  o  m
        String thumbnail_str = metaObj.path("thumbnail").toString();
        temp = thumbnail_str.split("http:\\/\\/");
        if (temp.length == 2) {
            thumbnail_str = temp[temp.length - 1];
        } else {
            thumbnail_str = temp[temp.length - 1];
        }
        metaObj.put("thumbnail", thumbnail_str);
    } else
        metaObj.put("thumbnail", "");
}

From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java

public static ObjectNode buildSchemaNode(final ObjectMapper objectMapper, final URI schemaUri,
        final SchemaLoader schemaLoader, final Set<URI> addedBaseSchemaUris) {

    final Prototype prototype = schemaLoader.getPrototype(schemaUri);
    if (prototype == null) {
        return null;
    }/*from   w  ww.ja va2s.  com*/

    final ObjectNode schemaNode = objectMapper.createObjectNode();
    schemaNode.put(PropertyName.localName.name(), prototype.getUniqueName().getLocalName());
    schemaNode.put(PropertyName.title.name(), prototype.getTitle());
    schemaNode.put(PropertyName.uri.name(), schemaUri.toString());
    schemaNode.put(PropertyName.version.name(), prototype.getVersion());

    String titleSlotName = prototype.getTitleSlotName();
    if (StringUtils.isNotBlank(titleSlotName)) {
        schemaNode.put(PropertyName.titleSlotName.name(), titleSlotName);
    } else {
        titleSlotName = getTitleSlotName(schemaUri, schemaLoader);
        if (StringUtils.isNotBlank(titleSlotName)) {
            schemaNode.put(PropertyName.titleSlotName.name(), titleSlotName);
        }
    }

    final Set<String> allSlotNames = prototype.getAllSlotNames();
    if (allSlotNames != null && !allSlotNames.isEmpty()) {
        final ArrayNode propertyNamesNode = objectMapper.createArrayNode();

        for (final String slotName : allSlotNames) {
            final ProtoSlot protoSlot = prototype.getProtoSlot(slotName);
            if (protoSlot instanceof LinkProtoSlot) {
                continue;
            }

            if (protoSlot.getDeclaringSchemaUri().equals(schemaUri)) {
                propertyNamesNode.add(slotName);
            }
        }
        if (propertyNamesNode.size() > 0) {
            schemaNode.put(PropertyName.propertyNames.name(), propertyNamesNode);
        }
    }

    final Set<String> keySlotNames = prototype.getDeclaredKeySlotNames();
    if (keySlotNames != null && !keySlotNames.isEmpty()) {
        final ArrayNode keyPropertyNamesNode = objectMapper.createArrayNode();

        for (final String keySlotName : keySlotNames) {
            keyPropertyNamesNode.add(keySlotName);
        }

        if (keyPropertyNamesNode.size() > 0) {
            schemaNode.put(PropertyName.keyPropertyNames.name(), keyPropertyNamesNode);
        }
    }

    final Set<String> allKeySlotNames = prototype.getAllKeySlotNames();
    final ArrayNode allKeySlotNamesNode = objectMapper.createArrayNode();
    schemaNode.put(PropertyName.allKeySlotNames.name(), allKeySlotNamesNode);

    for (final String keySlotName : allKeySlotNames) {
        allKeySlotNamesNode.add(keySlotName);
    }

    final Set<String> comparablePropertyNames = prototype.getComparableSlotNames();
    if (comparablePropertyNames != null && !comparablePropertyNames.isEmpty()) {
        final ArrayNode comparablePropertyNamesNode = objectMapper.createArrayNode();

        for (final String comparablePropertyName : comparablePropertyNames) {
            comparablePropertyNamesNode.add(comparablePropertyName);
        }

        if (comparablePropertyNamesNode.size() > 0) {
            schemaNode.put(PropertyName.comparablePropertyNames.name(), comparablePropertyNamesNode);
        }
    }

    final Map<URI, LinkProtoSlot> linkProtoSlots = prototype.getLinkProtoSlots();
    if (linkProtoSlots != null && !linkProtoSlots.isEmpty()) {
        final ArrayNode linkNamesNode = objectMapper.createArrayNode();

        for (final LinkProtoSlot linkProtoSlot : linkProtoSlots.values()) {
            if (linkProtoSlot.getDeclaringSchemaUri().equals(schemaUri)) {
                linkNamesNode.add(linkProtoSlot.getName());
            }
        }

        if (linkNamesNode.size() > 0) {
            schemaNode.put(PropertyName.linkNames.name(), linkNamesNode);
        }
    }

    final Set<URI> declaredBaseSchemaUris = prototype.getDeclaredBaseSchemaUris();
    if (declaredBaseSchemaUris != null && !declaredBaseSchemaUris.isEmpty() && addedBaseSchemaUris != null) {

        final ArrayNode baseSchemasNode = objectMapper.createArrayNode();
        for (final URI baseSchemaUri : declaredBaseSchemaUris) {
            if (!addedBaseSchemaUris.contains(baseSchemaUri)) {
                final ObjectNode baseSchemaNode = buildSchemaNode(objectMapper, baseSchemaUri, schemaLoader,
                        addedBaseSchemaUris);
                baseSchemasNode.add(baseSchemaNode);
                addedBaseSchemaUris.add(baseSchemaUri);
            }
        }

        if (baseSchemasNode.size() > 0) {
            schemaNode.put(PropertyName.baseSchemas.name(), baseSchemasNode);
        }
    }

    return schemaNode;
}

From source file:mobile.service.RNSService.java

/**
 * //  w  ww. j av  a2  s  .  c om
 *
 * @param title      
 * @param industryId Id
 * @param info       ??
 * @param budget     ??8?1??
 * @param skillsTags 
 * @param attachs    Id??
 * @return
 */
public static ServiceVOResult<CommonVO> createRequire(String title, Long industryId, String info, String budget,
        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)?$", budget) && !"-1".equals(budget)) {
        return ServiceVOResult.error("100005", "??8?1??");
    }
    if (null != attachs && attachs.size() > 5) {
        return ServiceVOResult.error("1006", "??");
    }

    ObjectNode data = Json.newObject();
    data.put("title", title);
    data.put("info", info);
    data.put("budget", budget);
    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 = createOrUpdateRequire(data, objectNodeResult);
    if (!createResult.isSuccess()) {
        return ServiceVOResult.create(createResult);
    }

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

    return ServiceVOResult.success(vo);
}

From source file:dao.FlowsDAO.java

public static ObjectNode getPagedFlowsByProject(String applicationName, String project, int page, int size) {
    ObjectNode result;

    if (StringUtils.isBlank(applicationName) || StringUtils.isBlank(project)) {
        result = Json.newObject();/*from   w  w w. j av  a 2  s. c o  m*/
        result.put("count", 0);
        result.put("page", page);
        result.put("itemsPerPage", size);
        result.put("totalPages", 0);
        result.set("flows", Json.toJson(""));
        return result;
    }

    String application = applicationName.replace(".", " ");

    Integer appID = getApplicationIDByName(applicationName);
    if (appID != 0) {
        javax.sql.DataSource ds = getJdbcTemplate().getDataSource();
        DataSourceTransactionManager tm = new DataSourceTransactionManager(ds);
        TransactionTemplate txTemplate = new TransactionTemplate(tm);
        final int applicationID = appID;
        result = txTemplate.execute(new TransactionCallback<ObjectNode>() {
            public ObjectNode doInTransaction(TransactionStatus status) {
                ObjectNode resultNode = Json.newObject();
                long count = 0;
                List<Flow> pagedFlows = new ArrayList<Flow>();
                List<Map<String, Object>> rows = null;
                if (StringUtils.isNotBlank(project) && (!project.equalsIgnoreCase("root"))) {
                    rows = getJdbcTemplate().queryForList(GET_PAGED_FLOWS_BY_APP_ID_AND_PROJECT_NAME,
                            applicationID, project, (page - 1) * size, size);
                } else {
                    rows = getJdbcTemplate().queryForList(GET_PAGED_FLOWS_WITHOUT_PROJECT_BY_APP_ID,
                            applicationID, (page - 1) * size, size);
                }

                try {
                    count = getJdbcTemplate().queryForObject("SELECT FOUND_ROWS()", Long.class);
                } catch (EmptyResultDataAccessException e) {
                    Logger.error("Exception = " + e.getMessage());
                }
                for (Map row : rows) {
                    Flow flow = new Flow();
                    flow.id = (Long) row.get("flow_id");
                    flow.level = (Integer) row.get("flow_level");
                    flow.name = (String) row.get("flow_name");
                    flow.path = (String) row.get("flow_path");
                    flow.appCode = (String) row.get("app_code");
                    flow.group = project;
                    if (StringUtils.isNotBlank(flow.path)) {
                        int index = flow.path.indexOf(":");
                        if (index != -1) {
                            flow.path = flow.path.substring(0, index);
                        }
                    }
                    Object created = row.get("created_time");
                    if (created != null) {
                        flow.created = DateFormat.format(created.toString());
                    }
                    Object modified = row.get("modified_time");
                    if (modified != null) {
                        flow.modified = DateFormat.format(row.get("modified_time").toString());
                    }

                    int jobCount = 0;

                    if (flow.id != null && flow.id != 0) {
                        try {
                            jobCount = getJdbcTemplate().queryForObject(GET_JOB_COUNT_BY_APP_ID_AND_FLOW_ID,
                                    new Object[] { appID, flow.id }, Integer.class);
                            flow.jobCount = jobCount;
                        } catch (EmptyResultDataAccessException e) {
                            Logger.error("Exception = " + e.getMessage());
                        }
                    }
                    pagedFlows.add(flow);
                }
                resultNode.set("flows", Json.toJson(pagedFlows));
                resultNode.put("count", count);
                resultNode.put("page", page);
                resultNode.put("itemsPerPage", size);
                resultNode.put("totalPages", (int) Math.ceil(count / ((double) size)));

                return resultNode;
            }
        });
        return result;
    }

    result = Json.newObject();
    result.put("count", 0);
    result.put("page", page);
    result.put("itemsPerPage", size);
    result.put("totalPages", 0);
    result.set("flows", Json.toJson(""));
    return result;
}

From source file:mobile.service.RNSService.java

/**
 * ?//from   ww w.  java  2  s  .  c  om
 *
 * @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

/**
 * ?//from   w  w w  .  ja  va 2s.  c o  m
 *
 * @param serviceId ?Id
 * @param index     ??0
 * @return
 */
public static ServiceResult deleteServicePic(Long serviceId, List<Integer> index) {
    Service service = Service.queryServiceById(serviceId);
    if (null == service) {
        return ServiceResult.error("1008", "??");
    }
    if (!service.getOwner().getId().equals(MobileUtil.getCurrentUser().getId())) {
        return ServiceResult.error("1004", "???");
    }

    // ?Json
    Set<AttachOfService> caseAttachs = service.getCaseAttachs();
    ArrayNode attachArray = Json.newObject().arrayNode();
    int counter = 0;
    List<Long> deleteAttachIdList = new ArrayList<Long>();
    for (AttachOfService attachOfService : caseAttachs) {
        if (index.contains(counter)) {
            deleteAttachIdList.add(attachOfService.id);
        } else {
            ObjectNode attachNode = Json.newObject();
            attachNode.put("attachId", attachOfService.id);
            attachArray.add(attachNode);
        }

        counter++;
    }
    Attach.deleteByIds(deleteAttachIdList, AttachOfService.class);

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

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

    return ServiceResult.success();
}

From source file:mobile.service.RNSService.java

/**
 * /*from  w w w.j  ava  2  s  .c  om*/
 *
 * @param requireId Id
 * @param index     ??0
 * @return
 */
public static ServiceResult deleteRequireAttachment(Long requireId, List<Integer> index) {
    Require require = Require.queryRequireById(requireId);
    if (null == require) {
        return ServiceResult.error("1007", "?");
    }
    if (!require.getOwner().getId().equals(MobileUtil.getCurrentUser().getId())) {
        return ServiceResult.error("1003", "??");
    }

    Set<AttachOfRequire> caseAttachs = require.getCaseAttachs();

    // ?Json
    ArrayNode attachArray = Json.newObject().arrayNode();
    int counter = 0;
    List<Long> deleteAttachIdList = new ArrayList<Long>();
    for (AttachOfRequire attachOfService : caseAttachs) {
        if (index.contains(counter)) {
            deleteAttachIdList.add(attachOfService.id);
        } else {
            ObjectNode attachNode = Json.newObject();
            attachNode.put("attachId", attachOfService.id);
            attachArray.add(attachNode);
        }

        counter++;
    }
    Attach.deleteByIds(deleteAttachIdList, AttachOfRequire.class);

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

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

    return ServiceResult.success();
}