Search in sources :

Example 26 with Collection

use of org.wso2.carbon.registry.api.Collection in project carbon-business-process by wso2.

the class BaseExecutionService method createExecutionVariable.

protected Response createExecutionVariable(Execution execution, boolean override, int variableType, HttpServletRequest httpServletRequest, UriInfo uriInfo) {
    Object result = null;
    Response.ResponseBuilder responseBuilder = Response.ok();
    List<RestVariable> inputVariables = new ArrayList<>();
    List<RestVariable> resultVariables = new ArrayList<>();
    if (Utils.isApplicationJsonRequest(httpServletRequest)) {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            @SuppressWarnings("unchecked") List<Object> variableObjects = (List<Object>) objectMapper.readValue(httpServletRequest.getInputStream(), List.class);
            for (Object restObject : variableObjects) {
                RestVariable restVariable = objectMapper.convertValue(restObject, RestVariable.class);
                inputVariables.add(restVariable);
            }
        } catch (Exception e) {
            throw new ActivitiIllegalArgumentException("Failed to serialize to a RestVariable instance", e);
        }
    } else if (Utils.isApplicationXmlRequest(httpServletRequest)) {
        JAXBContext jaxbContext = null;
        try {
            jaxbContext = JAXBContext.newInstance(RestVariableCollection.class);
            XMLInputFactory inputFactory = XMLInputFactory.newInstance();
            inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
            inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
            XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(new StreamSource(httpServletRequest.getInputStream()));
            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            RestVariableCollection restVariableCollection = (RestVariableCollection) jaxbUnmarshaller.unmarshal(xmlReader);
            if (restVariableCollection == null) {
                throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable Collection instance.");
            }
            List<RestVariable> restVariableList = restVariableCollection.getRestVariables();
            if (restVariableList.size() == 0) {
                throw new ActivitiIllegalArgumentException("xml request body could not identify any rest " + "variables to be updated");
            }
            for (RestVariable restVariable : restVariableList) {
                inputVariables.add(restVariable);
            }
        } catch (JAXBException | IOException | XMLStreamException e) {
            throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable instance.", e);
        }
    }
    if (inputVariables.size() == 0) {
        throw new ActivitiIllegalArgumentException("Request didn't contain a list of variables to create.");
    }
    RestVariable.RestVariableScope sharedScope = null;
    RestVariable.RestVariableScope varScope = null;
    Map<String, Object> variablesToSet = new HashMap<String, Object>();
    for (RestVariable var : inputVariables) {
        // Validate if scopes match
        varScope = var.getVariableScope();
        if (var.getName() == null) {
            throw new ActivitiIllegalArgumentException("Variable name is required");
        }
        if (varScope == null) {
            varScope = RestVariable.RestVariableScope.LOCAL;
        }
        if (sharedScope == null) {
            sharedScope = varScope;
        }
        if (varScope != sharedScope) {
            throw new ActivitiIllegalArgumentException("Only allowed to update multiple variables in the same scope.");
        }
        if (!override && hasVariableOnScope(execution, var.getName(), varScope)) {
            throw new BPMNConflictException("Variable '" + var.getName() + "' is already present on execution '" + execution.getId() + "'.");
        }
        Object actualVariableValue = new RestResponseFactory().getVariableValue(var);
        variablesToSet.put(var.getName(), actualVariableValue);
        resultVariables.add(new RestResponseFactory().createRestVariable(var.getName(), actualVariableValue, varScope, execution.getId(), variableType, false, uriInfo.getBaseUri().toString()));
    }
    if (!variablesToSet.isEmpty()) {
        RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
        if (sharedScope == RestVariable.RestVariableScope.LOCAL) {
            runtimeService.setVariablesLocal(execution.getId(), variablesToSet);
        } else {
            if (execution.getParentId() != null) {
                // Explicitly set on parent, setting non-local variables on execution itself will override local-variables if exists
                runtimeService.setVariables(execution.getParentId(), variablesToSet);
            } else {
                // Standalone task, no global variables possible
                throw new ActivitiIllegalArgumentException("Cannot set global variables on execution '" + execution.getId() + "', task is not part of process.");
            }
        }
    }
    RestVariableCollection restVariableCollection = new RestVariableCollection();
    restVariableCollection.setRestVariables(resultVariables);
    responseBuilder.entity(restVariableCollection);
    return responseBuilder.status(Response.Status.CREATED).build();
}
Also used : BPMNConflictException(org.wso2.carbon.bpmn.rest.common.exception.BPMNConflictException) XMLStreamReader(javax.xml.stream.XMLStreamReader) JAXBContext(javax.xml.bind.JAXBContext) RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Unmarshaller(javax.xml.bind.Unmarshaller) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService) StreamSource(javax.xml.transform.stream.StreamSource) ActivitiException(org.activiti.engine.ActivitiException) BPMNContentNotSupportedException(org.wso2.carbon.bpmn.rest.common.exception.BPMNContentNotSupportedException) XMLStreamException(javax.xml.stream.XMLStreamException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) BPMNConflictException(org.wso2.carbon.bpmn.rest.common.exception.BPMNConflictException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) JAXBException(javax.xml.bind.JAXBException) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 27 with Collection

