use of org.wso2.carbon.identity.application.common.model.xsd.ImportResponse in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method importApplication.
private ImportResponse importApplication(ServiceProvider serviceProvider, String tenantDomain, String username, boolean isUpdate) throws IdentityApplicationManagementException {
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
ServiceProvider savedSP = null;
String appName = serviceProvider.getApplicationName();
try {
if (isUpdate) {
savedSP = getApplicationExcludingFileBasedSPs(appName, tenantDomain);
if (savedSP == null) {
String errorMsg = String.format("Service provider %s@%s is not found", appName, tenantDomain);
throw new IdentityApplicationManagementClientException(APPLICATION_NOT_FOUND.getCode(), errorMsg);
}
}
if (!isUpdate) {
ServiceProvider basicApplication = new ServiceProvider();
basicApplication.setApplicationName(serviceProvider.getApplicationName());
basicApplication.setDescription(serviceProvider.getDescription());
String resourceId = createApplication(basicApplication, tenantDomain, username);
savedSP = getApplicationByResourceId(resourceId, tenantDomain);
}
serviceProvider.setApplicationResourceId(savedSP.getApplicationResourceId());
serviceProvider.setApplicationID(savedSP.getApplicationID());
serviceProvider.setOwner(getUser(tenantDomain, username));
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable()) {
listener.onPreCreateInbound(serviceProvider, isUpdate);
}
}
updateApplication(serviceProvider, tenantDomain, username);
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable()) {
listener.doImportServiceProvider(serviceProvider);
}
}
ImportResponse importResponse = new ImportResponse();
if (isUpdate) {
importResponse.setResponseCode(ImportResponse.UPDATED);
} else {
importResponse.setResponseCode(ImportResponse.CREATED);
}
importResponse.setApplicationName(appName);
importResponse.setApplicationResourceId(serviceProvider.getApplicationResourceId());
importResponse.setErrors(new String[0]);
return importResponse;
} catch (IdentityApplicationManagementClientException e) {
deleteCreatedSP(savedSP, tenantDomain, username, isUpdate);
return buildImportErrorResponse(e);
} catch (IdentityApplicationManagementException e) {
deleteCreatedSP(savedSP, tenantDomain, username, isUpdate);
String errorMsg = String.format("Error in importing provided service provider %s@%s from file ", appName, tenantDomain);
throw new IdentityApplicationManagementException(errorMsg, e);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ImportResponse in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method importSPApplication.
public ImportResponse importSPApplication(SpFileContent spFileContent, String tenantDomain, String username, boolean isUpdate) throws IdentityApplicationManagementException {
if (log.isDebugEnabled()) {
log.debug("Importing service provider from file " + spFileContent.getFileName());
}
ServiceProvider serviceProvider = unmarshalSP(spFileContent, tenantDomain);
ImportResponse importResponse = importSPApplication(serviceProvider, tenantDomain, username, isUpdate);
if (log.isDebugEnabled()) {
log.debug(String.format("Service provider %s@%s created successfully from file %s", serviceProvider.getApplicationName(), tenantDomain, spFileContent.getFileName()));
}
return importResponse;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ImportResponse in project product-is by wso2.
the class ApplicationManagementServiceClient method importApplication.
/**
* Import Service Provider
*
* @param fileName file name
* @param fileContent file content
* @return true if created
* @throws Exception exception
*/
public String importApplication(String fileName, String fileContent) throws Exception {
SpFileContent spFileContent = new SpFileContent();
spFileContent.setFileName(fileName);
spFileContent.setContent(fileContent);
ImportResponse importResponse = stub.importApplication(spFileContent);
if (201 == importResponse.getResponseCode()) {
return importResponse.getApplicationName();
}
return null;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ImportResponse in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method buildImportErrorResponse.
private ImportResponse buildImportErrorResponse(IdentityApplicationManagementClientException e) {
ImportResponse importResponse = new ImportResponse();
importResponse.setResponseCode(ImportResponse.FAILED);
importResponse.setApplicationName(null);
String errorCode = e.getErrorCode() != null ? e.getErrorCode() : INVALID_REQUEST.getCode();
importResponse.setErrorCode(errorCode);
if (e instanceof IdentityApplicationManagementValidationException) {
importResponse.setErrors(((IdentityApplicationManagementValidationException) e).getValidationMsg());
} else {
String message = e.getMessage();
if (StringUtils.isNotBlank(message)) {
importResponse.setErrors(new String[] { e.getMessage() });
}
}
return importResponse;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ImportResponse in project identity-api-server by wso2.
the class ServerApplicationManagementService method doImportApplication.
private String doImportApplication(InputStream fileInputStream, Attachment fileDetail, boolean isAppUpdate) {
try {
SpFileContent spFileContent = buildSpFileContent(fileInputStream, fileDetail);
String tenantDomain = ContextLoader.getTenantDomainFromContext();
String username = ContextLoader.getUsernameFromContext();
ImportResponse importResponse = getApplicationManagementService().importSPApplication(spFileContent, tenantDomain, username, isAppUpdate);
if (importResponse.getResponseCode() == ImportResponse.FAILED) {
throw handleErrorResponse(importResponse);
} else {
return importResponse.getApplicationResourceId();
}
} catch (IOException e) {
throw Utils.buildServerError("Error importing application from XML file.", e);
} catch (IdentityApplicationManagementException e) {
throw handleIdentityApplicationManagementException(e, "Error importing application from XML file.");
} finally {
IOUtils.closeQuietly(fileInputStream);
}
}
Aggregations