use of org.wso2.carbon.humantask.core.engine.commands.Skip in project ballerina by ballerina-lang.
the class CodeGenerator method generateURILookupInstructions.
private void generateURILookupInstructions(Map<Name, BXMLNSSymbol> namespaces, RegIndex localNameRegIndex, RegIndex uriRegIndex, RegIndex targetQNameRegIndex, DiagnosticPos pos, SymbolEnv symbolEnv) {
if (namespaces.isEmpty()) {
createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
return;
}
Stack<Operand> endJumpInstrStack = new Stack<>();
String prefix;
for (Entry<Name, BXMLNSSymbol> keyValues : namespaces.entrySet()) {
prefix = keyValues.getKey().getValue();
// skip the default namespace
if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
continue;
}
// Below section creates the condition to compare the namespace URIs
// store the comparing uri as string
BXMLNSSymbol nsSymbol = keyValues.getValue();
int opcode = getOpcode(TypeTags.STRING, InstructionCodes.IEQ);
RegIndex conditionExprIndex = getRegIndex(TypeTags.BOOLEAN);
emit(opcode, uriRegIndex, getNamespaceURIIndex(nsSymbol, symbolEnv), conditionExprIndex);
Operand ifCondJumpAddr = getOperand(-1);
emit(InstructionCodes.BR_FALSE, conditionExprIndex, ifCondJumpAddr);
// Below section creates instructions to be executed, if the above condition succeeds (then body)
// create the prefix literal
RegIndex prefixIndex = createStringLiteral(prefix, null, env);
// create a qname
emit(InstructionCodes.NEWQNAME, localNameRegIndex, uriRegIndex, prefixIndex, targetQNameRegIndex);
Operand endJumpAddr = getOperand(-1);
emit(InstructionCodes.GOTO, endJumpAddr);
endJumpInstrStack.add(endJumpAddr);
ifCondJumpAddr.value = nextIP();
}
// else part. create a qname with empty prefix
createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
while (!endJumpInstrStack.isEmpty()) {
endJumpInstrStack.pop().value = nextIP();
}
}
use of org.wso2.carbon.humantask.core.engine.commands.Skip in project carbon-apimgt by wso2.
the class FileBasedApiImportExportManager method exportAPIs.
/**
* Export a given set of APIs to the file system as a zip archive.
* The export root location is given by {@link FileBasedApiImportExportManager#path}/exported-apis.
*
* @param apiDetailSet Set of {@link APIDetails} objects to be exported
* @param exportDirectoryName Name of the directory to do the export
* @return Path to the directory with exported artifacts
* @throws APIMgtEntityImportExportException if an error occurred while exporting APIs to file system or
* no APIs are exported successfully
*/
public String exportAPIs(Set<APIDetails> apiDetailSet, String exportDirectoryName) throws APIMgtEntityImportExportException {
// this is the base directory for the archive. after export happens, this directory will
// be archived to be sent as a application/zip response to the client
String apiArtifactsBaseDirectoryPath = path + File.separator + exportDirectoryName;
try {
APIFileUtils.createDirectory(apiArtifactsBaseDirectoryPath);
} catch (APIMgtDAOException e) {
String errorMsg = "Unable to create directory for export API at :" + apiArtifactsBaseDirectoryPath;
throw new APIMgtEntityImportExportException(errorMsg, e);
}
for (APIDetails apiDetails : apiDetailSet) {
// derive the folder structure
String apiExportDirectory = APIFileUtils.getAPIBaseDirectory(apiArtifactsBaseDirectoryPath, new FileApi(apiDetails.getApi()));
API exportAPI = apiDetails.getApi();
try {
// create per-api export directory
APIFileUtils.createDirectory(apiExportDirectory);
// export API definition
APIFileUtils.exportApiDefinitionToFileSystem(new FileApi(exportAPI), apiExportDirectory);
// export swagger definition
APIFileUtils.exportSwaggerDefinitionToFileSystem(apiDetails.getSwaggerDefinition(), exportAPI, apiExportDirectory);
// export gateway configs
APIFileUtils.exportGatewayConfigToFileSystem(apiDetails.getGatewayConfiguration(), exportAPI, apiExportDirectory);
if (apiDetails.getEndpoints() != null && !apiDetails.getEndpoints().isEmpty()) {
exportEndpointsToFileSystem(apiDetails.getEndpoints(), exportAPI, apiExportDirectory);
}
} catch (APIMgtDAOException e) {
// no need to throw, log
log.error("Error in exporting API: " + exportAPI.getName() + ", version: " + apiDetails.getApi().getVersion(), e);
// cleanup the API directory
try {
APIFileUtils.deleteDirectory(path);
} catch (APIMgtDAOException e1) {
log.warn("Unable to remove directory " + path);
}
// skip this API
continue;
}
// as exported correctly.
if (apiDetails.getThumbnailStream() != null) {
try {
APIFileUtils.exportThumbnailToFileSystem(apiDetails.getThumbnailStream(), apiExportDirectory);
} catch (APIMgtDAOException warn) {
// log the warning without throwing
log.warn("Error in exporting thumbnail to file system for api: " + exportAPI.getName() + ", version: " + exportAPI.getVersion());
}
}
exportDocumentationToFileSystem(apiDetails.getAllDocumentInformation(), apiDetails, apiExportDirectory);
log.info("Successfully exported API: " + exportAPI.getName() + ", version: " + exportAPI.getVersion());
}
// if the directory is empty, no APIs have been exported!
try {
if (APIFileUtils.getDirectoryList(apiArtifactsBaseDirectoryPath).isEmpty()) {
// cleanup the archive root directory
APIFileUtils.deleteDirectory(path);
String errorMsg = "No APIs exported successfully";
throw new APIMgtEntityImportExportException(errorMsg, ExceptionCodes.API_EXPORT_ERROR);
}
} catch (APIMgtDAOException e) {
String errorMsg = "Unable to find API definitions at: " + apiArtifactsBaseDirectoryPath;
log.error(errorMsg, e);
throw new APIMgtEntityImportExportException(errorMsg, ExceptionCodes.API_IMPORT_ERROR);
}
return apiArtifactsBaseDirectoryPath;
}
use of org.wso2.carbon.humantask.core.engine.commands.Skip in project carbon-apimgt by wso2.
the class FileBasedApiImportExportManager method getApiDefinitionFromExtractedArchive.
/**
* Creates {@link APIDTO} instance from API Definition file
*
* @param apiDefinitionFilePath path to api definition file
* @return {@link APIDTO} instance
* @throws APIManagementException if an error occurs while creating API definition object
*/
private API getApiDefinitionFromExtractedArchive(String apiDefinitionFilePath) throws APIMgtEntityImportExportException {
String apiDefinitionString;
try {
apiDefinitionString = APIFileUtils.readFileContentAsText(apiDefinitionFilePath);
} catch (APIMgtDAOException e) {
// Unable to read the API definition file, skip this API
String errorMsg = "Error reading API definition from file at: " + apiDefinitionFilePath;
throw new APIMgtEntityImportExportException(errorMsg, e);
}
// convert to bean
Gson gson = new GsonBuilder().create();
try {
return new API.APIBuilder(gson.fromJson(apiDefinitionString, FileApi.class)).build();
} catch (Exception e) {
String errorMsg = "Error in building APIDTO from api definition read from file at: " + apiDefinitionFilePath;
throw new APIMgtEntityImportExportException(errorMsg, e);
}
}
use of org.wso2.carbon.humantask.core.engine.commands.Skip in project carbon-apimgt by wso2.
the class FileBasedApiImportExportManager method importAPIs.
/**
* Imports a set of APIs to API Manager by reading and decoding the input stream
*
* @param uploadedApiArchiveInputStream InputStream to be read ana decoded to a set of APIs
* @param provider API provider, if needs to be updated
* @return {@link APIListDTO} object comprising of successfully imported APIs
* @throws APIMgtEntityImportExportException if any error occurs while importing or no APIs are imported successfully
*/
public APIListDTO importAPIs(InputStream uploadedApiArchiveInputStream, String provider) throws APIMgtEntityImportExportException {
String apiArchiveLocation = path + File.separator + IMPORTED_APIS_DIRECTORY_NAME + ".zip";
String archiveExtractLocation = null;
try {
archiveExtractLocation = APIFileUtils.extractUploadedArchive(uploadedApiArchiveInputStream, IMPORTED_APIS_DIRECTORY_NAME, apiArchiveLocation, path);
} catch (APIMgtDAOException e) {
String errorMsg = "Error in accessing uploaded API archive " + apiArchiveLocation;
log.error(errorMsg, e);
throw new APIMgtEntityImportExportException(errorMsg, e, ExceptionCodes.API_IMPORT_ERROR);
}
// List to contain newly created/updated APIs
Set<APIDetails> apiDetailsSet = decodeApiInformationFromDirectoryStructure(archiveExtractLocation, provider);
List<API> apis = new ArrayList<>();
for (APIDetails apiDetails : apiDetailsSet) {
try {
apis.add(importApi(apiDetails));
} catch (APIManagementException e) {
log.error("Error while importing API: " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion());
// skip importing the API
continue;
}
log.info("Successfully imported API: " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion());
}
try {
APIFileUtils.deleteDirectory(path);
} catch (APIMgtDAOException e) {
log.warn("Unable to remove directory " + path);
}
// if no APIs are corrected exported, throw an error
if (apis.isEmpty()) {
String errorMsg = "No APIs imported successfully";
throw new APIMgtEntityImportExportException(errorMsg, ExceptionCodes.API_IMPORT_ERROR);
}
return MappingUtil.toAPIListDTO(apis);
}
use of org.wso2.carbon.humantask.core.engine.commands.Skip 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);
}
}
Aggregations