use of org.wso2.carbon.registry.api.Collection in project jaggery by wso2.

the class RegistryHostObject method loadResourceByPath.

private ResourceData loadResourceByPath(UserRegistry registry, String path) throws RegistryException {
    ResourceData resourceData = new ResourceData();
    resourceData.setResourcePath(path);
    if (path != null) {
        if (RegistryConstants.ROOT_PATH.equals(path)) {
            resourceData.setName("root");
        } else {
            String[] parts = path.split(RegistryConstants.PATH_SEPARATOR);
            resourceData.setName(parts[parts.length - 1]);
        }
    }
    Resource child = registry.get(path);
    resourceData.setResourceType(child instanceof Collection ? "collection" : "resource");
    resourceData.setAuthorUserName(child.getAuthorUserName());
    resourceData.setDescription(child.getDescription());
    resourceData.setAverageRating(registry.getAverageRating(child.getPath()));
    Calendar createdDateTime = Calendar.getInstance();
    createdDateTime.setTime(child.getCreatedTime());
    resourceData.setCreatedOn(createdDateTime);
    CommonUtil.populateAverageStars(resourceData);
    child.discard();
    return resourceData;
}
Also used : ResourceData(org.wso2.carbon.registry.common.ResourceData) Collection(org.wso2.carbon.registry.core.Collection)

Example 28 with Collection

use of org.wso2.carbon.registry.api.Collection in project carbon-apimgt by wso2.

the class ApiDAOImpl method addUrlMappings.

