Search in sources :

Example 11 with Skip

use of org.wso2.carbon.humantask.core.engine.commands.Skip in project carbon-apimgt by wso2.

the class ApiImportExportManager method getAPIDetails.

/**
 * Retrieves all API details of the APIs for the given search query. API details consist of:
 *      1. API {@link org.wso2.carbon.apimgt.core.models.API}
 *      2. Document Info {@link org.wso2.carbon.apimgt.core.models.DocumentInfo}
 *      3. Document Content {@link org.wso2.carbon.apimgt.core.models.DocumentContent}
 *      4. Swagger Definition
 *      5. Gateway Definition
 *      6. Thumbnail content
 *
 * @param limit number of max results
 * @param offset starting location when returning a limited set of results
 * @param query searchQuery
 * @return {@link APIDetails} instance
 * @throws APIManagementException if an error occurs while retrieving API details
 */
public Set<APIDetails> getAPIDetails(Integer limit, Integer offset, String query) throws APIManagementException {
    Set<APIDetails> apiDetailSet = new HashSet<>();
    // search for APIs
    List<API> apis = apiPublisher.searchAPIs(limit, offset, query);
    if (apis == null || apis.isEmpty()) {
        // no APIs found, return
        return apiDetailSet;
    }
    // iterate and collect all information
    for (API api : apis) {
        api = apiPublisher.getAPIbyUUID(api.getId());
        // get endpoints at API Level
        Map<String, Endpoint> endpoints = api.getEndpoint();
        if (endpoints.isEmpty()) {
            log.error("No Endpoints found for api: " + api.getName() + ", version: " + api.getVersion());
        // skip this API
        // continue;
        }
        Set<Endpoint> endpointSet = new HashSet<>();
        for (Map.Entry<String, Endpoint> endpointEntry : endpoints.entrySet()) {
            if (APIMgtConstants.GLOBAL_ENDPOINT.equals(endpointEntry.getValue().getApplicableLevel())) {
                Endpoint endpoint = new Endpoint.Builder(apiPublisher.getEndpoint(endpointEntry.getValue().getId())).id("").build();
                endpoints.replace(endpointEntry.getKey(), endpoint);
                endpointSet.add(endpoint);
            }
        }
        // get Endpoints at Resource Level
        Map<String, UriTemplate> uriTemplateMap = api.getUriTemplates();
        uriTemplateMap.forEach((k, v) -> {
            UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder(v);
            Map<String, Endpoint> resourceEndpoints = uriTemplateBuilder.getEndpoint();
            resourceEndpoints.forEach((type, value) -> {
                Endpoint endpoint = null;
                if (APIMgtConstants.GLOBAL_ENDPOINT.equals(value.getApplicableLevel())) {
                    try {
                        endpoint = new Endpoint.Builder(apiPublisher.getEndpoint(value.getId())).id("").build();
                        endpointSet.add(endpoint);
                    } catch (APIManagementException e) {
                        log.error("Error in getting endpoints for Resource: " + v.getTemplateId(), e);
                    }
                } else {
                    endpoint = new Endpoint.Builder(value).id("").build();
                }
                resourceEndpoints.replace(type, endpoint);
            });
            uriTemplateMap.replace(k, uriTemplateBuilder.endpoint(resourceEndpoints).build());
        });
        api = new API.APIBuilder(api).endpoint(endpoints).uriTemplates(uriTemplateMap).build();
        // get swagger definition
        String swaggerDefinition;
        try {
            swaggerDefinition = apiPublisher.getApiSwaggerDefinition(api.getId());
        } catch (APIManagementException e) {
            log.error("Error in getting Swagger configuration for api: " + api.getName() + ", version: " + api.getVersion(), e);
            // skip this API
            continue;
        }
        // get gateway configuration
        String gatewayConfig;
        try {
            gatewayConfig = apiPublisher.getApiGatewayConfig(api.getId());
        } catch (APIManagementException e) {
            log.error("Error in getting gateway configuration for api: " + api.getName() + ", version: " + api.getVersion(), e);
            // skip this API
            continue;
        }
        // get doc information
        List<DocumentInfo> documentInfo = null;
        try {
            documentInfo = apiPublisher.getAllDocumentation(api.getId(), 0, Integer.MAX_VALUE);
        } catch (APIManagementException e) {
            log.error("Error in getting documentation content for api: " + api.getName() + ", version: " + api.getVersion(), e);
        // no need to skip the API as docs don't affect API functionality
        }
        Set<DocumentContent> documentContents = new HashSet<>();
        if (documentInfo != null && !documentInfo.isEmpty()) {
            // iterate and collect document content
            for (DocumentInfo aDocumentInfo : documentInfo) {
                try {
                    documentContents.add(apiPublisher.getDocumentationContent(aDocumentInfo.getId()));
                } catch (APIManagementException e) {
                    log.error("Error in getting documentation content for api: " + api.getName() + ", version: " + api.getVersion() + ", doc id: " + aDocumentInfo.getId(), e);
                // no need to skip the API as docs don't affect API functionality
                }
            }
        }
        // get thumbnail
        InputStream thumbnailStream = null;
        try {
            thumbnailStream = apiPublisher.getThumbnailImage(api.getId());
        } catch (APIManagementException e) {
            log.error("Error in getting thumbnail for api: " + api.getName() + ", version: " + api.getVersion(), e);
        // no need to skip the API as thumbnail don't affect API functionality
        }
        // search operation returns a summary of APIs, need to get all details of APIs
        APIDetails apiDetails = new APIDetails(api, swaggerDefinition);
        apiDetails.setGatewayConfiguration(gatewayConfig);
        apiDetails.setEndpoints(endpointSet);
        if (documentInfo != null && !documentInfo.isEmpty()) {
            apiDetails.addDocumentInformation(documentInfo);
        }
        if (!documentContents.isEmpty()) {
            apiDetails.addDocumentContents(documentContents);
        }
        if (thumbnailStream != null) {
            apiDetails.setThumbnailStream(thumbnailStream);
        }
        apiDetailSet.add(apiDetails);
    }
    return apiDetailSet;
}
Also used : InputStream(java.io.InputStream) APIDetails(org.wso2.carbon.apimgt.core.models.APIDetails) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) DocumentContent(org.wso2.carbon.apimgt.core.models.DocumentContent) API(org.wso2.carbon.apimgt.core.models.API) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo)

