Search in sources :

Example 1 with Resource

use of org.eclipse.bpmn2.Resource in project oxTrust by GluuFederation.

the class ResourceTypeWS method listResources.

@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response listResources(@HeaderParam("Authorization") String authorization) throws Exception {
    ListResponse listResponse = new ListResponse();
    List<String> schemas = new ArrayList<String>();
    schemas.add(Constants.LIST_RESPONSE_SCHEMA_ID);
    listResponse.setSchemas(schemas);
    // START: User
    ResourceType userResourceType = new ResourceType();
    userResourceType.setDescription(Constants.USER_CORE_SCHEMA_DESCRIPTION);
    userResourceType.setEndpoint("/v2/Users");
    userResourceType.setName(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setId(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setSchema(Constants.USER_CORE_SCHEMA_ID);
    Meta userMeta = new Meta();
    userMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
    userMeta.setResourceType("ResourceType");
    userResourceType.setMeta(userMeta);
    List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
    SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
    userExtensionSchema.setSchema(Constants.USER_EXT_SCHEMA_ID);
    userExtensionSchema.setRequired(false);
    schemaExtensions.add(userExtensionSchema);
    userResourceType.setSchemaExtensions(schemaExtensions);
    // START: Group
    ResourceType groupResourceType = new ResourceType();
    groupResourceType.setDescription(Constants.GROUP_CORE_SCHEMA_DESCRIPTION);
    groupResourceType.setEndpoint("/v2/Groups");
    groupResourceType.setName(Constants.GROUP_CORE_SCHEMA_NAME);
    groupResourceType.setId(Constants.GROUP_CORE_SCHEMA_NAME);
    groupResourceType.setSchema(Constants.GROUP_CORE_SCHEMA_ID);
    Meta groupMeta = new Meta();
    groupMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/Group");
    groupMeta.setResourceType("ResourceType");
    groupResourceType.setMeta(groupMeta);
    // START: FidoDevice
    ResourceType fidoDeviceResourceType = new ResourceType();
    fidoDeviceResourceType.setDescription(Constants.FIDO_DEVICES_CORE_SCHEMA_DESCRIPTION);
    fidoDeviceResourceType.setEndpoint("/v2/FidoDevices");
    fidoDeviceResourceType.setName(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
    fidoDeviceResourceType.setId(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
    fidoDeviceResourceType.setSchema(Constants.FIDO_DEVICES_CORE_SCHEMA_ID);
    Meta fidoDeviceMeta = new Meta();
    fidoDeviceMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/FidoDevice");
    fidoDeviceMeta.setResourceType("ResourceType");
    fidoDeviceResourceType.setMeta(fidoDeviceMeta);
    // ResourceType[] resourceTypes = new ResourceType[]{userResourceType, groupResourceType};
    List<Resource> resourceTypes = new ArrayList<Resource>();
    resourceTypes.add(userResourceType);
    resourceTypes.add(groupResourceType);
    resourceTypes.add(fidoDeviceResourceType);
    listResponse.setResources(resourceTypes);
    listResponse.setTotalResults(resourceTypes.size());
    listResponse.setItemsPerPage(10);
    listResponse.setStartIndex(1);
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes");
    // return Response.ok(resourceTypes).location(location).build();
    return Response.ok(listResponse).location(location).build();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaExtensionHolder(org.gluu.oxtrust.model.scim2.schema.SchemaExtensionHolder) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) ArrayList(java.util.ArrayList) Resource(org.gluu.oxtrust.model.scim2.Resource) ResourceType(org.gluu.oxtrust.model.scim2.provider.ResourceType) URI(java.net.URI) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with Resource

use of org.eclipse.bpmn2.Resource in project oxTrust by GluuFederation.

the class SchemaWebService method listSchemas.

/**
     * Retrieves the complete schema.
     *
     * @param authorization
     * @return
     * @throws Exception
     */
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response listSchemas(@HeaderParam("Authorization") String authorization) throws Exception {
    log.info(" listSchemas() ");
    ListResponse listResponse = new ListResponse();
    List<String> schemas = new ArrayList<String>();
    schemas.add(Constants.LIST_RESPONSE_SCHEMA_ID);
    listResponse.setSchemas(schemas);
    List<SchemaType> schemaTypes = SchemaTypeMapping.getSchemaInstances();
    List<Resource> resources = new ArrayList<Resource>();
    SchemaTypeLoadingFactory factory = new SchemaTypeLoadingFactory();
    for (SchemaType schemaType : schemaTypes) {
        factory.load(appConfiguration, schemaType);
        resources.add(schemaType);
    }
    listResponse.setResources(resources);
    listResponse.setTotalResults(schemaTypes.size());
    listResponse.setItemsPerPage(10);
    listResponse.setStartIndex(1);
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas");
    // Serialize to JSON
    String json = serialize(listResponse);
    return Response.ok(json).location(location).build();
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) SchemaTypeLoadingFactory(org.gluu.oxtrust.service.scim2.schema.SchemaTypeLoadingFactory) ArrayList(java.util.ArrayList) Resource(org.gluu.oxtrust.model.scim2.Resource) URI(java.net.URI) SchemaType(org.gluu.oxtrust.model.scim2.schema.SchemaType) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with Resource

use of org.eclipse.bpmn2.Resource in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshaller method marshall.

@Override
@SuppressWarnings("unchecked")
public String marshall(final Diagram<Graph, Metadata> diagram) throws IOException {
    LOG.debug("Starting diagram marshalling...");
    Bpmn2Resource resource = createBpmn2Resource();
    // we start converting from the root, then pull out the result
    DefinitionsConverter definitionsConverter = new DefinitionsConverter(diagram.getGraph());
    Definitions definitions = definitionsConverter.toDefinitions();
    resource.getContents().add(definitions);
    LOG.debug("Diagram marshalling completed successfully.");
    String outputString = renderToString(resource);
    LOG.trace(outputString);
    return outputString;
}
Also used : Bpmn2Resource(org.eclipse.bpmn2.util.Bpmn2Resource) Definitions(org.eclipse.bpmn2.Definitions) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter)

Example 4 with Resource

use of org.eclipse.bpmn2.Resource in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshaller method parseDefinitions.

private static Definitions parseDefinitions(final InputStream inputStream) throws IOException {
    DroolsPackageImpl.init();
    BpsimPackageImpl.init();
    final ResourceSet resourceSet = new ResourceSetImpl();
    Resource.Factory.Registry resourceFactoryRegistry = resourceSet.getResourceFactoryRegistry();
    resourceFactoryRegistry.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new JBPMBpmn2ResourceFactoryImpl());
    EPackage.Registry packageRegistry = resourceSet.getPackageRegistry();
    packageRegistry.put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
    packageRegistry.put("http://www.jboss.org/drools", DroolsPackage.eINSTANCE);
    final JBPMBpmn2ResourceImpl resource = (JBPMBpmn2ResourceImpl) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8");
    resource.setEncoding("UTF-8");
    final Map<String, Object> options = new HashMap<String, Object>();
    options.put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8");
    options.put(JBPMBpmn2ResourceImpl.OPTION_DEFER_IDREF_RESOLUTION, true);
    options.put(JBPMBpmn2ResourceImpl.OPTION_DISABLE_NOTIFY, true);
    options.put(JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF, JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF_RECORD);
    resource.load(inputStream, options);
    final DocumentRoot root = (DocumentRoot) resource.getContents().get(0);
    return root.getDefinitions();
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) JBPMBpmn2ResourceImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl) HashMap(java.util.HashMap) DocumentRoot(org.eclipse.bpmn2.DocumentRoot) LoggerFactory(org.slf4j.LoggerFactory) ConverterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.ConverterFactory) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JBPMBpmn2ResourceFactoryImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceFactoryImpl) EPackage(org.eclipse.emf.ecore.EPackage)