private void addUrlMappings(Connection connection, Collection<UriTemplate> uriTemplates, String apiID) throws SQLException {
    final String query = "INSERT INTO AM_API_OPERATION_MAPPING (OPERATION_ID,API_ID, HTTP_METHOD, URL_PATTERN, " + "AUTH_SCHEME, API_POLICY_ID) VALUES (?,?,?,?,?,?)";
    try (PreparedStatement statement = connection.prepareStatement(query)) {
        for (UriTemplate uriTemplate : uriTemplates) {
            statement.setString(1, uriTemplate.getTemplateId());
            statement.setString(2, apiID);
            statement.setString(3, uriTemplate.getHttpVerb());
            statement.setString(4, uriTemplate.getUriTemplate());
            statement.setString(5, uriTemplate.getAuthType());
            statement.setString(6, uriTemplate.getPolicy().getUuid());
            statement.addBatch();
        }
        statement.executeBatch();
        for (UriTemplate uriTemplate : uriTemplates) {
            addEndPointsForOperation(connection, apiID, uriTemplate.getTemplateId(), uriTemplate.getEndpoint());
        }
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate)

Example 29 with Collection

use of org.wso2.carbon.registry.api.Collection in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method initPath.

/**
 * {@inheritDoc}
 * Will return true if all the provided WSDL files in the initialized path is of 2.0 and can be successfully
 * parsed by woden.
 */
@Override
public boolean initPath(String path) throws APIMgtWSDLException {
    pathToDescriptionMap = new HashMap<>();
    wsdlArchiveExtractedPath = path;
    try {
        WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
        reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
        File folderToImport = new File(path);
        Collection<File> foundWSDLFiles = APIFileUtils.searchFilesWithMatchingExtension(folderToImport, "wsdl");
        if (log.isDebugEnabled()) {
            log.debug("Found " + foundWSDLFiles.size() + " WSDL file(s) in path " + path);
        }
        for (File file : foundWSDLFiles) {
            if (log.isDebugEnabled()) {
                log.debug("Processing WSDL file: " + file.getAbsolutePath());
            }
            Description description = reader.readWSDL(file.getAbsolutePath());
            pathToDescriptionMap.put(file.getAbsolutePath(), description);
        }
        if (foundWSDLFiles.size() > 0) {
            canProcess = true;
        }
        if (log.isDebugEnabled()) {
            log.debug("Successfully processed all WSDL files in path " + path);
        }
    } catch (WSDLException e) {
        // This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        canProcess = false;
    }
    return canProcess;
}
Also used : Description(org.apache.woden.wsdl20.Description) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(org.apache.woden.WSDLException) File(java.io.File) WSDLReader(org.apache.woden.WSDLReader)

Example 30 with Collection

use of org.wso2.carbon.registry.api.Collection in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method initPath.

/**
 * {@inheritDoc}
 * Will return true if all the provided WSDL files in the initialized path is of 1.1 and can be successfully
 * parsed by WSDL4J.
 */
@Override
public boolean initPath(String path) throws APIMgtWSDLException {
    pathToDefinitionMap = new HashMap<>();
    wsdlArchiveExtractedPath = path;
    WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
    // switch off the verbose mode
    wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
    wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
    try {
        File folderToImport = new File(path);
        Collection<File> foundWSDLFiles = APIFileUtils.searchFilesWithMatchingExtension(folderToImport, "wsdl");
        if (log.isDebugEnabled()) {
            log.debug("Found " + foundWSDLFiles.size() + " WSDL file(s) in path " + path);
        }
        for (File file : foundWSDLFiles) {
            String absWSDLPath = file.getAbsolutePath();
            if (log.isDebugEnabled()) {
                log.debug("Processing WSDL file: " + absWSDLPath);
            }
            Definition definition = wsdlReader.readWSDL(null, absWSDLPath);
            pathToDefinitionMap.put(absWSDLPath, definition);
        }
        if (foundWSDLFiles.size() > 0) {
            canProcess = true;
        }
        if (log.isDebugEnabled()) {
            log.debug("Successfully processed all WSDL files in path " + path);
        }
    } catch (WSDLException e) {
        // This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        canProcess = false;
    }
    return canProcess;
}
Also used : APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) Definition(javax.wsdl.Definition) File(java.io.File) WSDLReader(javax.wsdl.xml.WSDLReader)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)13 Collection (java.util.Collection)9 ArrayList (java.util.ArrayList)8 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)8 IOException (java.io.IOException)7 Collection (org.wso2.carbon.registry.core.Collection)7 Map (java.util.Map)6 HashSet (java.util.HashSet)5 File (java.io.File)4 InstanceFilter (org.apache.ode.bpel.common.InstanceFilter)4 BpelDAOConnection (org.apache.ode.bpel.dao.BpelDAOConnection)4 ProcessInstanceDAO (org.apache.ode.bpel.dao.ProcessInstanceDAO)4 BpelDatabase (org.apache.ode.bpel.engine.BpelDatabase)4 Test (org.testng.annotations.Test)4 TenantProcessStoreImpl (org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl)4 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HashMap (java.util.HashMap)3 Response (javax.ws.rs.core.Response)3 JAXBContext (javax.xml.bind.JAXBContext)3