Search in sources :

Example 61 with Collection

use of org.wso2.carbon.registry.core.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 62 with Collection

use of org.wso2.carbon.registry.core.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 63 with Collection

use of org.wso2.carbon.registry.core.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 64 with Collection

use of org.wso2.carbon.registry.core.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 65 with Collection

use of org.wso2.carbon.registry.core.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

Collection (org.wso2.carbon.registry.core.Collection)45 Resource (org.wso2.carbon.registry.core.Resource)39 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 Test (org.junit.Test)24 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)23 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)22 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)20 IOException (java.io.IOException)19 InputStream (java.io.InputStream)19 ArrayList (java.util.ArrayList)17 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)17 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)16 FileInputStream (java.io.FileInputStream)14 OMElement (org.apache.axiom.om.OMElement)13 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)13 Collection (java.util.Collection)11 CollectionImpl (org.wso2.carbon.registry.core.CollectionImpl)11 ResourceImpl (org.wso2.carbon.registry.core.ResourceImpl)11 File (java.io.File)10