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 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; }
/** * Creates all the models. */ private void initModels() { SchemaManager schemaManager = Framework.getService(SchemaManager.class); log.debug("Schemas fields from descriptor: " + repositoryDescriptor.schemaFields); // document types for (DocumentType docType : schemaManager.getDocumentTypes()) { initDocTypeOrMixinModel(docType.getName(), docType.getSchemas(), allDocTypeSchemas, typeFragments, typePropertyInfos, typeComplexChildren, true); initDocTypePrefetch(docType); initDocTypeMixins(docType); inferSuperType(docType); } // mixins for (CompositeType type : schemaManager.getFacets()) { initDocTypeOrMixinModel(type.getName(), type.getSchemas(), allMixinSchemas, mixinFragments, mixinPropertyInfos, mixinComplexChildren, false); log.debug("Fragments for facet " + type.getName() + ": " + getMixinFragments(type.getName())); } // proxy schemas initProxySchemas(schemaManager.getProxySchemas(null)); // second pass to get subtypes (needs all supertypes) for (DocumentType documentType : schemaManager.getDocumentTypes()) { inferSubTypes(documentType); } // init no per instance query facets initNoPerDocumentQueryFacets(schemaManager); }
String xpath = type.getField(variableName).getName().getPrefixedName(); String blobUrl = VirtualHostHelper.getBaseURL(request) + downloadService.getDownloadUrl(doc, xpath, filename); jg.writeStringField("url", blobUrl);
for (Field f : type.getFields()) { String name = f.getName().getLocalName(); if (!map.containsKey(name)) {
/** * 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; }
for (String facet : getFacets()) { CompositeType facetType = schemaManager.getFacet(facet); field = facetType.getField(segment); if (field != null) { break;
for (Field f : type.getFields()) { String name = f.getName().getLocalName(); if (!map.containsKey(name)) {
@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()));
for (String facet : getFacets()) { CompositeType facetType = schemaManager.getFacet(facet); field = facetType.getField(segment); if (field != null) { break;
/** * @since 8.3 */ public static void writeVariables(DocumentRoute item, JsonGenerator jg, MarshallerRegistry registry, RenderingContext ctx, SchemaManager schemaManager) throws IOException, JsonGenerationException { String facet = (String) item.getDocument().getPropertyValue(GraphRoute.PROP_VARIABLES_FACET); if (StringUtils.isNotBlank(facet)) { CompositeType type = schemaManager.getFacet(facet); if (type != null) { boolean hasFacet = item.getDocument().hasFacet(facet); Writer<Property> propertyWriter = registry.getWriter(ctx, Property.class, APPLICATION_JSON_TYPE); // provides the current route to the property marshaller try (Closeable resource = ctx.wrap() .with(DocumentModelJsonWriter.ENTITY_TYPE, item.getDocument()) .open()) { for (Field f : type.getFields()) { String name = f.getName().getLocalName(); Property property = hasFacet ? item.getDocument().getProperty(name) : null; OutputStream out = new OutputStreamWithJsonWriter(jg); jg.writeFieldName(name); propertyWriter.write(property, Property.class, Property.class, APPLICATION_JSON_TYPE, out); } } } } }
@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); }
/** * @since 8.3 */ public static void writeTaskVariables(GraphNode node, JsonGenerator jg, MarshallerRegistry registry, RenderingContext ctx, SchemaManager schemaManager) throws IOException { if (node == null || node.getDocument() == null) { return; } String facet = (String) node.getDocument().getPropertyValue(GraphNode.PROP_VARIABLES_FACET); if (StringUtils.isNotBlank(facet)) { CompositeType type = schemaManager.getFacet(facet); if (type != null) { boolean hasFacet = node.getDocument().hasFacet(facet); Writer<Property> propertyWriter = registry.getWriter(ctx, Property.class, APPLICATION_JSON_TYPE); // provides the current route to the property marshaller try (Closeable resource = ctx.wrap() .with(DocumentModelJsonWriter.ENTITY_TYPE, node.getDocument()) .open()) { for (Field f : type.getFields()) { String name = f.getName().getLocalName(); Property property = hasFacet ? node.getDocument().getProperty(name) : null; OutputStream out = new OutputStreamWithJsonWriter(jg); jg.writeFieldName(name); propertyWriter.write(property, Property.class, Property.class, APPLICATION_JSON_TYPE, out); } } } } }
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); } }
.with(DocumentModelJsonWriter.ENTITY_TYPE, route.getDocument()) .open()) { for (Field f : type.getFields()) { String name = f.getName().getLocalName(); if (transientSchema.hasField(name)) {
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));