use of org.wso2.carbon.event.output.adapter.core.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.event.output.adapter.core.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.event.output.adapter.core.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;
}
use of org.wso2.carbon.event.output.adapter.core.Property in project carbon-business-process by wso2.
the class HistoricActivitiInstanceService method getHistoricActivityInstances.
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getHistoricActivityInstances(@Context UriInfo uriInfo) {
Map<String, String> allRequestParams = new HashMap<>();
for (String property : allPropertiesList) {
String value = uriInfo.getQueryParameters().getFirst(property);
if (value != null) {
allRequestParams.put(property, value);
}
}
HistoricActivityInstanceQueryRequest query = getHistoricActivityInstanceQueryRequest(uriInfo, allRequestParams);
DataResponse dataResponse = getQueryResponse(query, allRequestParams, uriInfo);
return Response.ok().entity(dataResponse).build();
}
use of org.wso2.carbon.event.output.adapter.core.Property in project carbon-business-process by wso2.
the class ProcessDefinitionFormPropertyService method getStartFormProperties.
@GET
@Path("/{processDefinitionId}/properties")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getStartFormProperties(@PathParam("processDefinitionId") String processDefinitionId) {
FormService formService = BPMNOSGIService.getFormService();
StartFormData startFormData = formService.getStartFormData(processDefinitionId);
FormPropertyResponseCollection formPropertyResponseCollection = new FormPropertyResponseCollection();
if (startFormData != null) {
List<FormProperty> properties = startFormData.getFormProperties();
List<FormPropertyResponse> formPropertyResponseList = new ArrayList<>();
for (FormProperty property : properties) {
// ObjectNode propertyJSON = objectMapper.createObjectNode();
FormPropertyResponse formPropertyResponse = new FormPropertyResponse();
formPropertyResponse.setId(property.getId());
formPropertyResponse.setName(property.getName());
if (property.getValue() != null) {
formPropertyResponse.setValue(property.getValue());
} else {
formPropertyResponse.setValue(null);
}
if (property.getType() != null) {
formPropertyResponse.setType(property.getType().getName());
if (property.getType() instanceof EnumFormType) {
@SuppressWarnings("unchecked") Map<String, String> valuesMap = (Map<String, String>) property.getType().getInformation("values");
if (valuesMap != null) {
List<FormPropertyEnumDataHolder> formPropertyEnumDataHoldersList = new ArrayList<>();
for (String key : valuesMap.keySet()) {
FormPropertyEnumDataHolder formPropertyEnumDataHolder = new FormPropertyEnumDataHolder();
formPropertyEnumDataHolder.setId(key);
formPropertyEnumDataHolder.setName(valuesMap.get(key));
formPropertyEnumDataHoldersList.add(formPropertyEnumDataHolder);
}
formPropertyResponse.setEnumValues(formPropertyEnumDataHoldersList);
}
}
} else {
formPropertyResponse.setType("String");
}
formPropertyResponse.setRequired(property.isRequired());
formPropertyResponse.setReadable(property.isReadable());
formPropertyResponse.setWritable(property.isWritable());
formPropertyResponseList.add(formPropertyResponse);
}
formPropertyResponseCollection.setData(formPropertyResponseList);
}
return Response.ok().entity(formPropertyResponseCollection).build();
}
Aggregations