use of org.wso2.carbon.identity.application.common.model.Property in project carbon-apimgt by wso2.
the class ApiStoreSdkGenerationManager method generateSdkForApi.
/*
* This method generates the client side SDK for the API with API ID (apiID) and SDK language (language)
*
* @param apiId ID for the specific API
* @param language preferred language to generate the SDK
* @throws ApiStoreSdkGenerationException if failed to generate the SDK
* */
public String generateSdkForApi(String apiId, String language, String userName) throws ApiStoreSdkGenerationException, APIManagementException {
APIStore apiStore = APIManagerFactory.getInstance().getAPIConsumer(userName);
API api = apiStore.getAPIbyUUID(apiId);
if (api == null) {
String errorMessage = "Cannot find API for specified API ID";
throw new APIManagementException(errorMessage, ExceptionCodes.API_NOT_FOUND);
}
String apiName = api.getName();
String apiVersion = api.getVersion();
String swaggerDefinitionForApi = null;
try {
swaggerDefinitionForApi = apiStore.getApiSwaggerDefinition(apiId);
} catch (APIManagementException e) {
handleSdkGenException("Error retrieving swagger definition for API " + apiId + " from database.", e);
}
Swagger swaggerDoc = new SwaggerParser().parse(swaggerDefinitionForApi);
if (swaggerDoc == null) {
handleSdkGenException("Error while parsing retrieved swagger definition");
}
// Format the swagger definition as a string before writing to the file.
String formattedSwaggerDefinitionForSdk = Json.pretty(swaggerDoc);
Path tempSdkGenDir = null;
File swaggerDefJsonFile = null;
try {
// Create a temporary directory to store the API files
tempSdkGenDir = Files.createTempDirectory(apiName + "_" + language + "_" + apiVersion);
// Create a temporary file to store the swagger definition
swaggerDefJsonFile = Files.createTempFile(tempSdkGenDir, apiId + "_" + language, APIMgtConstants.APIFileUtilConstants.JSON_EXTENSION).toFile();
} catch (IOException e) {
handleSdkGenException("Error creating temporary directory or json file for swagger definition!", e);
}
String tempZipFilePath = "";
if (swaggerDefJsonFile.exists()) {
try (Writer swaggerFileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(swaggerDefJsonFile.getAbsoluteFile()), "UTF-8"))) {
swaggerFileWriter.write(formattedSwaggerDefinitionForSdk);
log.debug("Writing the swagger definition was sucessful to file {}", swaggerDefJsonFile.getAbsolutePath());
} catch (IOException e) {
handleSdkGenException("Error writing swagger definition to file in " + tempSdkGenDir, e);
}
// Generate the SDK for the specified language
generateSdkForSwaggerDef(language, swaggerDefJsonFile.getAbsolutePath(), tempSdkGenDir.toString());
log.debug("Generating SDK for the swagger definition {} was successful.", swaggerDefJsonFile.getAbsolutePath());
String archiveName = apiName + "_" + language + "_" + apiVersion;
tempZipFilePath = tempSdkGenDir + File.separator + archiveName + ".zip";
APIFileUtils.archiveDirectory(tempSdkGenDir.toString(), tempSdkGenDir.toString(), archiveName);
log.debug("Generating the archive was successful for directory {}.", tempSdkGenDir.toString());
} else {
handleSdkGenException("Swagger definition file not found!");
}
try {
// Set deleteOnExit property to generated SDK directory, all sub directories and files.
recursiveDeleteOnExit(tempSdkGenDir);
} catch (IOException e) {
handleSdkGenException("Error while deleting temporary directory " + tempSdkGenDir, e);
}
return tempZipFilePath;
}
use of org.wso2.carbon.identity.application.common.model.Property in project carbon-apimgt by wso2.
the class APIStoreImpl method updateCompositeApi.
/**
* {@inheritDoc}
*/
@Override
public void updateCompositeApi(CompositeAPI.Builder apiBuilder) throws APIManagementException {
apiBuilder.provider(getUsername());
apiBuilder.updatedBy(getUsername());
CompositeAPI originalAPI = getApiDAO().getCompositeAPI(apiBuilder.getId());
apiBuilder.createdTime(originalAPI.getCreatedTime());
// workflow status is an internal property and shouldn't be allowed to update externally
apiBuilder.workflowStatus(originalAPI.getWorkflowStatus());
APIUtils.verifyValidityOfApiUpdate(apiBuilder, originalAPI);
try {
String updatedSwagger = apiDefinitionFromSwagger20.generateSwaggerFromResources(apiBuilder);
InputStream gatewayConfig = getApiDAO().getCompositeAPIGatewayConfig(apiBuilder.getId());
GatewaySourceGenerator gatewaySourceGenerator = getGatewaySourceGenerator();
APIConfigContext apiConfigContext = new APIConfigContext(apiBuilder.build(), config.getGatewayPackageName());
gatewaySourceGenerator.setApiConfigContext(apiConfigContext);
String updatedGatewayConfig = gatewaySourceGenerator.getGatewayConfigFromSwagger(IOUtils.toString(gatewayConfig, StandardCharsets.UTF_8), updatedSwagger);
CompositeAPI api = apiBuilder.build();
if (originalAPI.getContext() != null && !originalAPI.getContext().equals(apiBuilder.getContext())) {
if (isContextExist(api.getContext())) {
throw new APIManagementException("Context already Exist", ExceptionCodes.API_ALREADY_EXISTS);
}
}
// publishing config to gateway
gateway.addCompositeAPI(api);
getApiDAO().updateApiDefinition(api.getId(), updatedSwagger, api.getUpdatedBy());
getApiDAO().updateCompositeAPIGatewayConfig(api.getId(), new ByteArrayInputStream(updatedGatewayConfig.getBytes(StandardCharsets.UTF_8)), api.getUpdatedBy());
if (log.isDebugEnabled()) {
log.debug("API " + api.getName() + "-" + api.getVersion() + " was updated successfully.");
}
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while updating the API - " + apiBuilder.getName();
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
} catch (IOException e) {
String errorMsg = "Error occurred while reading gateway configuration the API - " + apiBuilder.getName();
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, ExceptionCodes.APIMGT_DAO_EXCEPTION);
}
}
use of org.wso2.carbon.identity.application.common.model.Property in project wso2-synapse by wso2.
the class EventSourceSerializer method serializeEventSource.
public static OMElement serializeEventSource(OMElement elem, SynapseEventSource eventSource) {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace nullNS = fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");
OMElement evenSourceElem = fac.createOMElement("eventSource", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
if (eventSource.getName() != null) {
evenSourceElem.addAttribute(fac.createOMAttribute("name", nullNS, eventSource.getName()));
}
if (eventSource.getSubscriptionManager() != null) {
OMElement subManagerElem = fac.createOMElement("subscriptionManager", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
subManagerElem.addAttribute(fac.createOMAttribute("class", nullNS, eventSource.getSubscriptionManager().getClass().getName()));
Collection<String> names = (Collection<String>) eventSource.getSubscriptionManager().getPropertyNames();
for (String name : names) {
String value;
if (eventSource.isContainsConfigurationProperty(name)) {
value = eventSource.getConfigurationProperty(name);
} else {
value = eventSource.getSubscriptionManager().getPropertyValue(name);
}
OMElement propElem = fac.createOMElement("property", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
propElem.addAttribute(fac.createOMAttribute("name", nullNS, name));
propElem.addAttribute(fac.createOMAttribute("value", nullNS, value));
subManagerElem.addChild(propElem);
}
evenSourceElem.addChild(subManagerElem);
// Adding static subscriptions
List<Subscription> staticSubscriptionList = eventSource.getSubscriptionManager().getStaticSubscriptions();
for (Iterator<Subscription> iterator = staticSubscriptionList.iterator(); iterator.hasNext(); ) {
Subscription staticSubscription = iterator.next();
OMElement staticSubElem = fac.createOMElement("subscription", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
staticSubElem.addAttribute(fac.createOMAttribute("id", nullNS, staticSubscription.getId()));
OMElement filterElem = fac.createOMElement("filter", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
filterElem.addAttribute(fac.createOMAttribute("source", nullNS, (String) staticSubscription.getFilterValue()));
filterElem.addAttribute(fac.createOMAttribute("dialect", nullNS, (String) staticSubscription.getFilterDialect()));
staticSubElem.addChild(filterElem);
OMElement endpointElem = fac.createOMElement("endpoint", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
OMElement addressElem = fac.createOMElement("address", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
addressElem.addAttribute(fac.createOMAttribute("uri", nullNS, staticSubscription.getEndpointUrl()));
endpointElem.addChild(addressElem);
staticSubElem.addChild(endpointElem);
if (staticSubscription.getExpires() != null) {
OMElement expiresElem = fac.createOMElement("expires", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
fac.createOMText(expiresElem, ConverterUtil.convertToString(staticSubscription.getExpires()));
staticSubElem.addChild(expiresElem);
}
evenSourceElem.addChild(staticSubElem);
}
}
if (elem != null) {
elem.addChild(evenSourceElem);
}
return evenSourceElem;
}
use of org.wso2.carbon.identity.application.common.model.Property in project wso2-synapse by wso2.
the class EventSourceSerializerTest method testSerializeEvent4.
/**
* Test SerialEvent and assert OMElement returned is not null.
*
* @throws XMLStreamException - XMLStreamException
* @throws EventException - EventException
*/
@Test
public void testSerializeEvent4() throws XMLStreamException, EventException {
String inputXML = " <eventSource name=\"SampleEventSource\" xmlns=\"http://ws.apache.org/ns/synapse\">\n" + " <subscriptionManager class=\"org.apache.synapse.eventing.managers." + "DefaultInMemorySubscriptionManager\">\n" + " <property name=\"topicHeaderName\" value=\"Topic\"/>\n" + " <property name=\"topicHeaderNS\" value=\"http://apache.org/aip\"/>\n" + " </subscriptionManager>\n" + " <subscription id=\"mySubscription\">\n" + " <filter source =\"synapse/event/test\" dialect=\"http://synapse.apache.org/" + "eventing/dialect/topicFilter\"/>\n" + " <endpoint><address uri=\"http://localhost:9000/services/" + "SimpleStockQuoteService\"/></endpoint>\n" + " </subscription>\n" + " <subscription id=\"mySubscription2\">\n" + " <filter source =\"synapse/event/test\" dialect=\"http://synapse.apache.org/" + "eventing/dialect/topicFilter\"/>\n" + " <endpoint><address uri=\"http://localhost:9000/services/" + "SimpleStockQuoteService\"/></endpoint>\n" + " <expires>2020-06-27T21:07:00.000-08:00</expires>\n" + " </subscription>\n" + " </eventSource>\n";
OMElement element = AXIOMUtil.stringToOM(inputXML);
SynapseEventSource synapseEventSource = new SynapseEventSource("Test");
SubscriptionManager subscriptionManager = new DefaultInMemorySubscriptionManager();
subscriptionManager.addProperty("Name", "Test");
SynapseSubscription synapseSubscription = new SynapseSubscription();
synapseSubscription.setStaticEntry(true);
Date date = new Date(System.currentTimeMillis() + 3600000);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
synapseSubscription.setExpires(cal);
subscriptionManager.subscribe(synapseSubscription);
synapseEventSource.setSubscriptionManager(subscriptionManager);
OMElement omElement = EventSourceSerializer.serializeEventSource(element, synapseEventSource);
Assert.assertNotNull("OMElement cannot be null.", omElement);
}
use of org.wso2.carbon.identity.application.common.model.Property in project carbon-business-process by wso2.
the class ProcessManagementServiceSkeleton method getProcessDeploymentInfo.
/* The methods gets data from ProcessConfigurationImpl and display the details
* @param pid
* @return processDeployDetailsList
*
*/
public ProcessDeployDetailsList_type0 getProcessDeploymentInfo(QName pid) {
/* Configuring process basic information*/
ProcessDeployDetailsList processDeployDetailsList = new ProcessDeployDetailsList();
ProcessDeployDetailsList_type0 processDeployDetailsListType = new ProcessDeployDetailsList_type0();
TenantProcessStoreImpl tenantProcessStore = AdminServiceUtils.getTenantProcessStore();
ProcessConf processConf = tenantProcessStore.getProcessConfiguration(pid);
ProcessConfigurationImpl processConfiguration = (ProcessConfigurationImpl) processConf;
QName processId = processConfiguration.getProcessId();
processDeployDetailsListType.setProcessName(processId);
ProcessStatus processStatus = ProcessStatus.Factory.fromValue(processConfiguration.getState().name());
processDeployDetailsListType.setProcessState(processStatus);
processDeployDetailsListType.setIsInMemory(processConfiguration.isTransient());
/* Configuring invoked services by the process*/
List<TInvoke> invokeList = processConfiguration.getInvokedServices();
if (invokeList != null) {
InvokeServiceListType ist = new InvokeServiceListType();
for (TInvoke invoke : invokeList) {
InvokedServiceType invokedServiceType = new InvokedServiceType();
Service_type1 service = new Service_type1();
service.setName(invoke.getService().getName());
service.setPort(invoke.getService().getPort());
invokedServiceType.setService(service);
invokedServiceType.setPartnerLink(invoke.getPartnerLink());
ist.addInvokedService(invokedServiceType);
processDeployDetailsListType.setInvokeServiceList(ist);
}
}
/* Configuring providing services by the process*/
List<TProvide> provideList = processConfiguration.getProvidedServices();
if (provideList != null) {
ProvideServiceListType pst = new ProvideServiceListType();
for (TProvide provide : provideList) {
ProvidedServiceType providedServiceType = new ProvidedServiceType();
Service_type0 service = new Service_type0();
service.setName(provide.getService().getName());
service.setPort(provide.getService().getPort());
providedServiceType.setService(service);
providedServiceType.setPartnerLink(provide.getPartnerLink());
pst.addProvidedService(providedServiceType);
}
processDeployDetailsListType.setProvideServiceList(pst);
}
/* Configuring message exchange interceptors of the process*/
MexInterpreterListType mxt = new MexInterpreterListType();
List<String> mexInterceptor = processConfiguration.getMexInterceptors();
if (mexInterceptor != null) {
for (String mexInt : mexInterceptor) {
mxt.addMexinterpreter(mexInt);
}
}
processDeployDetailsListType.setMexInterperterList(mxt);
/* Configuring process level and scope level enabled events of process*/
Map<String, Set<BpelEvent.TYPE>> eventsMap = processConfiguration.getEvents();
ProcessEventsListType processEventsListType = new ProcessEventsListType();
EnableEventListType enableEventListType = new EnableEventListType();
ScopeEventListType scopeEventListType = new ScopeEventListType();
for (Map.Entry<String, Set<BpelEvent.TYPE>> eventEntry : eventsMap.entrySet()) {
if (eventEntry.getKey() != null) {
ScopeEventType scopeEvent = new ScopeEventType();
String scopeName = eventEntry.getKey();
EnableEventListType enableEventList = new EnableEventListType();
Set<BpelEvent.TYPE> typeSetforScope = eventEntry.getValue();
for (BpelEvent.TYPE type : typeSetforScope) {
enableEventList.addEnableEvent(type.toString());
}
scopeEvent.setScope(scopeName);
scopeEvent.setEnabledEventList(enableEventList);
scopeEventListType.addScopeEvent(scopeEvent);
} else {
Set<BpelEvent.TYPE> typeSet = eventEntry.getValue();
for (BpelEvent.TYPE aTypeSet : typeSet) {
enableEventListType.addEnableEvent(aTypeSet.toString());
}
}
}
TProcessEvents.Generate.Enum genEnum = processConfiguration.getGenerateType();
if (genEnum != null) {
Generate_type1 generate = Generate_type1.Factory.fromValue(genEnum.toString());
processEventsListType.setGenerate(generate);
}
processEventsListType.setEnableEventsList(enableEventListType);
processEventsListType.setScopeEventsList(scopeEventListType);
processDeployDetailsListType.setProcessEventsList(processEventsListType);
// end of process events
/* configuring properties defined in the process */
PropertyListType propertyListType = new PropertyListType();
Map<QName, Node> propertiesMap = processConfiguration.getProcessProperties();
Set<Map.Entry<QName, Node>> entries = propertiesMap.entrySet();
for (Map.Entry entry : entries) {
ProcessProperty_type0 property = new ProcessProperty_type0();
property.setName((QName) entry.getKey());
Node node = (Node) entry.getValue();
property.setValue(DOMUtils.domToStringLevel2(node));
propertyListType.addProcessProperty(property);
}
processDeployDetailsListType.setPropertyList(propertyListType);
CleanUpListType cleanUpList = new CleanUpListType();
Set<ProcessConf.CLEANUP_CATEGORY> sucessTypeCleanups = processConfiguration.getCleanupCategories(true);
Set<ProcessConf.CLEANUP_CATEGORY> failureTypeCleanups = processConfiguration.getCleanupCategories(false);
if (sucessTypeCleanups != null) {
CleanUpType cleanUp = new CleanUpType();
On_type1 onType = On_type1.success;
cleanUp.setOn(onType);
CategoryListType categoryListType = new CategoryListType();
for (ProcessConf.CLEANUP_CATEGORY sCategory : sucessTypeCleanups) {
Category_type1 categoryType1 = Category_type1.Factory.fromValue(sCategory.name().toLowerCase());
categoryListType.addCategory(categoryType1);
}
cleanUp.setCategoryList(categoryListType);
cleanUpList.addCleanUp(cleanUp);
}
if (failureTypeCleanups != null) {
CleanUpType cleanUp = new CleanUpType();
On_type1 onType = On_type1.failure;
cleanUp.setOn(onType);
CategoryListType categoryListType = new CategoryListType();
for (ProcessConf.CLEANUP_CATEGORY fCategory : failureTypeCleanups) {
Category_type1 categoryType1 = Category_type1.Factory.fromValue(fCategory.name().toLowerCase());
categoryListType.addCategory(categoryType1);
}
cleanUp.setCategoryList(categoryListType);
cleanUpList.addCleanUp(cleanUp);
}
processDeployDetailsListType.setCleanUpList(cleanUpList);
processDeployDetailsList.setProcessDeployDetailsList(processDeployDetailsListType);
return processDeployDetailsListType;
}
Aggregations