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);
}
}
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());
}
}
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);
}
}
}
}
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;
}
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();
}
Aggregations