List of usage examples for com.fasterxml.jackson.databind.node ArrayNode size
public int size()
From source file:com.edp.service.product.BpmnJsonConverter.java
public BpmnModel convertToBpmnModel(JsonNode modelNode) { BpmnModel bpmnModel = new BpmnModel(); bpmnModel.setTargetNamespace("http://activiti.org/test"); Map<String, JsonNode> shapeMap = new HashMap<String, JsonNode>(); Map<String, JsonNode> sourceRefMap = new HashMap<String, JsonNode>(); Map<String, JsonNode> edgeMap = new HashMap<String, JsonNode>(); Map<String, List<JsonNode>> sourceAndTargetMap = new HashMap<String, List<JsonNode>>(); readShapeDI(modelNode, 0, 0, shapeMap, sourceRefMap, bpmnModel); filterAllEdges(modelNode, edgeMap, sourceAndTargetMap, shapeMap, sourceRefMap); readEdgeDI(edgeMap, sourceAndTargetMap, bpmnModel); ArrayNode shapesArrayNode = (ArrayNode) modelNode.get(EDITOR_CHILD_SHAPES); if ((shapesArrayNode == null) || (shapesArrayNode.size() == 0)) { return bpmnModel; }/* w ww. j a v a2 s . com*/ boolean nonEmptyPoolFound = false; Map<String, Lane> elementInLaneMap = new HashMap<String, Lane>(); // first create the pool structure for (JsonNode shapeNode : shapesArrayNode) { String stencilId = BpmnJsonConverterUtil.getStencilId(shapeNode); if (STENCIL_POOL.equals(stencilId)) { Pool pool = new Pool(); pool.setId(BpmnJsonConverterUtil.getElementId(shapeNode)); pool.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, shapeNode)); pool.setProcessRef(JsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, shapeNode)); pool.setExecutable( JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, shapeNode, true)); bpmnModel.getPools().add(pool); Process process = new Process(); process.setId(pool.getProcessRef()); process.setName(pool.getName()); process.setExecutable(pool.isExecutable()); bpmnModel.addProcess(process); ArrayNode laneArrayNode = (ArrayNode) shapeNode.get(EDITOR_CHILD_SHAPES); for (JsonNode laneNode : laneArrayNode) { // should be a lane, but just check to be certain String laneStencilId = BpmnJsonConverterUtil.getStencilId(laneNode); if (STENCIL_LANE.equals(laneStencilId)) { nonEmptyPoolFound = true; Lane lane = new Lane(); lane.setId(BpmnJsonConverterUtil.getElementId(laneNode)); lane.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, laneNode)); lane.setParentProcess(process); process.getLanes().add(lane); processJsonElements(laneNode.get(EDITOR_CHILD_SHAPES), modelNode, lane, shapeMap, bpmnModel); if (CollectionUtils.isNotEmpty(lane.getFlowReferences())) { for (String elementRef : lane.getFlowReferences()) { elementInLaneMap.put(elementRef, lane); } } } } } } // Signal Definitions exist on the root level JsonNode signalDefinitionNode = BpmnJsonConverterUtil.getProperty(PROPERTY_SIGNAL_DEFINITIONS, modelNode); signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode); signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode); // no idea why this needs to be done twice .. if (signalDefinitionNode != null) { if (signalDefinitionNode instanceof ArrayNode) { ArrayNode signalDefinitionArrayNode = (ArrayNode) signalDefinitionNode; Iterator<JsonNode> signalDefinitionIterator = signalDefinitionArrayNode.iterator(); while (signalDefinitionIterator.hasNext()) { JsonNode signalDefinitionJsonNode = signalDefinitionIterator.next(); String signalId = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_ID).asText(); String signalName = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_NAME).asText(); String signalScope = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_SCOPE).asText(); Signal signal = new Signal(); signal.setId(signalId); signal.setName(signalName); signal.setScope( (signalScope.toLowerCase().equals("processinstance")) ? Signal.SCOPE_PROCESS_INSTANCE : Signal.SCOPE_GLOBAL); bpmnModel.addSignal(signal); } } } if (nonEmptyPoolFound == false) { Process process = new Process(); bpmnModel.getProcesses().add(process); process.setId(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, modelNode)); process.setName(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, modelNode)); String namespace = BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_NAMESPACE, modelNode); if (StringUtils.isNotEmpty(namespace)) { bpmnModel.setTargetNamespace(namespace); } process.setDocumentation( BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_DOCUMENTATION, modelNode)); JsonNode processExecutableNode = JsonConverterUtil.getProperty(PROPERTY_PROCESS_EXECUTABLE, modelNode); if ((processExecutableNode != null) && StringUtils.isNotEmpty(processExecutableNode.asText())) { process.setExecutable( JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, modelNode)); } BpmnJsonConverterUtil.convertJsonToMessages(modelNode, bpmnModel); BpmnJsonConverterUtil.convertJsonToListeners(modelNode, process); JsonNode eventListenersNode = BpmnJsonConverterUtil.getProperty(PROPERTY_EVENT_LISTENERS, modelNode); if (eventListenersNode != null) { eventListenersNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(eventListenersNode); BpmnJsonConverterUtil.parseEventListeners(eventListenersNode.get(PROPERTY_EVENTLISTENER_VALUE), process); } JsonNode processDataPropertiesNode = modelNode.get(EDITOR_SHAPE_PROPERTIES) .get(PROPERTY_DATA_PROPERTIES); if (processDataPropertiesNode != null) { List<ValuedDataObject> dataObjects = BpmnJsonConverterUtil .convertJsonToDataProperties(processDataPropertiesNode, process); process.setDataObjects(dataObjects); process.getFlowElements().addAll(dataObjects); } processJsonElements(shapesArrayNode, modelNode, process, shapeMap, bpmnModel); } else { // sequence flows are on root level so need additional parsing for pools for (JsonNode shapeNode : shapesArrayNode) { if (STENCIL_SEQUENCE_FLOW.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode)) || STENCIL_ASSOCIATION.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode))) { String sourceRef = BpmnJsonConverterUtil.lookForSourceRef( shapeNode.get(EDITOR_SHAPE_ID).asText(), modelNode.get(EDITOR_CHILD_SHAPES)); if (sourceRef != null) { Lane lane = elementInLaneMap.get(sourceRef); SequenceFlowJsonConverter flowConverter = new SequenceFlowJsonConverter(); if (lane != null) { flowConverter.convertToBpmnModel(shapeNode, modelNode, this, lane, shapeMap, bpmnModel); } else { flowConverter.convertToBpmnModel(shapeNode, modelNode, this, bpmnModel.getProcesses().get(0), shapeMap, bpmnModel); } } } } } // sequence flows are now all on root level Map<String, SubProcess> subShapesMap = new HashMap<String, SubProcess>(); for (Process process : bpmnModel.getProcesses()) { for (FlowElement flowElement : process.findFlowElementsOfType(SubProcess.class)) { SubProcess subProcess = (SubProcess) flowElement; fillSubShapes(subShapesMap, subProcess); } if (subShapesMap.size() > 0) { List<String> removeSubFlowsList = new ArrayList<String>(); for (FlowElement flowElement : process.findFlowElementsOfType(SequenceFlow.class)) { SequenceFlow sequenceFlow = (SequenceFlow) flowElement; if (subShapesMap.containsKey(sequenceFlow.getSourceRef())) { SubProcess subProcess = subShapesMap.get(sequenceFlow.getSourceRef()); if (subProcess.getFlowElement(sequenceFlow.getId()) == null) { subProcess.addFlowElement(sequenceFlow); removeSubFlowsList.add(sequenceFlow.getId()); } } } for (String flowId : removeSubFlowsList) { process.removeFlowElement(flowId); } } } Map<String, FlowWithContainer> allFlowMap = new HashMap<String, FlowWithContainer>(); List<Gateway> gatewayWithOrderList = new ArrayList<Gateway>(); // post handling of process elements for (Process process : bpmnModel.getProcesses()) { postProcessElements(process, process.getFlowElements(), edgeMap, bpmnModel, allFlowMap, gatewayWithOrderList); } // sort the sequence flows for (Gateway gateway : gatewayWithOrderList) { List<ExtensionElement> orderList = gateway.getExtensionElements().get("EDITOR_FLOW_ORDER"); if (CollectionUtils.isNotEmpty(orderList)) { for (ExtensionElement orderElement : orderList) { String flowValue = orderElement.getElementText(); if (StringUtils.isNotEmpty(flowValue)) { if (allFlowMap.containsKey(flowValue)) { FlowWithContainer flowWithContainer = allFlowMap.get(flowValue); flowWithContainer.getFlowContainer() .removeFlowElement(flowWithContainer.getSequenceFlow().getId()); flowWithContainer.getFlowContainer() .addFlowElement(flowWithContainer.getSequenceFlow()); } } } } gateway.getExtensionElements().remove("EDITOR_FLOW_ORDER"); } return bpmnModel; }
From source file:org.activiti.editor.language.json.converter.BaseBpmnJsonConverter.java
protected void addFieldExtensions(List<FieldExtension> extensions, ObjectNode propertiesNode) { ObjectNode fieldExtensionsNode = objectMapper.createObjectNode(); ArrayNode itemsNode = objectMapper.createArrayNode(); for (FieldExtension extension : extensions) { ObjectNode propertyItemNode = objectMapper.createObjectNode(); propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_NAME, extension.getFieldName()); if (StringUtils.isNotEmpty(extension.getStringValue())) { propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_VALUE, extension.getStringValue()); }// w w w . j a v a 2 s . c om if (StringUtils.isNotEmpty(extension.getExpression())) { propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_EXPRESSION, extension.getExpression()); } itemsNode.add(propertyItemNode); } fieldExtensionsNode.put("totalCount", itemsNode.size()); fieldExtensionsNode.put(EDITOR_PROPERTIES_GENERAL_ITEMS, itemsNode); propertiesNode.put(PROPERTY_SERVICETASK_FIELDS, fieldExtensionsNode); }
From source file:de.jlo.talendcomp.json.JsonDocument.java
private JsonNode getNodeFromArray(JsonNode node, int arrayIndex, boolean allowMissing) throws Exception { if (node instanceof ArrayNode) { ArrayNode arrayNode = (ArrayNode) node; if (arrayIndex < arrayNode.size()) { return arrayNode.get(arrayIndex); } else if (allowMissing) { return null; } else {/*from w ww. ja va 2 s . c o m*/ throw new Exception( "Node: " + node + " has less elements than expected array index: " + arrayIndex); } } return node; }
From source file:org.activiti.editor.language.json.converter.UserTaskJsonConverter.java
@Override protected void convertElementToJson(ObjectNode propertiesNode, FlowElement flowElement) { UserTask userTask = (UserTask) flowElement; String assignee = userTask.getAssignee(); String candidateUsers = convertListToCommaSeparatedString(userTask.getCandidateUsers()); String candidateGroups = convertListToCommaSeparatedString(userTask.getCandidateGroups()); if (StringUtils.isNotEmpty(assignee) || StringUtils.isNotEmpty(candidateUsers) || StringUtils.isNotEmpty(candidateGroups)) { ObjectNode assignmentNode = objectMapper.createObjectNode(); ArrayNode itemsNode = objectMapper.createArrayNode(); if (StringUtils.isNotEmpty(assignee)) { ObjectNode assignmentItemNode = objectMapper.createObjectNode(); assignmentItemNode.put(PROPERTY_USERTASK_ASSIGNMENT_TYPE, PROPERTY_USERTASK_ASSIGNEE); assignmentItemNode.put(PROPERTY_USERTASK_ASSIGNMENT_EXPRESSION, assignee); itemsNode.add(assignmentItemNode); }//from w ww .jav a2 s. c o m if (StringUtils.isNotEmpty(candidateUsers)) { ObjectNode assignmentItemNode = objectMapper.createObjectNode(); assignmentItemNode.put(PROPERTY_USERTASK_ASSIGNMENT_TYPE, PROPERTY_USERTASK_CANDIDATE_USERS); assignmentItemNode.put(PROPERTY_USERTASK_ASSIGNMENT_EXPRESSION, candidateUsers); itemsNode.add(assignmentItemNode); } if (StringUtils.isNotEmpty(candidateGroups)) { ObjectNode assignmentItemNode = objectMapper.createObjectNode(); assignmentItemNode.put(PROPERTY_USERTASK_ASSIGNMENT_TYPE, PROPERTY_USERTASK_CANDIDATE_GROUPS); assignmentItemNode.put(PROPERTY_USERTASK_ASSIGNMENT_EXPRESSION, candidateGroups); itemsNode.add(assignmentItemNode); } assignmentNode.put("totalCount", itemsNode.size()); assignmentNode.put(EDITOR_PROPERTIES_GENERAL_ITEMS, itemsNode); propertiesNode.put(PROPERTY_USERTASK_ASSIGNMENT, assignmentNode); } if (userTask.getPriority() != null) { setPropertyValue(PROPERTY_PRIORITY, userTask.getPriority().toString(), propertiesNode); } setPropertyValue(PROPERTY_FORMKEY, userTask.getFormKey(), propertiesNode); setPropertyValue(PROPERTY_DUEDATE, userTask.getDueDate(), propertiesNode); setPropertyValue(PROPERTY_CATEGORY, userTask.getCategory(), propertiesNode); ; addFormProperties(userTask.getFormProperties(), propertiesNode); }
From source file:ai.general.net.wamp.WampConnection.java
/** * Internal unified publish method that accepts a URI topic path. * * The WAMP protocol distinguishes between a publish from a client and a server. Server messages * are published as WAMP events and client messages as WAMP publish messages. This method * combines the two mechanism by using the right WAMP type ID depending on connection context. * * This method adds the optional exclude_me, exclude and eligible parameters to the message. * The exclude_me parameter is only added if it is true. The exclude parameter is only added * if it is not null and exclude_me is false. The eligible parameter is only added if it is * not not. If the eligible parameter is specified, but both exclude_me is false and exclude * is null, this method adds an empty exclude array to the message to conform to the protocol. * * While this method does not strictly enforce it, the WAMP protocol does not support the * exclude_me, exclude and eligible parameters on the server side. So, on the server side * these values should be always set to false and null. * * @param topic_uri The topic URI to publish to. * @param data The data to publish./* w ww . j a va 2 s . co m*/ * @param exclude_me Optional value of exclude_me argument (only included if true). * @param exclude List of session ID's to exclude from the publish request or null. * @param eligible Explicit list of session ID's to include in the publish request or null. * @return True if the request was sent. */ private boolean publish(Uri topic_uri, Object data, boolean exclude_me, String[] exclude, String[] eligible) { ArrayNode request = json_mapper_.createArrayNode(); request.add(is_server_ ? kEvent : kPublish); request.add(topic_uri.toString()); request.addPOJO(data); if (exclude_me) { request.add(exclude_me); } else if (exclude != null) { request.addPOJO(exclude); } if (eligible != null) { if (request.size() < 4) { request.addPOJO(new String[] {}); } request.addPOJO(eligible); } try { return sender_.sendText(json_mapper_.writeValueAsString(request)); } catch (JsonProcessingException e) { return false; } }
From source file:org.apache.taverna.scufl2.translator.t2flow.t23activities.ExternalToolActivityParser.java
protected ObjectNode parseToolDescription(ObjectNode json, UsecaseDescription toolDesc, ParserState parserState) {/* ww w . j a va 2s .c o m*/ ObjectNode description = json.objectNode(); description.put("dc:title", toolDesc.getUsecaseid()); if (toolDesc.getGroup() != null) description.put("group", toolDesc.getGroup()); if (toolDesc.getDescription() != null) description.put("dc:description", toolDesc.getDescription()); description.put("command", toolDesc.getCommand()); description.put("preparingTimeoutInSeconds", toolDesc.getPreparingTimeoutInSeconds()); description.put("executionTimeoutInSeconds", toolDesc.getExecutionTimeoutInSeconds()); // Ignoring tags, REs, queue__preferred, queue__deny ArrayNode staticInputs = json.arrayNode(); // static inputs for (ScriptInputStatic inputStatic : toolDesc.getStaticInputs() .getDeUniLuebeckInbKnowarcUsecasesScriptInputStatic()) { ObjectNode input = json.objectNode(); staticInputs.add(input); input.put("tag", inputStatic.getTag()); input.put("file", inputStatic.isFile()); input.put("tempFile", inputStatic.isTempFile()); input.put("binary", inputStatic.isBinary()); input.put("charsetName", inputStatic.getCharsetName()); input.put("forceCopy", inputStatic.isForceCopy()); if (inputStatic.getUrl() != null) input.put("url", inputStatic.getUrl()); if (inputStatic.getContent() != null) input.put("content", inputStatic.getContent().getValue()); } if (staticInputs.size() > 0) json.put("staticInputs", staticInputs); // for (ScriptInputStatic inputStatic : toolDesc.getStaticInputs() // .getDeUniLuebeckInbKnowarcUsecasesScriptInputStatic()) { // String portName = inputStatic.getTag(); // PropertyResource staticInput = generatePortDefinition(portName, inputStatic.getTag(), // inputStatic.getCharsetName(), true, false, inputStatic.isBinary(), // inputStatic.isFile(), inputStatic.isTempFile(), inputStatic.isForceCopy(), // false, true, parserState); // // configResource.addProperty(ACTIVITY_URI.resolve("#staticInput"), staticInput); // if (inputStatic.getUrl() != null) { // staticInput.addPropertyReference(ACTIVITY_URI.resolve("#source"), // URI.create(inputStatic.getUrl())); // } else { // PropertyResource content = staticInput.addPropertyAsNewResource( // ACTIVITY_URI.resolve("#source"), CNT.resolve("#ContentAsText")); // content.addPropertyAsString(CNT.resolve("#chars"), inputStatic.getContent() // .getValue()); // // TODO: Support bytes? // } // } // Inputs ArrayNode inputs = json.arrayNode(); for (Entry entry : toolDesc.getInputs().getEntry()) { ObjectNode mapping = json.objectNode(); mapping.put("port", entry.getString()); ObjectNode input = json.objectNode(); mapping.put("input", input); ScriptInputUser scriptInput = entry.getDeUniLuebeckInbKnowarcUsecasesScriptInputUser(); input.put("tag", scriptInput.getTag()); input.put("file", scriptInput.isFile()); input.put("tempFile", scriptInput.isTempFile()); input.put("binary", scriptInput.isBinary()); input.put("charsetName", scriptInput.getCharsetName()); input.put("forceCopy", scriptInput.isForceCopy()); input.put("list", scriptInput.isList()); input.put("concatenate", scriptInput.isConcatenate()); } if (inputs.size() > 0) json.put("inputs", inputs); // for (Entry entry : toolDesc.getInputs().getEntry()) { // String portName = entry.getString(); // ScriptInputUser scriptInput = entry.getDeUniLuebeckInbKnowarcUsecasesScriptInputUser(); // PropertyResource portDef = generatePortDefinition(portName, scriptInput.getTag(), // scriptInput.getCharsetName(), true, scriptInput.isList(), // scriptInput.isBinary(), scriptInput.isFile(), scriptInput.isTempFile(), // scriptInput.isForceCopy(), scriptInput.isConcatenate(), false, parserState); // configResource.addProperty(Scufl2Tools.PORT_DEFINITION.resolve("#inputPortDefinition"), // portDef); // } // Outputs ArrayNode outputs = json.arrayNode(); for (Entry entry : toolDesc.getOutputs().getEntry()) { ObjectNode mapping = json.objectNode(); mapping.put("port", entry.getString()); ObjectNode output = json.objectNode(); mapping.put("output", output); ScriptOutput scriptOutput = entry.getDeUniLuebeckInbKnowarcUsecasesScriptOutput(); output.put("path", scriptOutput.getPath()); output.put("binary", scriptOutput.isBinary()); } if (outputs.size() > 0) json.put("outputs", outputs); // for (Entry entry : toolDesc.getOutputs().getEntry()) { // String portName = entry.getString(); // ScriptOutput scriptOutput = entry.getDeUniLuebeckInbKnowarcUsecasesScriptOutput(); // PropertyResource portDef = generatePortDefinition(portName, scriptOutput.getPath(), // null, false, false, scriptOutput.isBinary(), true, false, false, false, false, // parserState); // configResource.addProperty( // Scufl2Tools.PORT_DEFINITION.resolve("#outputPortDefinition"), portDef); // } json.put("includeStdIn", toolDesc.isIncludeStdIn()); json.put("includeStdOut", toolDesc.isIncludeStdOut()); json.put("includeStdErr", toolDesc.isIncludeStdErr()); // if (toolDesc.isIncludeStdIn()) { // InputActivityPort stdin = new InputActivityPort(parserState.getCurrentActivity(), STDIN); // stdin.setDepth(0); // } // if (toolDesc.isIncludeStdOut()) { // OutputActivityPort stdout = new OutputActivityPort(parserState.getCurrentActivity(), // STDOUT); // stdout.setDepth(0); // stdout.setGranularDepth(0); // } // if (toolDesc.isIncludeStdErr()) { // OutputActivityPort stderr = new OutputActivityPort(parserState.getCurrentActivity(), // STDERR); // stderr.setDepth(0); // stderr.setGranularDepth(0); // } return description; }
From source file:io.syndesis.maven.ExtractConnectorDescriptorsMojo.java
@Override @SuppressWarnings("PMD.EmptyCatchBlock") public void execute() throws MojoExecutionException, MojoFailureException { ArrayNode root = new ArrayNode(JsonNodeFactory.instance); URLClassLoader classLoader = null; try {//from ww w . java 2 s. c o m PluginDescriptor desc = (PluginDescriptor) getPluginContext().get("pluginDescriptor"); List<Artifact> artifacts = desc.getArtifacts(); ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest()); buildingRequest.setRemoteRepositories(remoteRepositories); for (Artifact artifact : artifacts) { ArtifactResult result = artifactResolver.resolveArtifact(buildingRequest, artifact); File jar = result.getArtifact().getFile(); classLoader = createClassLoader(jar); if (classLoader == null) { throw new IOException("Can not create classloader for " + jar); } ObjectNode entry = new ObjectNode(JsonNodeFactory.instance); addConnectorMeta(entry, classLoader); addComponentMeta(entry, classLoader); if (entry.size() > 0) { addGav(entry, artifact); root.add(entry); } } if (root.size() > 0) { saveCamelMetaData(root); } } catch (ArtifactResolverException | IOException e) { throw new MojoExecutionException(e.getMessage(), e); } finally { if (classLoader != null) { try { classLoader.close(); } catch (IOException ignored) { } } } }
From source file:lumbermill.internal.elasticsearch.ElasticSearchBulkResponse.java
List<JsonEvent> getRetryableItems(RequestSigner.SignableRequest request) { ArrayNode array = (ArrayNode) responseContents.get("items"); int pos = 0;/*from w w w. ja va 2 s . co m*/ int updatedCount = 0; for (JsonNode node : array) { JsonNode dataNode; if (node.has("create")) { dataNode = node.get("create"); } else if (node.has("index")) { dataNode = node.get("index"); } else { throw new IllegalStateException("Could not find field create or index in response"); } int statusCode = dataNode.get("status").asInt(); eventWithResponse.put(request.original().get(pos), new JsonEvent((ObjectNode) node)); if (statusCode != 200 && statusCode != 201 && statusCode != 202) { // No idea to retry if BAD_REQUEST, just skip and log them String err = dataNode.has("error") ? dataNode.get("error").asText() : "no error message"; if (statusCode == 400) { LOGGER.info("Will not retry event due to BAD_REQUEST:" + err); } else { LOGGER.debug("Bulk entry had errors, status: {}, error: {}", statusCode, err); retryableEvents.add(request.original().get(pos)); } } else { // Successful if (dataNode.get("_version").asInt() > 1) { updatedCount++; } } pos++; } if (!retryableEvents.isEmpty()) { LOGGER.debug("Bulk response contains {} failed items out of {}", retryableEvents.size(), array.size()); } if (updatedCount > 0) { LOGGER.debug("Bulk response contains {} document updates out of {}", updatedCount, array.size()); } return retryableEvents; }
From source file:org.activiti.editor.language.json.converter.BaseBpmnJsonConverter.java
protected void addListeners(List<ActivitiListener> listeners, boolean isExecutionListener, ObjectNode propertiesNode) {//from ww w . j av a2 s.c om String propertyName = null; String eventType = null; String listenerClass = null; String listenerExpression = null; String listenerDelegateExpression = null; if (isExecutionListener) { propertyName = PROPERTY_EXECUTION_LISTENERS; eventType = PROPERTY_EXECUTION_LISTENER_EVENT; listenerClass = PROPERTY_EXECUTION_LISTENER_CLASS; listenerExpression = PROPERTY_EXECUTION_LISTENER_EXPRESSION; listenerDelegateExpression = PROPERTY_EXECUTION_LISTENER_DELEGATEEXPRESSION; } else { propertyName = PROPERTY_TASK_LISTENERS; eventType = PROPERTY_TASK_LISTENER_EVENT; listenerClass = PROPERTY_TASK_LISTENER_CLASS; listenerExpression = PROPERTY_TASK_LISTENER_EXPRESSION; listenerDelegateExpression = PROPERTY_TASK_LISTENER_DELEGATEEXPRESSION; } ObjectNode listenersNode = objectMapper.createObjectNode(); ArrayNode itemsNode = objectMapper.createArrayNode(); for (ActivitiListener listener : listeners) { ObjectNode propertyItemNode = objectMapper.createObjectNode(); propertyItemNode.put(eventType, listener.getEvent()); if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(listener.getImplementationType())) { propertyItemNode.put(listenerClass, listener.getImplementation()); } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals(listener.getImplementationType())) { propertyItemNode.put(listenerExpression, listener.getImplementation()); } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION .equals(listener.getImplementationType())) { propertyItemNode.put(listenerDelegateExpression, listener.getImplementation()); } itemsNode.add(propertyItemNode); } listenersNode.put("totalCount", itemsNode.size()); listenersNode.put(EDITOR_PROPERTIES_GENERAL_ITEMS, itemsNode); propertiesNode.put(propertyName, listenersNode); }
From source file:com.redhat.lightblue.eval.ArrayAddExpressionEvaluator.java
@Override public boolean update(JsonDoc doc, FieldTreeNode contextMd, Path contextPath) { boolean ret = false; Path absPath = new Path(contextPath, arrayField); JsonNode node = doc.get(absPath);/*w w w . j a v a2 s. c o m*/ int insertTo = insertionIndex; if (node instanceof ArrayNode) { ArrayNode arrayNode = (ArrayNode) node; for (RValueData rvalueData : values) { LOGGER.debug("add element to {} rvalue:{}", absPath, rvalueData); Object newValue = null; Type newValueType = null; JsonNode newValueNode = null; if (rvalueData.refPath != null) { JsonNode refNode = doc.get(new Path(contextPath, rvalueData.refPath)); if (refNode != null) { newValueNode = refNode.deepCopy(); newValue = rvalueData.refType.fromJson(newValueNode); newValueType = rvalueData.refType; } } else if (rvalueData.value != null) { newValue = rvalueData.value.getValue(); newValueNode = fieldMd.getElement().getType().toJson(factory, newValue); newValueType = fieldMd.getElement().getType(); } else if (rvalueData.rvalueType == RValueExpression.RValueType._null) { newValueNode = factory.nullNode(); } else { newValueNode = factory.objectNode(); } LOGGER.debug("newValueType:{}, newValue:{}, newValueNode:{} ", newValueType, newValue, newValueNode); if (insertTo >= 0) { // If we're inserting, make sure we have that many elements while (arrayNode.size() < insertTo) { arrayNode.addNull(); } if (arrayNode.size() > insertTo) { arrayNode.insert(insertTo, newValueNode); } else { arrayNode.add(newValueNode); } insertTo++; } else { arrayNode.add(newValueNode); } ret = true; } if (ret) { // We have to rewrite the array indexes in arraySizeField using // the context path MutablePath p = new MutablePath(arraySizeField); p.rewriteIndexes(contextPath); LOGGER.debug("Setting {} = {}", p, arrayNode.size()); doc.modify(p, factory.numberNode(arrayNode.size()), false); } } return ret; }