Search in sources :

Example 31 with Collection

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

the class ApiImportExportManager method updateAPIDetails.

/**
 * Updates the API details
 *
 * @param apiDetails {@link APIDetails} instance
 * @throws APIManagementException if an error occurs while updating API details
 */
void updateAPIDetails(APIDetails apiDetails) throws APIManagementException {
    // update everything
    String swaggerDefinition = apiDetails.getSwaggerDefinition();
    String gatewayConfig = apiDetails.getGatewayConfiguration();
    Map<String, Endpoint> endpointTypeToIdMap = new HashMap<>();
    // endpoints
    for (Endpoint endpoint : apiDetails.getEndpoints()) {
        try {
            apiPublisher.updateEndpoint(endpoint);
            endpointTypeToIdMap.put(endpoint.getType(), endpoint);
        } catch (APIManagementException e) {
            // skip updating this API, log and continue
            log.error("Error while updating the endpoint with id: " + endpoint.getId() + ", type: " + endpoint.getType() + " for API: " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion());
        }
    }
    API.APIBuilder apiBuilder = new API.APIBuilder(apiDetails.getApi());
    apiPublisher.updateAPI(apiBuilder.apiDefinition(swaggerDefinition).gatewayConfig(gatewayConfig).endpoint(endpointTypeToIdMap));
    // docs
    try {
        Set<DocumentInfo> documentInfo = apiDetails.getAllDocumentInformation();
        for (DocumentInfo aDocInfo : documentInfo) {
            apiPublisher.updateDocumentation(aDocInfo.getId(), aDocInfo);
        }
        Collection<DocumentContent> docContents = apiDetails.getDocumentContents();
        for (DocumentContent docContent : docContents) {
            // update documentation
            if (docContent.getDocumentInfo().getSourceType().equals(DocumentInfo.SourceType.FILE)) {
                apiPublisher.uploadDocumentationFile(docContent.getDocumentInfo().getId(), docContent.getFileContent(), URLConnection.guessContentTypeFromStream(docContent.getFileContent()));
            } else if (docContent.getDocumentInfo().getSourceType().equals(DocumentInfo.SourceType.INLINE)) {
                apiPublisher.addDocumentationContent(docContent.getDocumentInfo().getId(), docContent.getInlineContent());
            }
        }
    } catch (APIManagementException e) {
        // no need to throw, log and continue
        log.error("Error while adding Document details for API: " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion(), e);
    } catch (IOException e) {
        // no need to throw, log and continue
        log.error("Error while retrieving content type of the File documentation of API : " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion(), e);
    }
    // update thumbnail
    try {
        apiPublisher.saveThumbnailImage(apiDetails.getApi().getId(), apiDetails.getThumbnailStream(), "thumbnail");
    } catch (APIManagementException e) {
        // no need to throw, log and continue
        log.error("Error while updating thumbnail for API: " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion(), e);
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) 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) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo)

Example 32 with Collection

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

the class CollectionExpressionParser method buildMultiPrimaryKeyExpressionExecutors.

