use of org.wso2.carbon.identity.application.common.model.xsd.Property in project jaggery by wso2.
the class ResourceHostObject method jsGet_content.
public Object jsGet_content() throws ScriptException {
try {
Object result = this.resource.getContent();
String mediaType = this.resource.getMediaType();
if (result instanceof byte[]) {
// if mediaType is xml related one, we return an e4x xml object
if (mediaType != null) {
if (mediaType.matches(".*[\\/].*[xX][mM][lL].*")) {
return context.newObject(this, "XML", new Object[] { new String((byte[]) result) });
}
}
return new String((byte[]) result);
} else if (result instanceof String[]) {
String[] content = (String[]) result;
return context.newArray(this, Arrays.copyOf(content, content.length, Object[].class));
} else {
return Context.toObject(result, this);
}
} catch (RegistryException e) {
throw new ScriptException("Registry Exception while reading content property", e);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.Property in project carbon-apimgt by wso2.
the class AbstractAPIManager method searchPaginatedAPIsByContent.
/**
* Search api resources by their content
*
* @param registry
* @param searchQuery
* @param start
* @param end
* @return
* @throws APIManagementException
*/
public Map<String, Object> searchPaginatedAPIsByContent(Registry registry, int tenantId, String searchQuery, int start, int end, boolean limitAttributes) throws APIManagementException {
SortedSet<API> apiSet = new TreeSet<API>(new APINameComparator());
SortedSet<APIProduct> apiProductSet = new TreeSet<APIProduct>(new APIProductNameComparator());
Map<Documentation, API> docMap = new HashMap<Documentation, API>();
Map<Documentation, APIProduct> productDocMap = new HashMap<Documentation, APIProduct>();
Map<String, Object> result = new HashMap<String, Object>();
int totalLength = 0;
boolean isMore = false;
// SortedSet<Object> compoundResult = new TreeSet<Object>(new ContentSearchResultNameComparator());
ArrayList<Object> compoundResult = new ArrayList<Object>();
try {
GenericArtifactManager apiArtifactManager = APIUtil.getArtifactManager(registry, APIConstants.API_KEY);
GenericArtifactManager docArtifactManager = APIUtil.getArtifactManager(registry, APIConstants.DOCUMENTATION_KEY);
String paginationLimit = getAPIManagerConfiguration().getFirstProperty(APIConstants.API_STORE_APIS_PER_PAGE);
// If the Config exists use it to set the pagination limit
final int maxPaginationLimit;
if (paginationLimit != null) {
// The additional 1 added to the maxPaginationLimit is to help us determine if more
// APIs may exist so that we know that we are unable to determine the actual total
// API count. We will subtract this 1 later on so that it does not interfere with
// the logic of the rest of the application
int pagination = Integer.parseInt(paginationLimit);
// leading to some of the APIs not being displayed
if (pagination < 11) {
pagination = 11;
log.warn("Value of '" + APIConstants.API_STORE_APIS_PER_PAGE + "' is too low, defaulting to 11");
}
maxPaginationLimit = start + pagination + 1;
} else // Else if the config is not specified we go with default functionality and load all
{
maxPaginationLimit = Integer.MAX_VALUE;
}
PaginationContext.init(start, end, "ASC", APIConstants.API_OVERVIEW_NAME, maxPaginationLimit);
if (tenantId == -1) {
tenantId = MultitenantConstants.SUPER_TENANT_ID;
}
UserRegistry systemUserRegistry = ServiceReferenceHolder.getInstance().getRegistryService().getRegistry(CarbonConstants.REGISTRY_SYSTEM_USERNAME, tenantId);
ContentBasedSearchService contentBasedSearchService = new ContentBasedSearchService();
String newSearchQuery = getSearchQuery(searchQuery);
String[] searchQueries = newSearchQuery.split("&");
String apiState = "";
String publisherRoles = "";
Map<String, String> attributes = new HashMap<String, String>();
for (String searchCriterea : searchQueries) {
String[] keyVal = searchCriterea.split("=");
if (APIConstants.STORE_VIEW_ROLES.equals(keyVal[0])) {
attributes.put("propertyName", keyVal[0]);
attributes.put("rightPropertyValue", keyVal[1]);
attributes.put("rightOp", "eq");
} else if (APIConstants.PUBLISHER_ROLES.equals(keyVal[0])) {
publisherRoles = keyVal[1];
} else {
if (APIConstants.LCSTATE_SEARCH_KEY.equals(keyVal[0])) {
apiState = keyVal[1];
continue;
}
attributes.put(keyVal[0], keyVal[1]);
}
}
// check whether the new document indexer is engaged
RegistryConfigLoader registryConfig = RegistryConfigLoader.getInstance();
Map<String, Indexer> indexerMap = registryConfig.getIndexerMap();
Indexer documentIndexer = indexerMap.get(APIConstants.DOCUMENT_MEDIA_TYPE_KEY);
String complexAttribute;
if (documentIndexer != null && documentIndexer instanceof DocumentIndexer) {
// field check on document_indexed was added to prevent unindexed(by new DocumentIndexer) from coming up as search results
// on indexed documents this property is always set to true
complexAttribute = ClientUtils.escapeQueryChars(APIConstants.API_RXT_MEDIA_TYPE) + " OR mediaType_s:(" + ClientUtils.escapeQueryChars(APIConstants.DOCUMENT_RXT_MEDIA_TYPE) + " AND document_indexed_s:true)";
// this was designed this way so that content search can be fully functional if registry is re-indexed after engaging DocumentIndexer
if (!StringUtils.isEmpty(publisherRoles)) {
complexAttribute = "(" + ClientUtils.escapeQueryChars(APIConstants.API_RXT_MEDIA_TYPE) + " AND publisher_roles_ss:" + publisherRoles + ") OR mediaType_s:(" + ClientUtils.escapeQueryChars(APIConstants.DOCUMENT_RXT_MEDIA_TYPE) + " AND publisher_roles_s:" + publisherRoles + ")";
}
} else {
// document indexer required for document content search is not engaged, therefore carry out the search only for api artifact contents
complexAttribute = ClientUtils.escapeQueryChars(APIConstants.API_RXT_MEDIA_TYPE);
if (!StringUtils.isEmpty(publisherRoles)) {
complexAttribute = "(" + ClientUtils.escapeQueryChars(APIConstants.API_RXT_MEDIA_TYPE) + " AND publisher_roles_ss:" + publisherRoles + ")";
}
}
attributes.put(APIConstants.DOCUMENTATION_SEARCH_MEDIA_TYPE_FIELD, complexAttribute);
attributes.put(APIConstants.API_OVERVIEW_STATUS, apiState);
SearchResultsBean resultsBean = contentBasedSearchService.searchByAttribute(attributes, systemUserRegistry);
String errorMsg = resultsBean.getErrorMessage();
if (errorMsg != null) {
handleException(errorMsg);
}
ResourceData[] resourceData = resultsBean.getResourceDataList();
if (resourceData == null || resourceData.length == 0) {
result.put("apis", compoundResult);
result.put("length", 0);
result.put("isMore", isMore);
}
totalLength = PaginationContext.getInstance().getLength();
// Check to see if we can speculate that there are more APIs to be loaded
if (maxPaginationLimit == totalLength) {
// More APIs exist, cannot determine total API count without incurring perf hit
isMore = true;
// Remove the additional 1 added earlier when setting max pagination limit
--totalLength;
}
for (ResourceData data : resourceData) {
String resourcePath = data.getResourcePath();
if (resourcePath.contains(APIConstants.APIMGT_REGISTRY_LOCATION)) {
int index = resourcePath.indexOf(APIConstants.APIMGT_REGISTRY_LOCATION);
resourcePath = resourcePath.substring(index);
Resource resource = registry.get(resourcePath);
if (APIConstants.DOCUMENT_RXT_MEDIA_TYPE.equals(resource.getMediaType()) || APIConstants.DOCUMENTATION_INLINE_CONTENT_TYPE.equals(resource.getMediaType())) {
if (resourcePath.contains(APIConstants.INLINE_DOCUMENT_CONTENT_DIR)) {
int indexOfContents = resourcePath.indexOf(APIConstants.INLINE_DOCUMENT_CONTENT_DIR);
resourcePath = resourcePath.substring(0, indexOfContents) + data.getName();
}
Resource docResource = registry.get(resourcePath);
String docArtifactId = docResource.getUUID();
GenericArtifact docArtifact = docArtifactManager.getGenericArtifact(docArtifactId);
Documentation doc = APIUtil.getDocumentation(docArtifact);
API associatedAPI = null;
APIProduct associatedAPIProduct = null;
int indexOfDocumentation = resourcePath.indexOf(APIConstants.DOCUMENTATION_KEY);
String apiPath = resourcePath.substring(0, indexOfDocumentation) + APIConstants.API_KEY;
Resource apiResource = registry.get(apiPath);
String apiArtifactId = apiResource.getUUID();
if (apiArtifactId != null) {
GenericArtifact apiArtifact = apiArtifactManager.getGenericArtifact(apiArtifactId);
if (apiArtifact.getAttribute(APIConstants.API_OVERVIEW_TYPE).equals(APIConstants.AuditLogConstants.API_PRODUCT)) {
associatedAPIProduct = APIUtil.getAPIProduct(apiArtifact, registry);
} else {
associatedAPI = APIUtil.getAPI(apiArtifact, registry);
}
} else {
throw new GovernanceException("artifact id is null of " + apiPath);
}
if (associatedAPI != null && doc != null) {
docMap.put(doc, associatedAPI);
}
if (associatedAPIProduct != null && doc != null) {
productDocMap.put(doc, associatedAPIProduct);
}
} else {
String apiArtifactId = resource.getUUID();
API api;
APIProduct apiProduct;
if (apiArtifactId != null) {
GenericArtifact apiArtifact = apiArtifactManager.getGenericArtifact(apiArtifactId);
if (apiArtifact.getAttribute(APIConstants.API_OVERVIEW_TYPE).equals(APIConstants.API_PRODUCT)) {
apiProduct = APIUtil.getAPIProduct(apiArtifact, registry);
apiProductSet.add(apiProduct);
} else {
api = APIUtil.getAPI(apiArtifact, registry);
apiSet.add(api);
}
} else {
throw new GovernanceException("artifact id is null for " + resourcePath);
}
}
}
}
compoundResult.addAll(apiSet);
compoundResult.addAll(apiProductSet);
compoundResult.addAll(docMap.entrySet());
compoundResult.addAll(productDocMap.entrySet());
compoundResult.sort(new ContentSearchResultNameComparator());
} catch (RegistryException e) {
handleException("Failed to search APIs by content", e);
} catch (IndexerException e) {
handleException("Failed to search APIs by content", e);
}
result.put("apis", compoundResult);
result.put("length", totalLength);
result.put("isMore", isMore);
return result;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Property in project carbon-apimgt by wso2.
the class APIUtil method replaceSystemProperty.
/**
* Resolves system properties and replaces in given in text
*
* @param text
* @return System properties resolved text
*/
public static String replaceSystemProperty(String text) {
int indexOfStartingChars = -1;
int indexOfClosingBrace;
// and are assumed to be System properties
while (indexOfStartingChars < text.indexOf("${") && (indexOfStartingChars = text.indexOf("${")) != -1 && (indexOfClosingBrace = text.indexOf('}')) != -1) {
// Is a
// property
// used?
String sysProp = text.substring(indexOfStartingChars + 2, indexOfClosingBrace);
String propValue = System.getProperty(sysProp);
if (propValue == null) {
if ("carbon.context".equals(sysProp)) {
propValue = ServiceReferenceHolder.getContextService().getServerConfigContext().getContextRoot();
} else if ("admin.username".equals(sysProp) || "admin.password".equals(sysProp)) {
try {
RealmConfiguration realmConfig = new RealmConfigXMLProcessor().buildRealmConfigurationFromFile();
if ("admin.username".equals(sysProp)) {
propValue = realmConfig.getAdminUserName();
} else {
propValue = realmConfig.getAdminPassword();
}
} catch (UserStoreException e) {
// Can't throw an exception because the server is
// starting and can't be halted.
log.error("Unable to build the Realm Configuration", e);
return null;
}
}
}
// Derive original text value with resolved system property value
if (propValue != null) {
text = text.substring(0, indexOfStartingChars) + propValue + text.substring(indexOfClosingBrace + 1);
}
if ("carbon.home".equals(sysProp) && propValue != null && ".".equals(propValue)) {
text = new File(".").getAbsolutePath() + File.separator + text;
}
}
return text;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Property in project carbon-apimgt by wso2.
the class APIUtil method getOAuthConfigurationFromAPIMConfig.
/**
* This method is used to get the authorization configurations from the api manager configurations
*
* @param property The configuration to get from api-manager.xml
* @return The configuration read from api-manager.xml or else null
* @throws APIManagementException Throws if the registry resource doesn't exist
* or the content cannot be parsed to JSON
*/
public static String getOAuthConfigurationFromAPIMConfig(String property) throws APIManagementException {
// If tenant registry doesn't have the configuration, then read it from api-manager.xml
APIManagerConfiguration apimConfig = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
String oAuthConfiguration = apimConfig.getFirstProperty(APIConstants.OAUTH_CONFIGS + property);
if (!StringUtils.isBlank(oAuthConfiguration)) {
return oAuthConfiguration;
}
return null;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Property in project carbon-apimgt by wso2.
the class APIUtil method getReducedPublisherAPIForListing.
/**
* Copy of the getAPI(GovernanceArtifact artifact, Registry registry) method with reduced DB calls for api
* publisher list view listing.
* @param artifact
* @param registry
* @return
* @throws APIManagementException
*/
public static API getReducedPublisherAPIForListing(GovernanceArtifact artifact, Registry registry) throws APIManagementException {
API api;
try {
String providerName = artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER);
String apiName = artifact.getAttribute(APIConstants.API_OVERVIEW_NAME);
String apiVersion = artifact.getAttribute(APIConstants.API_OVERVIEW_VERSION);
APIIdentifier apiIdentifier = new APIIdentifier(providerName, apiName, apiVersion);
api = new API(apiIdentifier);
// set description
api.setDescription(artifact.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION));
// set uuid
api.setUUID(artifact.getId());
// set url
api.setStatus(getLcStateFromArtifact(artifact));
api.setType(artifact.getAttribute(APIConstants.API_OVERVIEW_TYPE));
api.setThumbnailUrl(artifact.getAttribute(APIConstants.API_OVERVIEW_THUMBNAIL_URL));
api.setWsdlUrl(artifact.getAttribute(APIConstants.API_OVERVIEW_WSDL));
api.setWadlUrl(artifact.getAttribute(APIConstants.API_OVERVIEW_WADL));
api.setTechnicalOwner(artifact.getAttribute(APIConstants.API_OVERVIEW_TEC_OWNER));
api.setTechnicalOwnerEmail(artifact.getAttribute(APIConstants.API_OVERVIEW_TEC_OWNER_EMAIL));
api.setBusinessOwner(artifact.getAttribute(APIConstants.API_OVERVIEW_BUSS_OWNER));
api.setBusinessOwnerEmail(artifact.getAttribute(APIConstants.API_OVERVIEW_BUSS_OWNER_EMAIL));
api.setVisibility(artifact.getAttribute(APIConstants.API_OVERVIEW_VISIBILITY));
api.setVisibleRoles(artifact.getAttribute(APIConstants.API_OVERVIEW_VISIBLE_ROLES));
api.setVisibleTenants(artifact.getAttribute(APIConstants.API_OVERVIEW_VISIBLE_TENANTS));
api.setEndpointSecured(Boolean.parseBoolean(artifact.getAttribute(APIConstants.API_OVERVIEW_ENDPOINT_SECURED)));
api.setEndpointAuthDigest(Boolean.parseBoolean(artifact.getAttribute(APIConstants.API_OVERVIEW_ENDPOINT_AUTH_DIGEST)));
api.setEndpointUTUsername(artifact.getAttribute(APIConstants.API_OVERVIEW_ENDPOINT_USERNAME));
if (!((APIConstants.DEFAULT_MODIFIED_ENDPOINT_PASSWORD).equals(artifact.getAttribute(APIConstants.API_OVERVIEW_ENDPOINT_PASSWORD)))) {
api.setEndpointUTPassword(artifact.getAttribute(APIConstants.API_OVERVIEW_ENDPOINT_PASSWORD));
} else {
// If APIEndpointPasswordRegistryHandler is enabled take password from the registry hidden property
api.setEndpointUTPassword(getActualEpPswdFromHiddenProperty(api, registry));
}
api.setTransports(artifact.getAttribute(APIConstants.API_OVERVIEW_TRANSPORTS));
api.setInSequence(artifact.getAttribute(APIConstants.API_OVERVIEW_INSEQUENCE));
api.setOutSequence(artifact.getAttribute(APIConstants.API_OVERVIEW_OUTSEQUENCE));
api.setFaultSequence(artifact.getAttribute(APIConstants.API_OVERVIEW_FAULTSEQUENCE));
api.setResponseCache(artifact.getAttribute(APIConstants.API_OVERVIEW_RESPONSE_CACHING));
api.setImplementation(artifact.getAttribute(APIConstants.PROTOTYPE_OVERVIEW_IMPLEMENTATION));
api.setProductionMaxTps(artifact.getAttribute(APIConstants.API_PRODUCTION_THROTTLE_MAXTPS));
int cacheTimeout = APIConstants.API_RESPONSE_CACHE_TIMEOUT;
try {
cacheTimeout = Integer.parseInt(artifact.getAttribute(APIConstants.API_OVERVIEW_CACHE_TIMEOUT));
} catch (NumberFormatException e) {
// ignore
}
api.setCacheTimeout(cacheTimeout);
api.setEndpointConfig(artifact.getAttribute(APIConstants.API_OVERVIEW_ENDPOINT_CONFIG));
api.setRedirectURL(artifact.getAttribute(APIConstants.API_OVERVIEW_REDIRECT_URL));
api.setApiOwner(artifact.getAttribute(APIConstants.API_OVERVIEW_OWNER));
api.setAdvertiseOnly(Boolean.parseBoolean(artifact.getAttribute(APIConstants.API_OVERVIEW_ADVERTISE_ONLY)));
api.setSubscriptionAvailability(artifact.getAttribute(APIConstants.API_OVERVIEW_SUBSCRIPTION_AVAILABILITY));
api.setSubscriptionAvailableTenants(artifact.getAttribute(APIConstants.API_OVERVIEW_SUBSCRIPTION_AVAILABLE_TENANTS));
api.setContext(artifact.getAttribute(APIConstants.API_OVERVIEW_CONTEXT));
// We set the context template here
api.setContextTemplate(artifact.getAttribute(APIConstants.API_OVERVIEW_CONTEXT_TEMPLATE));
api.setLatest(Boolean.parseBoolean(artifact.getAttribute(APIConstants.API_OVERVIEW_IS_LATEST)));
api.setEnableSchemaValidation(Boolean.parseBoolean(artifact.getAttribute(APIConstants.API_OVERVIEW_ENABLE_JSON_SCHEMA)));
api.setEnableStore(Boolean.parseBoolean(artifact.getAttribute(APIConstants.API_OVERVIEW_ENABLE_STORE)));
api.setAsDefaultVersion(Boolean.parseBoolean(artifact.getAttribute(APIConstants.API_OVERVIEW_IS_DEFAULT_VERSION)));
api.setImplementation(artifact.getAttribute(APIConstants.PROTOTYPE_OVERVIEW_IMPLEMENTATION));
api.setAuthorizationHeader(artifact.getAttribute(APIConstants.API_OVERVIEW_AUTHORIZATION_HEADER));
api.setApiSecurity(artifact.getAttribute(APIConstants.API_OVERVIEW_API_SECURITY));
} catch (GovernanceException e) {
String msg = "Failed to get API for artifact ";
throw new APIManagementException(msg, e);
} catch (RegistryException e) {
String msg = "Failed to get LastAccess time or Rating";
throw new APIManagementException(msg, e);
}
return api;
}
Aggregations