Example 12 with Skip

use of org.wso2.carbon.humantask.core.engine.commands.Skip in project siddhi by wso2.

the class LengthWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    synchronized (this) {
        long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
            clonedEvent.setType(StreamEvent.Type.EXPIRED);
            if (count < length) {
                count++;
                this.expiredEventChunk.add(clonedEvent);
            } else {
                StreamEvent firstEvent = this.expiredEventChunk.poll();
                if (firstEvent != null) {
                    firstEvent.setTimestamp(currentTime);
                    streamEventChunk.insertBeforeCurrent(firstEvent);
                    this.expiredEventChunk.add(clonedEvent);
                } else {
                    StreamEvent resetEvent = streamEventCloner.copyStreamEvent(streamEvent);
                    resetEvent.setType(ComplexEvent.Type.RESET);
                    // adding resetEvent and clonedEvent event to the streamEventChunk
                    // since we are using insertAfterCurrent(), the final order will be
                    // currentEvent > clonedEvent (or expiredEvent) > resetEvent
                    streamEventChunk.insertAfterCurrent(resetEvent);
                    streamEventChunk.insertAfterCurrent(clonedEvent);
                    // since we manually added resetEvent and clonedEvent in earlier step
                    // we have to skip those two events from getting processed in the next
                    // iteration. Hence, calling next() twice.
                    streamEventChunk.next();
                    streamEventChunk.next();
                }
            }
        }
    }
    nextProcessor.process(streamEventChunk);
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 13 with Skip

use of org.wso2.carbon.humantask.core.engine.commands.Skip in project carbon-business-process by wso2.

the class TaskOperationsImpl method skip.

/**
 * Skip the task.
 * @param taskIdURI : task identifier
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public void skip(URI taskIdURI) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                Skip skipCommand = new Skip(getCaller(), taskId);
                skipCommand.execute();
                return null;
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : Skip(org.wso2.carbon.humantask.core.engine.commands.Skip) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Aggregations

API (org.wso2.carbon.apimgt.core.models.API)8 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)7 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)5 APIMgtEntityImportExportException (org.wso2.carbon.apimgt.core.exception.APIMgtEntityImportExportException)5 APIDetails (org.wso2.carbon.apimgt.core.models.APIDetails)5 DocumentContent (org.wso2.carbon.apimgt.core.models.DocumentContent)4 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)4 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 BXMLNSSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 File (java.io.File)1 Arrays (java.util.Arrays)1 LinkedList (java.util.LinkedList)1