use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project carbon-apimgt by wso2.
the class AbstractAPIManager method getAllGlobalMediationPolicies.
/**
* Returns list of global mediation policies available
*
* @return List of Mediation objects of global mediation policies
* @throws APIManagementException If failed to get global mediation policies
*/
@Override
public List<Mediation> getAllGlobalMediationPolicies() throws APIManagementException {
List<Mediation> mediationList = new ArrayList<Mediation>();
Mediation mediation;
String resourcePath = APIConstants.API_CUSTOM_SEQUENCE_LOCATION;
try {
// Resource : customsequences
Resource resource = registry.get(resourcePath);
if (resource instanceof Collection) {
Collection typeCollection = (Collection) resource;
String[] typeArray = typeCollection.getChildren();
for (String type : typeArray) {
// Resource : in / out / fault
Resource typeResource = registry.get(type);
if (typeResource instanceof Collection) {
String[] sequenceArray = ((Collection) typeResource).getChildren();
if (sequenceArray.length > 0) {
for (String sequence : sequenceArray) {
// Resource : actual resource eg : log_in_msg.xml
Resource sequenceResource = registry.get(sequence);
String resourceId = sequenceResource.getUUID();
try {
String contentString = IOUtils.toString(sequenceResource.getContentStream(), RegistryConstants.DEFAULT_CHARSET_ENCODING);
OMElement omElement = AXIOMUtil.stringToOM(contentString);
OMAttribute attribute = omElement.getAttribute(new QName(PolicyConstants.MEDIATION_NAME_ATTRIBUTE));
String mediationPolicyName = attribute.getAttributeValue();
mediation = new Mediation();
mediation.setUuid(resourceId);
mediation.setName(mediationPolicyName);
// Extract sequence type from the registry resource path
String resourceType = type.substring(type.lastIndexOf("/") + 1);
mediation.setType(resourceType);
// Add mediation to the mediation list
mediationList.add(mediation);
} catch (XMLStreamException e) {
// If any exception been caught flow may continue with the next mediation policy
log.error("Error occurred while getting omElement out of " + "mediation content from " + sequence, e);
} catch (IOException e) {
log.error("Error occurred while converting resource " + "contentStream in to string in " + sequence, e);
}
}
}
}
}
}
} catch (RegistryException e) {
String msg = "Failed to get global mediation policies";
throw new APIManagementException(msg, e);
}
return mediationList;
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project carbon-apimgt by wso2.
the class AbstractAPIManager method getGlobalMediationPolicy.
/**
* Return mediation policy corresponds to the given identifier
*
* @param mediationPolicyId uuid of the registry resource
* @return Mediation object related to the given identifier or null
* @throws APIManagementException If failed to get specified mediation policy
*/
@Override
public Mediation getGlobalMediationPolicy(String mediationPolicyId) throws APIManagementException {
Mediation mediation = null;
// Get registry resource correspond to identifier
Resource mediationResource = this.getCustomMediationResourceFromUuid(mediationPolicyId);
if (mediationResource != null) {
// Get mediation config details
try {
// extracting content stream of mediation policy in to string
String contentString = IOUtils.toString(mediationResource.getContentStream(), RegistryConstants.DEFAULT_CHARSET_ENCODING);
// Get policy name from the mediation config
OMElement omElement = AXIOMUtil.stringToOM(contentString);
OMAttribute attribute = omElement.getAttribute(new QName(PolicyConstants.MEDIATION_NAME_ATTRIBUTE));
String mediationPolicyName = attribute.getAttributeValue();
mediation = new Mediation();
mediation.setUuid(mediationResource.getUUID());
mediation.setName(mediationPolicyName);
String resourcePath = mediationResource.getPath();
// Extracting mediation type from the registry resource path
String[] path = resourcePath.split(RegistryConstants.PATH_SEPARATOR);
String resourceType = path[(path.length - 2)];
mediation.setType(resourceType);
mediation.setConfig(contentString);
} catch (RegistryException e) {
log.error("Error occurred while getting content stream of the ,mediation policy ", e);
} catch (IOException e) {
log.error("Error occurred while converting content stream of mediation policy " + "into string ", e);
} catch (XMLStreamException e) {
log.error("Error occurred while getting omElement out of mediation content ", e);
}
}
return mediation;
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project carbon-apimgt by wso2.
the class AbstractAPIManager method getAllApiSpecificMediationPolicies.
/**
* Returns a list of API specific mediation policies from registry
*
* @param apiIdentifier API identifier
* @return List of api specific mediation objects available
* @throws APIManagementException If unable to get mediation policies of specified API Id
*/
@Override
public List<Mediation> getAllApiSpecificMediationPolicies(APIIdentifier apiIdentifier) throws APIManagementException {
List<Mediation> mediationList = new ArrayList<Mediation>();
Mediation mediation;
String apiResourcePath = APIUtil.getAPIPath(apiIdentifier);
apiResourcePath = apiResourcePath.substring(0, apiResourcePath.lastIndexOf("/"));
try {
// Getting API registry resource
Resource resource = registry.get(apiResourcePath);
// resource eg: /_system/governance/apimgt/applicationdata/provider/admin/calculatorAPI/2.0
if (resource instanceof Collection) {
Collection typeCollection = (Collection) resource;
String[] typeArray = typeCollection.getChildren();
for (String type : typeArray) {
// Check for mediation policy sequences
if ((type.equalsIgnoreCase(apiResourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN)) || (type.equalsIgnoreCase(apiResourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT)) || (type.equalsIgnoreCase(apiResourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT))) {
Resource typeResource = registry.get(type);
// typeResource : in / out / fault
if (typeResource instanceof Collection) {
String[] mediationPolicyArr = ((Collection) typeResource).getChildren();
if (mediationPolicyArr.length > 0) {
for (String mediationPolicy : mediationPolicyArr) {
Resource policyResource = registry.get(mediationPolicy);
// policyResource eg: custom_in_message
// Get uuid of the registry resource
String resourceId = policyResource.getUUID();
// Get mediation policy config
try {
String contentString = IOUtils.toString(policyResource.getContentStream(), RegistryConstants.DEFAULT_CHARSET_ENCODING);
// Extract name from the policy config
OMElement omElement = AXIOMUtil.stringToOM(contentString);
OMAttribute attribute = omElement.getAttribute(new QName("name"));
String mediationPolicyName = attribute.getAttributeValue();
mediation = new Mediation();
mediation.setUuid(resourceId);
mediation.setName(mediationPolicyName);
// Extracting mediation policy type from the registry resource path
String resourceType = type.substring(type.lastIndexOf("/") + 1);
mediation.setType(resourceType);
mediationList.add(mediation);
} catch (XMLStreamException e) {
// If exception been caught flow will continue with next mediation policy
log.error("Error occurred while getting omElement out of" + " mediation content", e);
} catch (IOException e) {
log.error("Error occurred while converting the content " + "stream of mediation " + mediationPolicy + " to string", e);
}
}
}
}
}
}
}
} catch (RegistryException e) {
String msg = "Error occurred while getting Api Specific mediation policies ";
throw new APIManagementException(msg, e);
}
return mediationList;
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project ballerina by ballerina-lang.
the class CodeGenerator method createResourceInfoEntry.
private void createResourceInfoEntry(BLangResource resourceNode, ServiceInfo serviceInfo) {
BInvokableType resourceType = (BInvokableType) resourceNode.symbol.type;
// Add resource name as an UTFCPEntry to the constant pool
int serviceNameCPIndex = addUTF8CPEntry(currentPkgInfo, resourceNode.name.value);
ResourceInfo resourceInfo = new ResourceInfo(currentPackageRefCPIndex, serviceNameCPIndex);
resourceInfo.paramTypes = resourceType.paramTypes.toArray(new BType[0]);
setParameterNames(resourceNode, resourceInfo);
resourceInfo.retParamTypes = new BType[0];
resourceInfo.signatureCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(resourceInfo.paramTypes, resourceInfo.retParamTypes));
// Add worker info
int workerNameCPIndex = addUTF8CPEntry(currentPkgInfo, "default");
resourceInfo.defaultWorkerInfo = new WorkerInfo(workerNameCPIndex, "default");
resourceNode.workers.forEach(worker -> addWorkerInfoEntry(worker, resourceInfo));
// Add resource info to the service info
serviceInfo.resourceInfoMap.put(resourceNode.name.getValue(), resourceInfo);
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project charon by wso2.
the class ScimAttributeAware method replaceLocation.
/**
* sets or overrides the location attribute of the given {@link #getResource()} object
*
* @param resourceType the location attribute to write
*/
public void replaceLocation(String resourceType) {
SCIMAttributeSchema metaDefinition = SCIMSchemaDefinitions.META;
SCIMAttributeSchema locationDefinition = SCIMSchemaDefinitions.LOCATION;
ComplexAttribute meta = getOrCrateComplexAttribute(metaDefinition);
getSetSubAttributeConsumer(meta).accept(locationDefinition, () -> resourceType);
}
Aggregations