@Override public boolean addFacet(String facet) { if (facet == null) { throw new IllegalArgumentException("Null facet"); } if (facets.contains(facet)) { return false; } TypeProvider typeProvider = getSchemaManager(); CompositeType facetType = typeProvider.getFacet(facet); if (facetType == null) { throw new IllegalArgumentException("No such facet: " + facet); } // add it facets.add(facet); instanceFacets.add(facet); schemas.addAll(Arrays.asList(facetType.getSchemaNames())); return true; }
/** * Recomputes effective schemas from a type + instance facets. */ public static Set<String> computeSchemas(DocumentType type, Collection<String> instanceFacets, boolean isProxy) { Set<String> schemas = new HashSet<>(); schemas.addAll(Arrays.asList(type.getSchemaNames())); TypeProvider typeProvider = getSchemaManager(); for (String facet : instanceFacets) { CompositeType facetType = typeProvider.getFacet(facet); if (facetType != null) { // ignore pseudo-facets like Immutable schemas.addAll(Arrays.asList(facetType.getSchemaNames())); } } if (isProxy) { for (Schema schema : typeProvider.getProxySchemas(type.getName())) { schemas.add(schema.getName()); } } return schemas; }
protected void writeFacet(JsonGenerator jg, CompositeType facet, boolean expandSchemas) throws IOException { jg.writeStringField("name", facet.getName()); if (facet.getSchemaNames() != null && facet.getSchemaNames().length > 0) { jg.writeArrayFieldStart("schemas"); if (expandSchemas) { for (Schema schema : facet.getSchemas()) { writeSchemaObject(jg, schema); } } else { for (String schemaName : facet.getSchemaNames()) { jg.writeString(schemaName); } } jg.writeEndArray(); } } }
@Override protected void writeEntityBody(CompositeType facet, JsonGenerator jg) throws IOException { jg.writeStringField("name", facet.getName()); if (facet.getSchemaNames() != null && facet.getSchemaNames().length > 0) { jg.writeArrayFieldStart("schemas"); Writer<Schema> schemaWriter = registry.getWriter(ctx, Schema.class, APPLICATION_JSON_TYPE); for (Schema schema : facet.getSchemas()) { OutputStream out = new OutputStreamWithJsonWriter(jg); schemaWriter.write(schema, Schema.class, Schema.class, APPLICATION_JSON_TYPE, out); } jg.writeEndArray(); } }
schemaNames.addAll(Arrays.asList(ct.getSchemaNames()));
@Override protected WorkflowRequest readEntity(JsonNode jn) throws IOException { String workflowModelName = getStringField(jn, "workflowModelName"); List<String> attachedDocumentIds = new ArrayList<String>(); JsonNode attachedDocumentIdsNode = jn.get("attachedDocumentIds"); if (attachedDocumentIdsNode != null) { for (Iterator<JsonNode> it = attachedDocumentIdsNode.elements(); it.hasNext();) { attachedDocumentIds.add(it.next().textValue()); } } Map<String, Serializable> variables = new HashMap<>(); JsonNode variablesNode = jn.get("variables"); if (variablesNode != null) { try (SessionWrapper closeable = ctx.getSession(null)) { CoreSession session = closeable.getSession(); String workflowModelId = documentRoutingService.getRouteModelDocIdWithId(session, workflowModelName); DocumentModel model = session.getDocument(new IdRef(workflowModelId)); String workflowSchemaFacet = (String) model.getPropertyValue(GraphRoute.PROP_VARIABLES_FACET); CompositeType type = schemaManager.getFacet(workflowSchemaFacet); String workflowSchema = type.getSchemaNames()[0]; variables.putAll(getVariables(variablesNode, workflowSchema)); } } return new WorkflowRequest(workflowModelName, attachedDocumentIds, variables); }
protected void loadDataModelsForFacet(DocumentModel docModel, Document doc, String facetName) { // Load all the data related to facet's schemas SchemaManager schemaManager = Framework.getService(SchemaManager.class); CompositeType facet = schemaManager.getFacet(facetName); if (facet == null) { return; } String[] facetSchemas = facet.getSchemaNames(); for (String schema : facetSchemas) { DataModel dm = DocumentModelFactory.createDataModel(doc, schemaManager.getSchema(schema)); docModel.getDataModels().put(schema, dm); } }
GraphRoute.PROP_VARIABLES_FACET); CompositeType type = schemaManager.getFacet(workflowSchemaFacet); workflowSchema = type.getSchemaNames()[0]; variables.putAll(getVariables(variablesNode, workflowSchema)); nodeSchema = type.getSchemaNames()[0]; variables.putAll(getVariables(variablesNode, nodeSchema));