Example 5 with Resource

use of org.eclipse.bpmn2.Resource in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method marshallDefinitions.

protected void marshallDefinitions(Definitions def, JsonGenerator generator, String preProcessingData) throws JsonGenerationException, IOException {
    try {
        generator.writeStartObject();
        generator.writeObjectField("resourceId", def.getId());
        /**
         * "properties":{"name":"",
         * "documentation":"",
         * "auditing":"",
         * "monitoring":"",
         * "executable":"true",
         * "package":"com.sample",
         * "vardefs":"a,b,c,d",
         * "lanes" : "a,b,c",
         * "id":"",
         * "version":"",
         * "author":"",
         * "language":"",
         * "namespaces":"",
         * "targetnamespace":"",
         * "expressionlanguage":"",
         * "typelanguage":"",
         * "creationdate":"",
         * "modificationdate":""
         * }
         */
        Map<String, Object> props = new LinkedHashMap<String, Object>();
        props.put(NAMESPACES, "");
        // props.put("targetnamespace", def.getTargetNamespace());
        props.put(TARGETNAMESPACE, "http://www.omg.org/bpmn20");
        props.put(TYPELANGUAGE, def.getTypeLanguage());
        props.put(NAME, StringEscapeUtils.unescapeXml(def.getName()));
        props.put(ID, def.getId());
        props.put(EXPRESSIONLANGUAGE, def.getExpressionLanguage());
        // backwards compat for BZ 1048191
        putDocumentationProperty(def, props);
        for (RootElement rootElement : def.getRootElements()) {
            if (rootElement instanceof Process) {
                // have to wait for process node to finish properties and stencil marshalling
                props.put(EXECUTABLE, ((Process) rootElement).isIsExecutable() + "");
                props.put(ID, rootElement.getId());
                if (rootElement.getDocumentation() != null && rootElement.getDocumentation().size() > 0) {
                    props.put(DOCUMENTATION, rootElement.getDocumentation().get(0).getText());
                }
                Process pr = (Process) rootElement;
                if (pr.getName() != null && pr.getName().length() > 0) {
                    props.put(PROCESSN, StringEscapeUtils.unescapeXml(((Process) rootElement).getName()));
                }
                List<Property> processProperties = ((Process) rootElement).getProperties();
                if (processProperties != null && processProperties.size() > 0) {
                    String propVal = "";
                    for (int i = 0; i < processProperties.size(); i++) {
                        Property p = processProperties.get(i);
                        String pKPI = Utils.getMetaDataValue(p.getExtensionValues(), "customKPI");
                        propVal += p.getId();
                        // check the structureRef value
                        if (p.getItemSubjectRef() != null && p.getItemSubjectRef().getStructureRef() != null) {
                            propVal += ":" + p.getItemSubjectRef().getStructureRef();
                        }
                        if (pKPI != null && pKPI.length() > 0) {
                            propVal += ":" + pKPI;
                        }
                        if (i != processProperties.size() - 1) {
                            propVal += ",";
                        }
                    }
                    props.put("vardefs", propVal);
                }
                // packageName and version and adHoc are jbpm-specific extension attribute
                Iterator<FeatureMap.Entry> iter = ((Process) rootElement).getAnyAttribute().iterator();
                while (iter.hasNext()) {
                    FeatureMap.Entry entry = iter.next();
                    if (entry.getEStructuralFeature().getName().equals("packageName")) {
                        props.put(PACKAGE, entry.getValue());
                    }
                    if (entry.getEStructuralFeature().getName().equals("version")) {
                        props.put(VERSION, entry.getValue());
                    }
                    if (entry.getEStructuralFeature().getName().equals("adHoc")) {
                        props.put(ADHOCPROCESS, entry.getValue());
                    }
                }
                // process imports, custom description and globals extension elements
                String allImports = "";
                if ((rootElement).getExtensionValues() != null && (rootElement).getExtensionValues().size() > 0) {
                    String importsStr = "";
                    String globalsStr = "";
                    for (ExtensionAttributeValue extattrval : rootElement.getExtensionValues()) {
                        FeatureMap extensionElements = extattrval.getValue();
                        @SuppressWarnings("unchecked") List<ImportType> importExtensions = (List<ImportType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, true);
                        @SuppressWarnings("unchecked") List<GlobalType> globalExtensions = (List<GlobalType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, true);
                        List<MetaDataType> metadataExtensions = (List<MetaDataType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__META_DATA, true);
                        for (ImportType importType : importExtensions) {
                            importsStr += importType.getName();
                            importsStr += "|default,";
                        }
                        for (GlobalType globalType : globalExtensions) {
                            globalsStr += (globalType.getIdentifier() + ":" + globalType.getType());
                            globalsStr += ",";
                        }
                        for (MetaDataType metaType : metadataExtensions) {
                            props.put("customdescription", metaType.getMetaValue());
                        }
                    }
                    allImports += importsStr;
                    if (globalsStr.length() > 0) {
                        if (globalsStr.endsWith(",")) {
                            globalsStr = globalsStr.substring(0, globalsStr.length() - 1);
                        }
                        props.put(GLOBALS, globalsStr);
                    }
                }
                // definitions imports (wsdl)
                List<org.eclipse.bpmn2.Import> wsdlImports = def.getImports();
                if (wsdlImports != null) {
                    for (org.eclipse.bpmn2.Import imp : wsdlImports) {
                        allImports += imp.getLocation() + "|" + imp.getNamespace() + "|wsdl,";
                    }
                }
                if (allImports.endsWith(",")) {
                    allImports = allImports.substring(0, allImports.length() - 1);
                }
                props.put(IMPORTS, allImports);
                // simulation
                if (_simulationScenario != null && _simulationScenario.getScenarioParameters() != null) {
                    props.put(CURRENCY, _simulationScenario.getScenarioParameters().getBaseCurrencyUnit() == null ? "" : _simulationScenario.getScenarioParameters().getBaseCurrencyUnit());
                    props.put(TIMEUNIT, _simulationScenario.getScenarioParameters().getBaseTimeUnit().getName());
                }
                marshallProperties(props, generator);
                marshallStencil("BPMNDiagram", generator);
                linkSequenceFlows(((Process) rootElement).getFlowElements());
                marshallProcess((Process) rootElement, def, generator, preProcessingData);
            } else if (rootElement instanceof Interface) {
            // TODO
            } else if (rootElement instanceof ItemDefinition) {
            // TODO
            } else if (rootElement instanceof Resource) {
            // TODO
            } else if (rootElement instanceof Error) {
            // TODO
            } else if (rootElement instanceof Message) {
            // TODO
            } else if (rootElement instanceof Signal) {
            // TODO
            } else if (rootElement instanceof Escalation) {
            // TODO
            } else if (rootElement instanceof Collaboration) {
            } else {
                _logger.warn("Unknown root element " + rootElement + ". This element will not be parsed.");
            }
        }
        generator.writeObjectFieldStart("stencilset");
        generator.writeObjectField("url", this.profile.getStencilSetURL());
        generator.writeObjectField("namespace", this.profile.getStencilSetNamespaceURL());
        generator.writeEndObject();
        generator.writeArrayFieldStart("ssextensions");
        generator.writeObject(this.profile.getStencilSetExtensionURL());
        generator.writeEndArray();
        generator.writeEndObject();
    } finally {
        _diagramElements.clear();
    }
}
Also used : Message(org.eclipse.bpmn2.Message) Escalation(org.eclipse.bpmn2.Escalation) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) Signal(org.eclipse.bpmn2.Signal) MetaDataType(org.jboss.drools.MetaDataType) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) Property(org.eclipse.bpmn2.Property) ImportType(org.jboss.drools.ImportType) Resource(org.eclipse.bpmn2.Resource) Error(org.eclipse.bpmn2.Error) Point(org.eclipse.dd.dc.Point) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) RootElement(org.eclipse.bpmn2.RootElement) Collaboration(org.eclipse.bpmn2.Collaboration) DataObject(org.eclipse.bpmn2.DataObject) Interface(org.eclipse.bpmn2.Interface) GlobalType(org.jboss.drools.GlobalType)

Aggregations

Definitions (org.eclipse.bpmn2.Definitions)7 Test (org.junit.Test)6 JBPMBpmn2ResourceImpl (org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl)6 Process (org.eclipse.bpmn2.Process)5 DocumentRoot (org.eclipse.bpmn2.DocumentRoot)4 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)4 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)4 Graph (org.kie.workbench.common.stunner.core.graph.Graph)4 Resource (io.opencensus.proto.resource.v1.Resource)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)3 Matchers.anyString (org.mockito.Matchers.anyString)3 IOException (java.io.IOException)2 URI (java.net.URI)2 LinkedHashMap (java.util.LinkedHashMap)2 DefaultValue (javax.ws.rs.DefaultValue)2 GET (javax.ws.rs.GET)2