/** Unit test to check for regression of [JACKSON-18]. */ public void testSmallNumbers() throws Exception { ObjectMapper mapper = new ObjectMapper(); ArrayNode root = mapper.createArrayNode(); for (int i = -20; i <= 20; ++i) { JsonNode n = root.numberNode(i); root.add(n); // Hmmh. Not sure why toString() won't be triggered otherwise... assertEquals(String.valueOf(i), n.toString()); } // Loop over 2 different serialization methods for (int type = 0; type < 2; ++type) { StringWriter sw = new StringWriter(); if (type == 0) { JsonGenerator gen = new JsonFactory().createGenerator(sw); root.serialize(gen, null); gen.close(); } else { mapper.writeValue(sw, root); } String doc = sw.toString(); JsonParser p = new JsonFactory().createParser(new StringReader(doc)); assertEquals(JsonToken.START_ARRAY, p.nextToken()); for (int i = -20; i <= 20; ++i) { assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken()); assertEquals(i, p.getIntValue()); assertEquals("" + i, p.getText()); } assertEquals(JsonToken.END_ARRAY, p.nextToken()); p.close(); } }
// Processes parameters of javaMethod and enters the proper key-values into the methodNode private void processParameters(JavaMethod javaMethod, ObjectNode methodNode) { ArrayNode parameters = mapper.createArrayNode(); methodNode.set("parameters", parameters); boolean required = true; for (JavaParameter javaParameter : javaMethod.getParameters()) { ObjectNode individualParameterNode = mapper.createObjectNode(); Optional<JavaAnnotation> optional = javaParameter .getAnnotations() .stream() .filter( annotation -> annotation.getType().getName().equals(PATH_PARAM) || annotation.getType().getName().equals(QUERY_PARAM)) .findAny(); JavaAnnotation pathType = optional.isPresent() ? optional.get() : null; String annotationName = javaParameter.getName(); if (pathType != null) { // the parameter is a path or query parameter individualParameterNode.put( "name", pathType.getNamedParameter("value").toString().replace("\"", "")); if (pathType.getType().getName().equals(PATH_PARAM)) { individualParameterNode.put("in", "path"); } else if (pathType.getType().getName().equals(QUERY_PARAM)) { individualParameterNode.put("in", "query"); } individualParameterNode.put("type", getType(javaParameter.getType())); } else { // the parameter is a body parameter individualParameterNode.put("name", annotationName); individualParameterNode.put("in", "body"); // TODO add actual hardcoded schemas and a type // body parameters must have a schema associated with them ArrayNode schema = mapper.createArrayNode(); individualParameterNode.set("schema", schema); } for (DocletTag p : javaMethod.getTagsByName("param")) { if (p.getValue().contains(annotationName)) { try { String description = p.getValue().split(" ", 2)[1].trim(); if (description.contains("optional")) { required = false; } individualParameterNode.put("description", description); } catch (Exception e) { e.printStackTrace(); } } } individualParameterNode.put("required", required); parameters.add(individualParameterNode); } }
public JsonNode toObjectArray(ObjectMapper mapper) throws WampError { ArrayNode messageNode = mapper.createArrayNode(); messageNode.add(ID); messageNode.add(requestId); if (details != null) messageNode.add(details); else messageNode.add(mapper.createObjectNode()); if (arguments != null) messageNode.add(arguments); else if (argumentsKw != null) messageNode.add(mapper.createArrayNode()); if (argumentsKw != null) messageNode.add(argumentsKw); return messageNode; }
protected void createDataAssociation( DataAssociation dataAssociation, boolean incoming, Activity activity) { String sourceRef = null; String targetRef = null; if (incoming) { sourceRef = dataAssociation.getSourceRef(); targetRef = activity.getId(); } else { sourceRef = activity.getId(); targetRef = dataAssociation.getTargetRef(); } ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape( dataAssociation.getId(), STENCIL_DATA_ASSOCIATION, 172, 212, 128, 212); ArrayNode dockersArrayNode = objectMapper.createArrayNode(); ObjectNode dockNode = objectMapper.createObjectNode(); dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(sourceRef).getWidth() / 2.0); dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(sourceRef).getHeight() / 2.0); dockersArrayNode.add(dockNode); if (model.getFlowLocationGraphicInfo(dataAssociation.getId()).size() > 2) { for (int i = 1; i < model.getFlowLocationGraphicInfo(dataAssociation.getId()).size() - 1; i++) { GraphicInfo graphicInfo = model.getFlowLocationGraphicInfo(dataAssociation.getId()).get(i); dockNode = objectMapper.createObjectNode(); dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX()); dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY()); dockersArrayNode.add(dockNode); } } dockNode = objectMapper.createObjectNode(); dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(targetRef).getWidth() / 2.0); dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(targetRef).getHeight() / 2.0); dockersArrayNode.add(dockNode); flowNode.put("dockers", dockersArrayNode); ArrayNode outgoingArrayNode = objectMapper.createArrayNode(); outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(targetRef)); flowNode.put("outgoing", outgoingArrayNode); flowNode.put("target", BpmnJsonConverterUtil.createResourceNode(targetRef)); ObjectNode propertiesNode = objectMapper.createObjectNode(); propertiesNode.put(PROPERTY_OVERRIDE_ID, dataAssociation.getId()); flowNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode); shapesArrayNode.add(flowNode); }
public JsonNode toObjectArray(ObjectMapper mapper) throws WampError { ArrayNode messageNode = mapper.createArrayNode(); if (details != null) messageNode.add(details); else messageNode.add(mapper.createObjectNode()); messageNode.add(reason.toString()); return messageNode; }
public void testFromArray() throws Exception { ObjectMapper mapper = new ObjectMapper(); ArrayNode root = mapper.createArrayNode(); root.add(TEXT1); root.add(3); ObjectNode obj = root.addObject(); obj.put(FIELD1, true); obj.putArray(FIELD2); root.add(false); /* Ok, ready... let's serialize using one of two alternate * methods: first preferred (using generator) * (there are 2 variants here too) */ for (int i = 0; i < 2; ++i) { StringWriter sw = new StringWriter(); if (i == 0) { JsonGenerator gen = new JsonFactory().createGenerator(sw); root.serialize(gen, null); gen.close(); } else { mapper.writeValue(sw, root); } verifyFromArray(sw.toString()); } // And then convenient but less efficient alternative: verifyFromArray(root.toString()); }
// Checks whether javaClass has a path tag associated with it and if it does // processes its methods and creates a tag for the class on the root void processClass(JavaClass javaClass, ObjectNode paths, ArrayNode tags) { // If the class does not have a Path tag then ignore it JavaAnnotation annotation = getPathAnnotation(javaClass); if (annotation == null) { return; } String path = getPath(annotation); if (path == null) { return; } String resourcePath = "/" + path; String tagPath = path.isEmpty() ? "/" : path; // Create tag node for this class. ObjectNode tagObject = mapper.createObjectNode(); tagObject.put("name", tagPath); if (javaClass.getComment() != null) { tagObject.put("description", shortText(javaClass.getComment())); } tags.add(tagObject); // Create an array node add to all methods from this class. ArrayNode tagArray = mapper.createArrayNode(); tagArray.add(tagPath); processAllMethods(javaClass, resourcePath, paths, tagArray); }
/** * Converts partition info into a JSON object. * * @param partitionInfo partition descriptions */ private JsonNode json(List<PartitionInfo> partitionInfo) { ObjectMapper mapper = new ObjectMapper(); ArrayNode partitions = mapper.createArrayNode(); // Create a JSON node for each partition partitionInfo .stream() .forEach( info -> { ObjectNode partition = mapper.createObjectNode(); // Add each member to the "members" array for this partition ArrayNode members = partition.putArray("members"); info.members().stream().forEach(members::add); // Complete the partition attributes and add it to the array partition .put("name", info.name()) .put("term", info.term()) .put("leader", info.leader()); partitions.add(partition); }); return partitions; }
public JsonNode toObjectArray(ObjectMapper mapper) throws WampError { ArrayNode messageNode = mapper.createArrayNode(); messageNode.add(ID); messageNode.add(requestId); messageNode.add(registrationId); return messageNode; }
@Test public void testLoadTwoRootObjectsWithNoType() throws JsonProcessingException { JsonNode data = mapper .createArrayNode() .add( mapper.createObjectNode().put("userId", "1").put("name", "Paul").put("sex", "MALE")) .add( mapper .createObjectNode() .put("userId", "2") .put("name", "Anna") .put("sex", "FEMALE")); Resource result = mapper .reader() .withAttribute(RESOURCE_SET, resourceSet) .withAttribute(ROOT_ELEMENT, ModelPackage.Literals.USER) .treeToValue(data, Resource.class); assertNotNull(result); assertEquals(2, result.getContents().size()); User first = (User) result.getContents().get(0); User second = (User) result.getContents().get(1); assertEquals("1", first.getUserId()); assertEquals("Paul", first.getName()); assertEquals("MALE", first.getSex().getLiteral()); assertEquals("2", second.getUserId()); assertEquals("Anna", second.getName()); assertEquals("FEMALE", second.getSex().getLiteral()); }
public ArrayNode toObjectArray(ObjectMapper mapper) { ArrayNode messageNode = mapper.createArrayNode(); messageNode.add(Messages.NOTIFY); messageNode.add(method); messageNode.add(args); return messageNode; }
@Override public void execute() throws MojoExecutionException { try { JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSourceTree(new File(srcDirectory, "src/main/java")); ObjectNode root = initializeRoot(); ArrayNode tags = mapper.createArrayNode(); ObjectNode paths = mapper.createObjectNode(); root.set("tags", tags); root.set("paths", paths); builder.getClasses().forEach(jc -> processClass(jc, paths, tags)); if (paths.size() > 0) { getLog().info("Generating ONOS REST API documentation..."); genCatalog(root); if (!isNullOrEmpty(apiPackage)) { genRegistrator(); } } project.addCompileSourceRoot(new File(dstDirectory, GEN_SRC).getPath()); } catch (Exception e) { getLog().warn("Unable to generate ONOS REST API documentation", e); throw e; } }
private void processConsumesProduces(ObjectNode methodNode, String type, String io) { if (!io.equals("")) { ArrayNode array = mapper.createArrayNode(); methodNode.set(type, array); array.add(io); } }
@Test public void testSaveTwoRootObjectsWithNoType() { JsonNode expected = mapper .createArrayNode() .add(mapper.createObjectNode().put("userId", "1").put("name", "Paul")) .add( mapper .createObjectNode() .put("userId", "2") .put("name", "Anna") .put("sex", "FEMALE")); User u1 = ModelFactory.eINSTANCE.createUser(); u1.setUserId("1"); u1.setName("Paul"); User u2 = ModelFactory.eINSTANCE.createUser(); u2.setUserId("2"); u2.setName("Anna"); u2.setSex(Sex.FEMALE); Resource resource = new JsonResource(URI.createURI("test"), mapper); resource.getContents().add(u1); resource.getContents().add(u2); JsonNode result = mapper.valueToTree(resource); assertEquals(expected, result); }
public JsonNode toObjectArray(ObjectMapper mapper) throws WampError { ArrayNode messageNode = mapper.createArrayNode(); messageNode.add(ID); messageNode.add(signature); if (extra != null) messageNode.add(extra); else messageNode.add(mapper.createObjectNode()); return messageNode; }
public JsonNode toObjectArray(ObjectMapper mapper) throws WampError { ArrayNode messageNode = mapper.createArrayNode(); messageNode.add(ID); messageNode.add(requestId); if (options != null) messageNode.add(options); else messageNode.add(mapper.createObjectNode()); messageNode.add(procedure.toString()); return messageNode; }
protected void addFormProperties(List<FormProperty> formProperties, ObjectNode propertiesNode) { if (CollectionUtils.isEmpty(formProperties)) return; ObjectNode formPropertiesNode = objectMapper.createObjectNode(); ArrayNode propertiesArrayNode = objectMapper.createArrayNode(); for (FormProperty property : formProperties) { ObjectNode propertyItemNode = objectMapper.createObjectNode(); propertyItemNode.put(PROPERTY_FORM_ID, property.getId()); propertyItemNode.put(PROPERTY_FORM_NAME, property.getName()); propertyItemNode.put(PROPERTY_FORM_TYPE, property.getType()); if (StringUtils.isNotEmpty(property.getExpression())) { propertyItemNode.put(PROPERTY_FORM_EXPRESSION, property.getExpression()); } else { propertyItemNode.putNull(PROPERTY_FORM_EXPRESSION); } if (StringUtils.isNotEmpty(property.getVariable())) { propertyItemNode.put(PROPERTY_FORM_VARIABLE, property.getVariable()); } else { propertyItemNode.putNull(PROPERTY_FORM_VARIABLE); } if (StringUtils.isNotEmpty(property.getDatePattern())) { propertyItemNode.put(PROPERTY_FORM_DATE_PATTERN, property.getDatePattern()); } if (CollectionUtils.isNotEmpty(property.getFormValues())) { ArrayNode valuesNode = objectMapper.createArrayNode(); for (FormValue formValue : property.getFormValues()) { ObjectNode valueNode = objectMapper.createObjectNode(); valueNode.put(PROPERTY_FORM_ENUM_VALUES_NAME, formValue.getName()); valueNode.put(PROPERTY_FORM_ENUM_VALUES_ID, formValue.getId()); valuesNode.add(valueNode); } propertyItemNode.put(PROPERTY_FORM_ENUM_VALUES, valuesNode); } propertyItemNode.put(PROPERTY_FORM_REQUIRED, property.isRequired()); propertyItemNode.put(PROPERTY_FORM_READABLE, property.isReadable()); propertyItemNode.put(PROPERTY_FORM_WRITABLE, property.isWriteable()); propertiesArrayNode.add(propertyItemNode); } formPropertiesNode.put("formProperties", propertiesArrayNode); propertiesNode.put(PROPERTY_FORM_PROPERTIES, formPropertiesNode); }
// initializes top level root with Swagger required specifications private ObjectNode initializeRoot() { ObjectNode root = mapper.createObjectNode(); root.put("swagger", "2.0"); ObjectNode info = mapper.createObjectNode(); root.set("info", info); root.put("basePath", webContext); info.put("version", apiVersion); info.put("title", apiTitle); info.put("description", apiDescription); ArrayNode produces = mapper.createArrayNode(); produces.add("application/json"); root.set("produces", produces); ArrayNode consumes = mapper.createArrayNode(); consumes.add("application/json"); root.set("consumes", consumes); return root; }
// TODO all this is very memory inefficient and will lead to stack overflows for very deep trees public static ObjectNode toJsonTree(ObjectMapper objectMapper, Tree<? extends JsonNode> tree) { final ObjectNode node = objectMapper.createObjectNode(); node.put("_value", tree.value()); final ArrayNode children = objectMapper.createArrayNode(); for (Tree<? extends JsonNode> child : tree.children()) children.add(toJsonTree(objectMapper, child)); node.put("_children", children); return node; }
private JsonNode createProduct(JsonNode node, String userName) throws Exception { ObjectMapper om = new ObjectMapper(); ArrayNode anode = om.createArrayNode(); if (node.isArray()) { Iterator<JsonNode> nodeiterator = node.iterator(); while (nodeiterator.hasNext()) { ProductBack cbase = om.convertValue(nodeiterator.next(), ProductBack.class); anode.add(createProductToDb(om, cbase, userName)); } } else { ProductBack cbase = JSON.parseObject(node.asText(), ProductBack.class); anode.add(createProductToDb(om, cbase, userName)); } return anode; }
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_STRING_VALUE, extension.getStringValue()); } if (StringUtils.isNotEmpty(extension.getExpression())) { propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_EXPRESSION, extension.getExpression()); } itemsNode.add(propertyItemNode); } fieldExtensionsNode.put("fields", itemsNode); propertiesNode.put(PROPERTY_SERVICETASK_FIELDS, fieldExtensionsNode); }
@Deployment public void testSubmitFormData() throws Exception { Map<String, Object> variableMap = new HashMap<String, Object>(); variableMap.put("SpeakerName", "John Doe"); Address address = new Address(); variableMap.put("address", address); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap); String processInstanceId = processInstance.getId(); String processDefinitionId = processInstance.getProcessDefinitionId(); Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); ClientResource client = getAuthenticatedClient(RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA)); ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("taskId", task.getId()); ArrayNode propertyArray = objectMapper.createArrayNode(); requestNode.put("properties", propertyArray); ObjectNode propNode = objectMapper.createObjectNode(); propNode.put("id", "room"); propNode.put("value", 123l); propertyArray.add(propNode); try { client.post(requestNode); } catch (Exception e) { // expected assertEquals(Status.SERVER_ERROR_INTERNAL, client.getResponse().getStatus()); } propNode = objectMapper.createObjectNode(); propNode.put("id", "street"); propNode.put("value", "test"); propertyArray.add(propNode); client.release(); client.post(requestNode); assertEquals(Status.SUCCESS_NO_CONTENT, client.getResponse().getStatus()); task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); assertNull(task); processInstance = runtimeService .createProcessInstanceQuery() .processInstanceId(processInstanceId) .singleResult(); assertNull(processInstance); List<HistoricVariableInstance> variables = historyService .createHistoricVariableInstanceQuery() .processInstanceId(processInstanceId) .list(); Map<String, HistoricVariableInstance> historyMap = new HashMap<String, HistoricVariableInstance>(); for (HistoricVariableInstance historicVariableInstance : variables) { historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance); } assertEquals("123", historyMap.get("room").getValue()); assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId()); processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap); processInstanceId = processInstance.getId(); task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); requestNode.put("taskId", task.getId()); propNode = objectMapper.createObjectNode(); propNode.put("id", "direction"); propNode.put("value", "nowhere"); propertyArray.add(propNode); try { client.release(); client.post(requestNode); } catch (Exception e) { // expected assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, client.getResponse().getStatus()); } propNode.put("value", "up"); client.release(); client.post(requestNode); assertEquals(Status.SUCCESS_NO_CONTENT, client.getResponse().getStatus()); task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); assertNull(task); processInstance = runtimeService .createProcessInstanceQuery() .processInstanceId(processInstanceId) .singleResult(); assertNull(processInstance); variables = historyService .createHistoricVariableInstanceQuery() .processInstanceId(processInstanceId) .list(); historyMap.clear(); for (HistoricVariableInstance historicVariableInstance : variables) { historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance); } assertEquals("123", historyMap.get("room").getValue()); assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId()); assertEquals("up", historyMap.get("direction").getValue()); requestNode = objectMapper.createObjectNode(); requestNode.put("processDefinitionId", processDefinitionId); propertyArray = objectMapper.createArrayNode(); requestNode.put("properties", propertyArray); propNode = objectMapper.createObjectNode(); propNode.put("id", "number"); propNode.put("value", 123); propertyArray.add(propNode); client.release(); Representation response = client.post(requestNode); assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus()); JsonNode responseNode = objectMapper.readTree(response.getStream()); assertNotNull(responseNode.get("id").asText()); assertEquals(processDefinitionId, responseNode.get("processDefinitionId").asText()); task = taskService .createTaskQuery() .processInstanceId(responseNode.get("id").asText()) .singleResult(); assertNotNull(task); }
/** * 百度账户树 * * @return */ @Override public ArrayNode getAccountTree() { ObjectMapper mapper = new ObjectMapper(); ArrayNode arrayNode = mapper.createArrayNode(); ObjectNode objectNode; Long accountId = AppContext.getAccountId(); MongoTemplate mongoTemplate = BaseMongoTemplate.getUserMongo(); Aggregation aggregation1 = Aggregation.newAggregation( match(Criteria.where(ACCOUNT_ID).is(accountId)), project(CAMPAIGN_ID, NAME, SYSTEM_ID), sort(Sort.Direction.ASC, CAMPAIGN_ID)); // 推广计划树 AggregationResults<CampaignVO> results1 = mongoTemplate.aggregate(aggregation1, TBL_CAMPAIGN, CampaignVO.class); for (CampaignVO vo : results1) { objectNode = mapper.createObjectNode(); if (vo.getCampaignId() == null) { objectNode.put("id", vo.getId()); } else { objectNode.put("id", vo.getCampaignId()); } objectNode.put("pId", 0); objectNode.put("name", vo.getCampaignName()); arrayNode.add(objectNode); } Aggregation aggregation2 = Aggregation.newAggregation( match(Criteria.where(ACCOUNT_ID).is(accountId)), project(CAMPAIGN_ID, OBJ_CAMPAIGN_ID, ADGROUP_ID, SYSTEM_ID, NAME), sort(Sort.Direction.ASC, ADGROUP_ID)); AggregationResults<AdgroupVO> results2 = mongoTemplate.aggregate(aggregation2, TBL_ADGROUP, AdgroupVO.class); for (AdgroupVO vo : results2) { objectNode = mapper.createObjectNode(); objectNode.put("name", vo.getAdgroupName()); if (vo.getCampaignId() == null) { objectNode.put("id", vo.getId()); objectNode.put("pId", vo.getCampaignObjId()); arrayNode.add(objectNode); continue; } if (vo.getAdgroupId() == null) { objectNode.put("id", vo.getId()); objectNode.put("pId", vo.getCampaignId()); arrayNode.add(objectNode); continue; } objectNode.put("id", vo.getAdgroupId()); objectNode.put("pId", vo.getCampaignId()); arrayNode.add(objectNode); } return arrayNode; }
public static ArrayNode createArrayNode() { ObjectMapper objectMapper = new ObjectMapper(); ArrayNode ArrayNode = objectMapper.createArrayNode(); return ArrayNode; }
public void convertToJson( BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) { this.model = model; this.processor = processor; this.subProcessX = subProcessX; this.subProcessY = subProcessY; this.shapesArrayNode = shapesArrayNode; GraphicInfo graphicInfo = model.getGraphicInfo(baseElement.getId()); String stencilId = null; if (baseElement instanceof ServiceTask) { ServiceTask serviceTask = (ServiceTask) baseElement; if ("mail".equalsIgnoreCase(serviceTask.getType())) { stencilId = STENCIL_TASK_MAIL; } else if ("camel".equalsIgnoreCase(serviceTask.getType())) { stencilId = STENCIL_TASK_CAMEL; } else if ("mule".equalsIgnoreCase(serviceTask.getType())) { stencilId = STENCIL_TASK_MULE; } else { stencilId = getStencilId(baseElement); } } else { stencilId = getStencilId(baseElement); } flowElementNode = BpmnJsonConverterUtil.createChildShape( baseElement.getId(), stencilId, graphicInfo.getX() - subProcessX + graphicInfo.getWidth(), graphicInfo.getY() - subProcessY + graphicInfo.getHeight(), graphicInfo.getX() - subProcessX, graphicInfo.getY() - subProcessY); shapesArrayNode.add(flowElementNode); ObjectNode propertiesNode = objectMapper.createObjectNode(); propertiesNode.put(PROPERTY_OVERRIDE_ID, baseElement.getId()); if (baseElement instanceof FlowElement) { FlowElement flowElement = (FlowElement) baseElement; if (StringUtils.isNotEmpty(flowElement.getName())) { propertiesNode.put(PROPERTY_NAME, flowElement.getName()); } if (StringUtils.isNotEmpty(flowElement.getDocumentation())) { propertiesNode.put(PROPERTY_DOCUMENTATION, flowElement.getDocumentation()); } } convertElementToJson(propertiesNode, baseElement); flowElementNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode); ArrayNode outgoingArrayNode = objectMapper.createArrayNode(); if (baseElement instanceof FlowNode) { FlowNode flowNode = (FlowNode) baseElement; for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) { outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getId())); } for (MessageFlow messageFlow : model.getMessageFlows().values()) { if (messageFlow.getSourceRef().equals(flowNode.getId())) { outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId())); } } } if (baseElement instanceof Activity) { Activity activity = (Activity) baseElement; for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) { outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(boundaryEvent.getId())); } propertiesNode.put(PROPERTY_ASYNCHRONOUS, activity.isAsynchronous()); propertiesNode.put(PROPERTY_EXCLUSIVE, !activity.isNotExclusive()); if (activity.getLoopCharacteristics() != null) { MultiInstanceLoopCharacteristics loopDef = activity.getLoopCharacteristics(); if (StringUtils.isNotEmpty(loopDef.getLoopCardinality()) || StringUtils.isNotEmpty(loopDef.getInputDataItem()) || StringUtils.isNotEmpty(loopDef.getCompletionCondition())) { if (loopDef.isSequential() == false) { propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Parallel"); } else { propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Sequential"); } if (StringUtils.isNotEmpty(loopDef.getLoopCardinality())) { propertiesNode.put(PROPERTY_MULTIINSTANCE_CARDINALITY, loopDef.getLoopCardinality()); } if (StringUtils.isNotEmpty(loopDef.getInputDataItem())) { propertiesNode.put(PROPERTY_MULTIINSTANCE_COLLECTION, loopDef.getInputDataItem()); } if (StringUtils.isNotEmpty(loopDef.getElementVariable())) { propertiesNode.put(PROPERTY_MULTIINSTANCE_VARIABLE, loopDef.getElementVariable()); } if (StringUtils.isNotEmpty(loopDef.getCompletionCondition())) { propertiesNode.put(PROPERTY_MULTIINSTANCE_CONDITION, loopDef.getCompletionCondition()); } } } if (activity instanceof UserTask) { BpmnJsonConverterUtil.convertListenersToJson( ((UserTask) activity).getTaskListeners(), false, propertiesNode); } BpmnJsonConverterUtil.convertListenersToJson( activity.getExecutionListeners(), true, propertiesNode); if (CollectionUtils.isNotEmpty(activity.getDataInputAssociations())) { for (DataAssociation dataAssociation : activity.getDataInputAssociations()) { if (model.getFlowElement(dataAssociation.getSourceRef()) != null) { createDataAssociation(dataAssociation, true, activity); } } } if (CollectionUtils.isNotEmpty(activity.getDataOutputAssociations())) { for (DataAssociation dataAssociation : activity.getDataOutputAssociations()) { if (model.getFlowElement(dataAssociation.getTargetRef()) != null) { createDataAssociation(dataAssociation, false, activity); outgoingArrayNode.add( BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId())); } } } } for (Artifact artifact : container.getArtifacts()) { if (artifact instanceof Association) { Association association = (Association) artifact; if (StringUtils.isNotEmpty(association.getSourceRef()) && association.getSourceRef().equals(baseElement.getId())) { outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getId())); } } } if (baseElement instanceof DataStoreReference) { for (Process process : model.getProcesses()) { processDataStoreReferences(process, baseElement.getId(), outgoingArrayNode); } } flowElementNode.put("outgoing", outgoingArrayNode); }
/** * Creates and returns a new child array within the specified parent and bound to the given key. * * @param parent parent object * @param key key for the new child array * @return child array */ public ArrayNode newArray(ObjectNode parent, String key) { ArrayNode node = mapper.createArrayNode(); parent.set(key, node); return node; }
// Processes parameters of javaMethod and enters the proper key-values into the methodNode private void processParameters( JavaMethod javaMethod, ObjectNode methodNode, String method, DocletTag tag) { ArrayNode parameters = mapper.createArrayNode(); methodNode.set("parameters", parameters); boolean required = true; for (JavaParameter javaParameter : javaMethod.getParameters()) { ObjectNode individualParameterNode = mapper.createObjectNode(); Optional<JavaAnnotation> optional = javaParameter .getAnnotations() .stream() .filter( annotation -> annotation.getType().getName().equals(PATH_PARAM) || annotation.getType().getName().equals(QUERY_PARAM)) .findAny(); JavaAnnotation pathType = optional.isPresent() ? optional.get() : null; String annotationName = javaParameter.getName(); if (pathType != null) { // the parameter is a path or query parameter individualParameterNode.put( "name", pathType.getNamedParameter("value").toString().replace("\"", "")); if (pathType.getType().getName().equals(PATH_PARAM)) { individualParameterNode.put("in", "path"); } else if (pathType.getType().getName().equals(QUERY_PARAM)) { individualParameterNode.put("in", "query"); } individualParameterNode.put("type", getType(javaParameter.getType())); } else { // the parameter is a body parameter individualParameterNode.put("name", annotationName); individualParameterNode.put("in", "body"); // Adds the reference to the Json model for the input // that goes in the post or put operation if (tag != null && (method.toLowerCase().equals("post") || method.toLowerCase().equals("put"))) { ObjectNode schema = mapper.createObjectNode(); tag.getParameters() .stream() .forEach( param -> { schema.put("$ref", "#/definitions/" + param); }); individualParameterNode.set("schema", schema); } } for (DocletTag p : javaMethod.getTagsByName("param")) { if (p.getValue().contains(annotationName)) { try { String description = p.getValue().split(" ", 2)[1].trim(); if (description.contains("optional")) { required = false; } individualParameterNode.put("description", description); } catch (Exception e) { e.printStackTrace(); } } } individualParameterNode.put("required", required); parameters.add(individualParameterNode); } }