private static Map<String, ExpressionExecutor> buildMultiPrimaryKeyExpressionExecutors(CollectionExpression collectionExpression, MatchingMetaInfoHolder matchingMetaInfoHolder, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, SiddhiAppContext siddhiAppContext, String queryName) {
    if (collectionExpression instanceof AndMultiPrimaryKeyCollectionExpression) {
        CollectionExpression leftCollectionExpression = ((AndMultiPrimaryKeyCollectionExpression) collectionExpression).getLeftCollectionExpression();
        CollectionExpression rightCollectionExpression = ((AndMultiPrimaryKeyCollectionExpression) collectionExpression).getRightCollectionExpression();
        Map<String, ExpressionExecutor> expressionExecutors = buildMultiPrimaryKeyExpressionExecutors(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, queryName);
        expressionExecutors.putAll(buildMultiPrimaryKeyExpressionExecutors(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, queryName));
        return expressionExecutors;
    } else if (collectionExpression instanceof AndCollectionExpression) {
        CollectionExpression leftCollectionExpression = ((AndCollectionExpression) collectionExpression).getLeftCollectionExpression();
        CollectionExpression rightCollectionExpression = ((AndCollectionExpression) collectionExpression).getLeftCollectionExpression();
        Map<String, ExpressionExecutor> expressionExecutors = buildMultiPrimaryKeyExpressionExecutors(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, queryName);
        expressionExecutors.putAll(buildMultiPrimaryKeyExpressionExecutors(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, queryName));
        return expressionExecutors;
    } else if (collectionExpression instanceof CompareCollectionExpression) {
        if (((CompareCollectionExpression) collectionExpression).getOperator() == Compare.Operator.EQUAL) {
            CollectionExpression attributeCollectionExpression = ((CompareCollectionExpression) collectionExpression).getAttributeCollectionExpression();
            if (attributeCollectionExpression instanceof AttributeCollectionExpression) {
                String attribue = ((AttributeCollectionExpression) attributeCollectionExpression).getAttribute();
                CollectionExpression valueCollectionExpression = ((CompareCollectionExpression) collectionExpression).getValueCollectionExpression();
                ExpressionExecutor valueExpressionExecutor = ExpressionParser.parseExpression(valueCollectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
                Map<String, ExpressionExecutor> expressionExecutors = new HashMap<String, ExpressionExecutor>();
                expressionExecutors.put(attribue, valueExpressionExecutor);
                return expressionExecutors;
            } else {
                throw new SiddhiAppCreationException("Only attribute EQUAL " + "comparision supported for multiple primary key optimization, " + "but found  '" + attributeCollectionExpression.getClass() + "'", collectionExpression.getExpression().getQueryContextStartIndex(), collectionExpression.getExpression().getQueryContextEndIndex());
            }
        } else {
            throw new SiddhiAppCreationException("Only '" + Compare.Operator.EQUAL + "' supported for multiple " + "primary key for multiple primary key optimization, but found '" + ((CompareCollectionExpression) collectionExpression).getOperator() + "'", collectionExpression.getExpression().getQueryContextStartIndex(), collectionExpression.getExpression().getQueryContextEndIndex());
        }
    } else {
        // Attribute Collection
        throw new SiddhiAppCreationException("Only 'AND' and '" + Compare.Operator.EQUAL + "' operators are " + "supported for multiple primary key optimization, but found '" + ((CompareCollectionExpression) collectionExpression).getOperator() + "'", collectionExpression.getExpression().getQueryContextStartIndex(), collectionExpression.getExpression().getQueryContextEndIndex());
    }
}
Also used : VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) CompareCollectionExpression(org.wso2.siddhi.core.util.collection.expression.CompareCollectionExpression) HashMap(java.util.HashMap) AndCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndCollectionExpression) AttributeCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AttributeCollectionExpression) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) AndMultiPrimaryKeyCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) NotCollectionExpression(org.wso2.siddhi.core.util.collection.expression.NotCollectionExpression) AndCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndCollectionExpression) BasicCollectionExpression(org.wso2.siddhi.core.util.collection.expression.BasicCollectionExpression) CompareCollectionExpression(org.wso2.siddhi.core.util.collection.expression.CompareCollectionExpression) CollectionExpression(org.wso2.siddhi.core.util.collection.expression.CollectionExpression) OrCollectionExpression(org.wso2.siddhi.core.util.collection.expression.OrCollectionExpression) AttributeCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AttributeCollectionExpression) AndMultiPrimaryKeyCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) NullCollectionExpression(org.wso2.siddhi.core.util.collection.expression.NullCollectionExpression) Map(java.util.Map) HashMap(java.util.HashMap)

Example 33 with Collection

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

the class CollectionOperator method delete.

@Override
public void delete(ComplexEventChunk<StateEvent> deletingEventChunk, Object storeEvents) {
    if (((Collection<StreamEvent>) storeEvents).size() > 0) {
        deletingEventChunk.reset();
        while (deletingEventChunk.hasNext()) {
            StateEvent deletingEvent = deletingEventChunk.next();
            try {
                for (Iterator<StreamEvent> iterator = ((Collection<StreamEvent>) storeEvents).iterator(); iterator.hasNext(); ) {
                    StreamEvent storeEvent = iterator.next();
                    deletingEvent.setEvent(storeEventPosition, storeEvent);
                    if ((Boolean) expressionExecutor.execute(deletingEvent)) {
                        iterator.remove();
                    }
                }
            } finally {
                deletingEvent.setEvent(storeEventPosition, null);
            }
        }
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) Collection(java.util.Collection) StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Example 34 with Collection

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

the class CollectionOperator method tryUpdate.

@Override
public ComplexEventChunk<StreamEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    updatingOrAddingEventChunk.reset();
    ComplexEventChunk<StreamEvent> failedEventChunk = new ComplexEventChunk<StreamEvent>(updatingOrAddingEventChunk.isBatch());
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent updateOrAddingEvent = updatingOrAddingEventChunk.next();
        try {
            boolean updated = false;
            if (((Collection<StreamEvent>) storeEvents).size() > 0) {
                for (StreamEvent storeEvent : ((Collection<StreamEvent>) storeEvents)) {
                    updateOrAddingEvent.setEvent(storeEventPosition, storeEvent);
                    if ((Boolean) expressionExecutor.execute(updateOrAddingEvent)) {
                        for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                            storeEvent.setOutputData(entry.getValue().execute(updateOrAddingEvent), entry.getKey());
                        }
                        updated = true;
                    }
                }
            }
            if (!updated) {
                failedEventChunk.add(addingStreamEventExtractor.getAddingStreamEvent(updateOrAddingEvent));
            }
        } finally {
            updateOrAddingEvent.setEvent(storeEventPosition, null);
        }
    }
    return failedEventChunk;
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StateEvent(org.wso2.siddhi.core.event.state.StateEvent) Map(java.util.Map)

Example 35 with Collection

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

the class CollectionOperator method find.

@Override
public StreamEvent find(StateEvent matchingEvent, Object storeEvents, StreamEventCloner storeEventCloner) {
    ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<StreamEvent>(false);
    for (StreamEvent storeEvent : (Collection<StreamEvent>) storeEvents) {
        matchingEvent.setEvent(storeEventPosition, storeEvent);
        if ((Boolean) expressionExecutor.execute(matchingEvent)) {
            returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
        }
        matchingEvent.setEvent(storeEventPosition, null);
    }
    return returnEventChunk.getFirst();
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) Collection(java.util.Collection)

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