use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromDTOtoApplication.
public static Application fromDTOtoApplication(ApplicationDTO applicationDTO, String username) {
// subscriber field of the body is not honored
Subscriber subscriber = new Subscriber(username);
Application application = new Application(applicationDTO.getName(), subscriber);
application.setTier(applicationDTO.getThrottlingPolicy());
application.setDescription(applicationDTO.getDescription());
application.setUUID(applicationDTO.getApplicationId());
// Check if the token type is not set in the request.
if (StringUtils.isEmpty(applicationDTO.getTokenType().toString())) {
// Set the default to JWT.
application.setTokenType(APIConstants.TOKEN_TYPE_JWT);
} else {
// Otherwise set it to the type in the request.
application.setTokenType(applicationDTO.getTokenType().toString());
}
Map<String, String> appAttributes = applicationDTO.getAttributes();
application.setApplicationAttributes(appAttributes);
if (applicationDTO.getGroups() != null && applicationDTO.getGroups().size() > 0) {
application.setGroupId(String.join(",", applicationDTO.getGroups()));
}
return application;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class ExportUtils method createApplicationDTOToExport.
/**
* Create an aggregated Application DTO to be exported.
*
* @param application Application{@link Application} to be exported
* @param apiConsumer API Consumer
* @param withKeys Export the Application with keys or not
* @return Exported application
* @throws APIManagementException If an error occurs while retrieving subscribed APIs
*/
private static ExportedApplication createApplicationDTOToExport(Application application, APIConsumer apiConsumer, Boolean withKeys) throws APIManagementException {
ApplicationDTO applicationDto = ApplicationMappingUtil.fromApplicationtoDTO(application);
// Set keys if withKeys is true
if (withKeys == null || !withKeys) {
application.clearOAuthApps();
} else {
List<ApplicationKeyDTO> applicationKeyDTOs = new ArrayList<>();
for (APIKey apiKey : application.getKeys()) {
// Encode the consumer secret and set it
apiKey.setConsumerSecret(new String(Base64.encodeBase64(apiKey.getConsumerSecret().getBytes(Charset.defaultCharset()))));
ApplicationKeyDTO applicationKeyDTO = ApplicationKeyMappingUtil.fromApplicationKeyToDTO(apiKey);
applicationKeyDTOs.add(applicationKeyDTO);
}
applicationDto.setKeys(applicationKeyDTOs);
}
// Get the subscribed API details and add it to a set
Set<SubscribedAPI> subscribedAPIs = apiConsumer.getSubscribedAPIs(application.getSubscriber(), application.getName(), application.getGroupId());
Set<ExportedSubscribedAPI> exportedSubscribedAPIs = new HashSet<>();
for (SubscribedAPI subscribedAPI : subscribedAPIs) {
ExportedSubscribedAPI exportedSubscribedAPI = new ExportedSubscribedAPI(subscribedAPI.getApiId(), subscribedAPI.getSubscriber(), subscribedAPI.getTier().getName());
exportedSubscribedAPIs.add(exportedSubscribedAPI);
}
// Set the subscription count by counting the number of subscribed APIs
applicationDto.setSubscriptionCount(exportedSubscribedAPIs.size());
// Set the application
ExportedApplication exportedApplication = new ExportedApplication(applicationDto);
// Set the subscribed APIs
exportedApplication.setSubscribedAPIs(exportedSubscribedAPIs);
return exportedApplication;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class SubscriptionValidationDataUtil method fromApplicationToApplicationListDTO.
public static ApplicationListDTO fromApplicationToApplicationListDTO(List<Application> model) {
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
if (model != null) {
for (Application appModel : model) {
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setUuid(appModel.getUuid());
applicationDTO.setId(appModel.getId());
applicationDTO.setName(appModel.getName());
applicationDTO.setPolicy(appModel.getPolicy());
applicationDTO.setSubName(appModel.getSubName());
applicationDTO.setTokenType(appModel.getTokenType());
applicationDTO.setOrganization(appModel.getOrganization());
Set<String> groupIds = appModel.getGroupIds();
for (String grp : groupIds) {
GroupIdDTO groupIdDTO = new GroupIdDTO();
groupIdDTO.setApplicationId(appModel.getId());
groupIdDTO.setGroupId(grp);
applicationDTO.getGroupIds().add(groupIdDTO);
}
Map<String, String> attributes = appModel.getAttributes();
applicationDTO.setAttributes(attributes);
applicationListDTO.getList().add(applicationDTO);
}
applicationListDTO.setCount(model.size());
} else {
applicationListDTO.setCount(0);
}
return applicationListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsApplicationIdGet.
/**
* Get an application by Id
*
* @param applicationId application identifier
* @param ifNoneMatch If-None-Match header value
* @return response containing the required application object
*/
@Override
public Response applicationsApplicationIdGet(String applicationId, String ifNoneMatch, String xWSO2Tenant, MessageContext messageContext) {
String username = RestApiCommonUtil.getLoggedInUsername();
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(username);
Application application = apiConsumer.getApplicationByUUID(applicationId, organization);
if (application != null) {
// Remove hidden attributes and set the rest of the attributes from config
JSONArray applicationAttributesFromConfig = apiConsumer.getAppAttributesFromConfig(username);
Map<String, String> existingApplicationAttributes = application.getApplicationAttributes();
Map<String, String> applicationAttributes = new HashMap<>();
if (existingApplicationAttributes != null && applicationAttributesFromConfig != null) {
for (Object object : applicationAttributesFromConfig) {
JSONObject attribute = (JSONObject) object;
Boolean hidden = (Boolean) attribute.get(APIConstants.ApplicationAttributes.HIDDEN);
String attributeName = (String) attribute.get(APIConstants.ApplicationAttributes.ATTRIBUTE);
if (!BooleanUtils.isTrue(hidden)) {
String attributeVal = existingApplicationAttributes.get(attributeName);
if (attributeVal != null) {
applicationAttributes.put(attributeName, attributeVal);
} else {
applicationAttributes.put(attributeName, "");
}
}
}
}
application.setApplicationAttributes(applicationAttributes);
if (RestAPIStoreUtils.isUserAccessAllowedForApplication(application)) {
ApplicationDTO applicationDTO = ApplicationMappingUtil.fromApplicationtoDTO(application);
applicationDTO.setHashEnabled(OAuthServerConfiguration.getInstance().isClientSecretHashEnabled());
Set<Scope> scopes = apiConsumer.getScopesForApplicationSubscription(username, application.getId(), organization);
List<ScopeInfoDTO> scopeInfoList = ApplicationMappingUtil.getScopeInfoDTO(scopes);
applicationDTO.setSubscriptionScopes(scopeInfoList);
return Response.ok().entity(applicationDTO).build();
} else {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_APPLICATION, applicationId, log);
}
} else {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_APPLICATION, applicationId, log);
}
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while retrieving application " + applicationId, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromApplicationtoDTO.
public static ApplicationDTO fromApplicationtoDTO(Application application) {
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setApplicationId(application.getUUID());
applicationDTO.setThrottlingPolicy(application.getTier());
applicationDTO.setDescription(application.getDescription());
Map<String, String> applicationAttributes = application.getApplicationAttributes();
applicationDTO.setAttributes(applicationAttributes);
applicationDTO.setName(application.getName());
applicationDTO.setStatus(application.getStatus());
applicationDTO.setOwner(application.getOwner());
if (StringUtils.isNotEmpty(application.getGroupId())) {
applicationDTO.setGroups(Arrays.asList(application.getGroupId().split(",")));
}
applicationDTO.setTokenType(ApplicationDTO.TokenTypeEnum.OAUTH);
applicationDTO.setSubscriptionCount(application.getSubscriptionCount());
if (StringUtils.isNotEmpty(application.getTokenType()) && !APIConstants.DEFAULT_TOKEN_TYPE.equals(application.getTokenType())) {
applicationDTO.setTokenType(ApplicationDTO.TokenTypeEnum.valueOf(application.getTokenType()));
}
return applicationDTO;
}
Aggregations