Change to base64 string for file uploads instead of using multipart form data

Make release optional when creating new application
Fix screenshots not getting saved if duplicate screenshot file name found
Delete artifacts if errors while adding release to db
Improve service provider application related apis
Refactor code
This commit is contained in:
Mohamed Rashd 2022-02-26 22:18:09 +05:30
parent 5e247c6e6b
commit 9cdc438970
32 changed files with 1202 additions and 1294 deletions

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.common; package io.entgra.application.mgt.common;
public class Base64File { public class Base64File {

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.common; package io.entgra.application.mgt.common;
import java.io.InputStream; import java.io.InputStream;

View File

@ -1,5 +1,22 @@
package io.entgra.application.mgt.common; /*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.common;
public class IdentityServer { public class IdentityServer {
private int id; private int id;

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.common; package io.entgra.application.mgt.common;
import java.util.List; import java.util.List;

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.common; package io.entgra.application.mgt.common;

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.common; package io.entgra.application.mgt.common;
import java.util.List; import java.util.List;

View File

@ -34,15 +34,10 @@ import io.entgra.application.mgt.common.response.ApplicationRelease;
import io.entgra.application.mgt.common.response.Category; import io.entgra.application.mgt.common.response.Category;
import io.entgra.application.mgt.common.response.Tag; import io.entgra.application.mgt.common.response.Tag;
import io.entgra.application.mgt.common.wrapper.CustomAppReleaseWrapper; import io.entgra.application.mgt.common.wrapper.CustomAppReleaseWrapper;
import io.entgra.application.mgt.common.wrapper.CustomAppWrapper;
import io.entgra.application.mgt.common.wrapper.EntAppReleaseWrapper; import io.entgra.application.mgt.common.wrapper.EntAppReleaseWrapper;
import io.entgra.application.mgt.common.wrapper.ApplicationUpdateWrapper; import io.entgra.application.mgt.common.wrapper.ApplicationUpdateWrapper;
import io.entgra.application.mgt.common.wrapper.ApplicationWrapper;
import io.entgra.application.mgt.common.wrapper.PublicAppReleaseWrapper; import io.entgra.application.mgt.common.wrapper.PublicAppReleaseWrapper;
import io.entgra.application.mgt.common.wrapper.PublicAppWrapper;
import io.entgra.application.mgt.common.wrapper.WebAppReleaseWrapper; import io.entgra.application.mgt.common.wrapper.WebAppReleaseWrapper;
import io.entgra.application.mgt.common.wrapper.WebAppWrapper;
import java.util.List; import java.util.List;
/** /**
@ -50,40 +45,64 @@ import java.util.List;
*/ */
public interface ApplicationManager { public interface ApplicationManager {
/**
ApplicationReleaseDTO uploadEntAppReleaseArtifacts(EntAppReleaseWrapper releaseWrapper, ApplicationArtifact artifact, * This method is responsible for handling application creation
String deviceType) throws ApplicationManagementException;
/***
* The method is responsible to add new application into entgra App Manager.
* *
* @param applicationWrapper Application that need to be created. * @param appId application id of the application to which the release should be created
* @param applicationArtifact contains artifact data. i.e image name and stream, icon name and stream etc. * @param releaseWrapper {@link EntAppReleaseWrapper} of the release to be created
* @return {@link Application} * @return Created application release bean
* @throws ApplicationManagementException Catch all other throwing exceptions and throw {@link ApplicationManagementException} * @throws ApplicationManagementException if any error occurred while creating the application
*/ */
ApplicationDTO uploadEntAppReleaseArtifacts(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact) ApplicationRelease createEntAppRelease(int appId, EntAppReleaseWrapper releaseWrapper)
throws ApplicationManagementException; throws ApplicationManagementException;
ApplicationReleaseDTO uploadWebAppReleaseArtifacts(WebAppReleaseWrapper releaseWrapper, ApplicationArtifact artifact) /**
* This method is responsible for handling application creation
*
* @param appId application id of the application to which the release should be created
* @param releaseWrapper {@link WebAppReleaseWrapper} of the release to be created
* @return Created application release bean
* @throws ApplicationManagementException if any error occurred while creating the application
*/
ApplicationRelease createWebAppRelease(int appId, WebAppReleaseWrapper releaseWrapper)
throws ApplicationManagementException, ResourceManagementException; throws ApplicationManagementException, ResourceManagementException;
ApplicationDTO uploadWebAppReleaseArtifacts(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) /**
throws ApplicationManagementException; * This method is responsible for handling application creation
*
* @param appId application id of the application to which the release should be created
* @param releaseWrapper {@link PublicAppReleaseWrapper} of the release to be created
* @return Created application release bean
* @throws ApplicationManagementException if any error occurred while creating the application
*/
ApplicationRelease createPubAppRelease(int appId, PublicAppReleaseWrapper releaseWrapper)
throws ApplicationManagementException, ResourceManagementException;
ApplicationReleaseDTO uploadPubAppReleaseArtifacts(PublicAppReleaseWrapper releaseWrapper, ApplicationArtifact artifact, /**
String deviceType) throws ResourceManagementException; * This method is responsible for handling application creation
*
* @param appId application id of the application to which the release should be created
* @param releaseWrapper {@link CustomAppReleaseWrapper} of the release to be created
* @return Created application release bean
* @throws ApplicationManagementException if any error occurred while creating the application
*/
ApplicationRelease createCustomAppRelease(int appId, CustomAppReleaseWrapper releaseWrapper)
throws ResourceManagementException, ApplicationManagementException;
ApplicationDTO uploadPublicAppReleaseArtifacts(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact) /**
throws ApplicationManagementException; * Checks if release is available for a given application wrapper, and if exists it uploads
* the artifacts of the release
*
* @param app Application wrapper bean of the application
* @param <T> Application Wrapper class
* @return constructed ApplicationDTO after uploading the release artifacts if exist
* @throws ApplicationManagementException if any error occurred while uploading release artifacts
*/
<T> ApplicationDTO uploadReleaseArtifactIfExist(T app) throws ApplicationManagementException;
ApplicationReleaseDTO uploadCustomAppReleaseArtifacts(CustomAppReleaseWrapper releaseWrapper, ApplicationArtifact artifact, void validatePublicAppReleasePackageName(String packageName) throws ApplicationManagementException;
String deviceType) throws ResourceManagementException, ApplicationManagementException;
ApplicationDTO uploadCustomAppReleaseArtifactsAndConstructAppDTO(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact) /**
throws ApplicationManagementException;
/***
* This method is responsible to add application data into APPM database. However, before call this method it is * This method is responsible to add application data into APPM database. However, before call this method it is
* required to do the validation of request and check the existence of application releaseDTO. * required to do the validation of request and check the existence of application releaseDTO.
* *
@ -91,12 +110,18 @@ public interface ApplicationManager {
* @return {@link Application} * @return {@link Application}
* @throws ApplicationManagementException which throws if error occurs while during application management. * @throws ApplicationManagementException which throws if error occurs while during application management.
*/ */
Application executeApplicationPersistenceTransaction(ApplicationDTO applicationDTO) throws Application addAppDataIntoDB(ApplicationDTO applicationDTO) throws
ApplicationManagementException; ApplicationManagementException;
/**
Application persistApplication(ApplicationDTO applicationDTO) throws ApplicationManagementException; * This method is responsible for handling application creation
*
* @param app Application wrapper object which depends on the application type
* @param <T> Application wrapper class which depends on the application type
* @return Created application bean
* @throws ApplicationManagementException if any error occurred while creating the application
*/
<T> Application createApplication(T app) throws ApplicationManagementException;
/** /**
* Check the existence of an application for given application name and the device type. * Check the existence of an application for given application name and the device type.
@ -109,7 +134,6 @@ public interface ApplicationManager {
*/ */
boolean isExistingAppName(String appName, String deviceTypeName) throws ApplicationManagementException; boolean isExistingAppName(String appName, String deviceTypeName) throws ApplicationManagementException;
/** /**
* Updates an already existing application. * Updates an already existing application.
* *
@ -145,6 +169,8 @@ public interface ApplicationManager {
*/ */
void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException; void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException;
void deleteApplicationArtifacts(List<String> directoryPaths) throws ApplicationManagementException;
/** /**
* To get the applications based on the search filter. * To get the applications based on the search filter.
* *
@ -154,9 +180,21 @@ public interface ApplicationManager {
*/ */
ApplicationList getApplications(Filter filter) throws ApplicationManagementException; ApplicationList getApplications(Filter filter) throws ApplicationManagementException;
/**
*
* @param applicationReleaseDTOs application releases of the application
* @return if application is hide-able
* @throws ApplicationManagementException if any error occurred while checking if hide-able
*/
boolean isHideableApp(List<ApplicationReleaseDTO> applicationReleaseDTOs) boolean isHideableApp(List<ApplicationReleaseDTO> applicationReleaseDTOs)
throws ApplicationManagementException; throws ApplicationManagementException;
/**
*
* @param applicationReleaseDTOs application releases of the application
* @return if application is deletable
* @throws ApplicationManagementException if any error occurred while checking if deletable
*/
boolean isDeletableApp(List<ApplicationReleaseDTO> applicationReleaseDTOs) boolean isDeletableApp(List<ApplicationReleaseDTO> applicationReleaseDTOs)
throws ApplicationManagementException; throws ApplicationManagementException;
@ -170,7 +208,6 @@ public interface ApplicationManager {
*/ */
List<Application> getApplications(List<String> packageNames) throws ApplicationManagementException; List<Application> getApplications(List<String> packageNames) throws ApplicationManagementException;
/** /**
* To create an application release for an ApplicationDTO. * To create an application release for an ApplicationDTO.
* *
@ -244,7 +281,6 @@ public interface ApplicationManager {
void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact) void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException; throws ApplicationManagementException;
/** /**
* To update release images. * To update release images.
* *
@ -279,7 +315,7 @@ public interface ApplicationManager {
* To validate the application creating request * To validate the application creating request
* *
*/ */
<T> void validateAppCreatingRequest(T param, boolean isReleaseRequired) throws ApplicationManagementException; <T> void validateAppCreatingRequest(T param) throws ApplicationManagementException, RequestValidatingException;
/*** /***
* *
@ -287,8 +323,49 @@ public interface ApplicationManager {
*/ */
<T> void validateReleaseCreatingRequest(T releases, String deviceType) throws ApplicationManagementException; <T> void validateReleaseCreatingRequest(T releases, String deviceType) throws ApplicationManagementException;
/**
* Validate enterprise application release
*
*/
void validateEntAppReleaseCreatingRequest(EntAppReleaseWrapper releaseWrapper, String deviceType)
throws RequestValidatingException, ApplicationManagementException;
/**
* Validate custom application release
*
*/
void validateCustomAppReleaseCreatingRequest(CustomAppReleaseWrapper releaseWrapper, String deviceType)
throws RequestValidatingException, ApplicationManagementException;
/**
* Validate web application release
*
*/
void validateWebAppReleaseCreatingRequest(WebAppReleaseWrapper releaseWrapper)
throws RequestValidatingException, ApplicationManagementException;
/**
* Validate public application release
*
*/
void validatePublicAppReleaseCreatingRequest(PublicAppReleaseWrapper releaseWrapper, String deviceType)
throws RequestValidatingException, ApplicationManagementException;
/**
* Validates image files of the application release
*
* @param iconFile icon of the application release
* @param screenshots screenshots of the application release
* @throws RequestValidatingException if any image is invalid
*/
void validateImageArtifacts(Base64File iconFile, List<Base64File> screenshots) throws RequestValidatingException; void validateImageArtifacts(Base64File iconFile, List<Base64File> screenshots) throws RequestValidatingException;
/**
* Validates any base64 files, for example a base64file may an empty file name which is invalid
*
* @param file Base64 File to be validated
* @throws RequestValidatingException if the file is invalid
*/
void validateBase64File(Base64File file) throws RequestValidatingException; void validateBase64File(Base64File file) throws RequestValidatingException;
/*** /***
@ -301,6 +378,12 @@ public interface ApplicationManager {
void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List<Attachment> attachmentList) void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List<Attachment> attachmentList)
throws RequestValidatingException; throws RequestValidatingException;
/**
* Validates binary file of the application release
*
* @param binaryFile binary file of the application release
* @throws RequestValidatingException if binary file is invalid
*/
void validateBinaryArtifact(Base64File binaryFile) throws RequestValidatingException; void validateBinaryArtifact(Base64File binaryFile) throws RequestValidatingException;
void validateBinaryArtifact(Attachment binaryFile) throws RequestValidatingException; void validateBinaryArtifact(Attachment binaryFile) throws RequestValidatingException;
@ -343,7 +426,6 @@ public interface ApplicationManager {
void updateSubsStatus (int deviceId, int operationId, String status) throws ApplicationManagementException; void updateSubsStatus (int deviceId, int operationId, String status) throws ApplicationManagementException;
/** /**
* Get plist content to download and install the application. * Get plist content to download and install the application.
* *

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.common.services; package io.entgra.application.mgt.common.services;
import io.entgra.application.mgt.common.IdentityServer; import io.entgra.application.mgt.common.IdentityServer;
@ -6,28 +24,93 @@ import io.entgra.application.mgt.common.SPApplication;
import io.entgra.application.mgt.common.exception.ApplicationManagementException; import io.entgra.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.application.mgt.common.exception.RequestValidatingException; import io.entgra.application.mgt.common.exception.RequestValidatingException;
import io.entgra.application.mgt.common.response.Application; import io.entgra.application.mgt.common.response.Application;
import java.util.List; import java.util.List;
public interface SPApplicationManager { public interface SPApplicationManager {
/**
* This method adds existing consumer applications of service providers to the SPApplication bean
*
* @param identityServerId identity server id of the service provider
* @param applications Service providers list to which the existing applications should be added
* @throws ApplicationManagementException if error occurred while adding existing applications
*/
void addExistingApps(int identityServerId, List<SPApplication> applications) throws ApplicationManagementException; void addExistingApps(int identityServerId, List<SPApplication> applications) throws ApplicationManagementException;
/**
* Removes consumer application from service provider
*
* @param identityServerId of the service provider
* @param spUID uid of the service provider
* @param appIds List of application ids to be removed
* @throws ApplicationManagementException if errors while removing appIds from service provider
*/
void detachSPApplications(int identityServerId, String spUID, List<Integer> appIds) throws ApplicationManagementException; void detachSPApplications(int identityServerId, String spUID, List<Integer> appIds) throws ApplicationManagementException;
/**
* Maps consumer applications to service provider
*
* @param identityServerId of the service provider
* @param spUID uid of the service provider
* @param appIds List of application ids to be mapped
* @throws ApplicationManagementException if errors while mapping appIds to service provider
*/
void attachSPApplications(int identityServerId, String spUID, List<Integer> appIds) throws ApplicationManagementException; void attachSPApplications(int identityServerId, String spUID, List<Integer> appIds) throws ApplicationManagementException;
/**
*
* @param identityServerId of the identity server that is to be retrieved
* @return Identity server for the given ID
* @throws ApplicationManagementException if error occurred while getting identity server
*/
IdentityServer getIdentityServer(int identityServerId) throws ApplicationManagementException; IdentityServer getIdentityServer(int identityServerId) throws ApplicationManagementException;
/**
*
* @return Available identity servers
* @throws ApplicationManagementException if error occurred while getting identity servers
*/
IdentityServerList getIdentityServers() throws ApplicationManagementException; IdentityServerList getIdentityServers() throws ApplicationManagementException;
/**
*
* @param identityServerId of the service provider
* @param spUID uid of the service provider
* @return Applications that are mapped to given service provider uid and identity server id
* @throws ApplicationManagementException
*/
List<Application> getSPApplications(int identityServerId, String spUID) throws ApplicationManagementException; List<Application> getSPApplications(int identityServerId, String spUID) throws ApplicationManagementException;
/**
* This method is responsible for creating a new application and mapping it the given service provider uid
* and identity server id
*
* @param app Application wrapper of the application that should be created
* @param identityServerId id of the identity server to which the created application should be mapped
* @param spId uid of the service provder to which the created application should be mapped
* @param <T> Application wrapper class which depends on application type (PUBLIC, ENTERPRISE & etc)
* @return Application bean of the created application
* @throws ApplicationManagementException if errors while creating and mapping the application
* @throws RequestValidatingException if app contains any invalid payload
*/
<T> Application createSPApplication(T app, int identityServerId, String spId) throws ApplicationManagementException, RequestValidatingException; <T> Application createSPApplication(T app, int identityServerId, String spId) throws ApplicationManagementException, RequestValidatingException;
/**
* Validates application ids of the applications that should be attached
*
* @param appIds application ids to be validated
* @throws ApplicationManagementException
*/
void validateAttachAppsRequest(int identityServerId, List<Integer> appIds) throws ApplicationManagementException; void validateAttachAppsRequest(int identityServerId, List<Integer> appIds) throws ApplicationManagementException;
/**
* Validates application ids of the applications that should be detached
*
* @param identityServerId id of identity server
* @param spId uid of service provider from which applications should be detached
* @param appIds applications ids to be detached
* @throws ApplicationManagementException
*/
void validateDetachAppsRequest(int identityServerId, String spId, List<Integer> appIds) throws ApplicationManagementException; void validateDetachAppsRequest(int identityServerId, String spId, List<Integer> appIds) throws ApplicationManagementException;
} }

View File

@ -79,6 +79,10 @@ public class CustomAppReleaseWrapper {
value = "binary file of the application") value = "binary file of the application")
private Base64File binaryFile; private Base64File binaryFile;
@ApiModelProperty(name = "icon",
value = "banner of the application")
private Base64File banner;
public String getReleaseType() { public String getReleaseType() {
return releaseType; return releaseType;
} }
@ -160,4 +164,12 @@ public class CustomAppReleaseWrapper {
public void setBinaryFile(Base64File binaryFile) { public void setBinaryFile(Base64File binaryFile) {
this.binaryFile = binaryFile; this.binaryFile = binaryFile;
} }
public Base64File getBanner() {
return banner;
}
public void setBanner(Base64File banner) {
this.banner = banner;
}
} }

View File

@ -82,6 +82,10 @@ public class EntAppReleaseWrapper {
value = "binary file of the application") value = "binary file of the application")
private Base64File binaryFile; private Base64File binaryFile;
@ApiModelProperty(name = "icon",
value = "banner of the application")
private Base64File banner;
public String getReleaseType() { public String getReleaseType() {
return releaseType; return releaseType;
} }
@ -161,4 +165,12 @@ public class EntAppReleaseWrapper {
public void setBinaryFile(Base64File binaryFile) { public void setBinaryFile(Base64File binaryFile) {
this.binaryFile = binaryFile; this.binaryFile = binaryFile;
} }
public Base64File getBanner() {
return banner;
}
public void setBanner(Base64File banner) {
this.banner = banner;
}
} }

View File

@ -82,6 +82,10 @@ public class PublicAppReleaseWrapper {
value = "icon of the application") value = "icon of the application")
private Base64File icon; private Base64File icon;
@ApiModelProperty(name = "icon",
value = "banner of the application")
private Base64File banner;
public String getReleaseType() { public String getReleaseType() {
return releaseType; return releaseType;
} }
@ -149,4 +153,12 @@ public class PublicAppReleaseWrapper {
public void setScreenshots(List<Base64File> screenshots) { public void setScreenshots(List<Base64File> screenshots) {
this.screenshots = screenshots; this.screenshots = screenshots;
} }
public Base64File getBanner() {
return banner;
}
public void setBanner(Base64File banner) {
this.banner = banner;
}
} }

View File

@ -73,6 +73,10 @@ public class WebAppReleaseWrapper {
value = "icon of the application") value = "icon of the application")
private Base64File icon; private Base64File icon;
@ApiModelProperty(name = "icon",
value = "banner of the application")
private Base64File banner;
public String getReleaseType() { public String getReleaseType() {
return releaseType; return releaseType;
} }
@ -140,4 +144,12 @@ public class WebAppReleaseWrapper {
public void setIcon(Base64File icon) { public void setIcon(Base64File icon) {
this.icon = icon; this.icon = icon;
} }
public Base64File getBanner() {
return banner;
}
public void setBanner(Base64File banner) {
this.banner = banner;
}
} }

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.core.dao; package io.entgra.application.mgt.core.dao;
import io.entgra.application.mgt.common.IdentityServer; import io.entgra.application.mgt.common.IdentityServer;
@ -7,47 +25,68 @@ import io.entgra.application.mgt.core.exception.ApplicationManagementDAOExceptio
import java.util.List; import java.util.List;
public interface SPApplicationDAO { public interface SPApplicationDAO {
/** /**
* *
* @param tenantId * @param identityServerId Id of identity server in which the service provider is in
* @return the application with the provided installer location * @param spUID Service provider uid of which the applications to be retrieved
* @throws ApplicationManagementDAOException * @return the service provider applications for the given service provider
* @throws ApplicationManagementDAOException if any db error occurred
*/ */
List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException; List<ApplicationDTO> getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException;
/** /**
* *
* @param tenantId * @param identityServerId Id of identity server in which the service provider is in
* @return the application with the provided installer location * @param spUID Id of the service provider to which the application should be mapped
* @throws ApplicationManagementDAOException * @param appId Id of the application that should be mapped
* @return Primary key of the new service provider and application mapping entry
* @throws ApplicationManagementDAOException if any db error occurred
*/ */
int attachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException; int attachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException;
/** /**
* *
* @param tenantId * @param identityServerId Id of identity server in which the service provider is in
* @return the application with the provided installer location * @param spUID Id of the service provider from which the application should be removed
* @throws ApplicationManagementDAOException * @param appId Id of the application that should be removed
* @throws ApplicationManagementDAOException if any db error occurred
*/ */
void detachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException; void detachSPApplication(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException;
/**
*
* @return All available identity servers
* @throws ApplicationManagementDAOException if any db error occurred
*/
List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException; List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException;
/**
*
* @param id Id of the Identity Server to be retrieved
* @return Identity Server of the given id
* @throws ApplicationManagementDAOException if any db error occurred
*/
IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException; IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException;
/** /**
* Verify whether application exist for given application name and device type. Because a name and device type is * Verify whether application exist for given identity server id, service provider id and application id.
* unique for an application. * Because if an application does not exist for those, it should not be mapped
* *
* @param appId id of the application. * @param appId Id of the application.
* @param identityServerId Id of the identity server.
* @param spUID UID of the service provider. * @param spUID UID of the service provider.
* @param tenantId ID of the tenant.
* @return ID of the ApplicationDTO.
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
boolean isSPApplicationExist(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException; boolean isSPApplicationExist(int identityServerId, String spUID, int appId, int tenantId) throws ApplicationManagementDAOException;
/**
* Delete application from all service providers if exists. When an application is deleted from the database
* it shoulbe be deleted from mapping table as well
*
* @param applicationId Id of the application to be deleted
* @throws ApplicationManagementDAOException if any db error occurred
*/
void deleteApplicationFromServiceProviders(int applicationId, int tenantId) throws ApplicationManagementDAOException; void deleteApplicationFromServiceProviders(int applicationId, int tenantId) throws ApplicationManagementDAOException;
} }

View File

@ -262,9 +262,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
ResultSet rs = null; ResultSet rs = null;
String sql = "SELECT count(AP_APP.ID) AS APP_COUNT " String sql = "SELECT count(AP_APP.ID) AS APP_COUNT "
+ "FROM AP_APP " + "FROM AP_APP "
+ "INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "
+ "INNER JOIN (SELECT ID FROM AP_APP) AS app_data ON app_data.ID = AP_APP.ID "
+ "WHERE AP_APP.TENANT_ID = ?"; + "WHERE AP_APP.TENANT_ID = ?";
if (filter == null) { if (filter == null) {

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.core.dao.impl.application.spapplication; package io.entgra.application.mgt.core.dao.impl.application.spapplication;
import io.entgra.application.mgt.common.IdentityServer; import io.entgra.application.mgt.common.IdentityServer;
@ -24,7 +42,7 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class); private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class);
@Override @Override
public List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException { public List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT * " String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try { try {
@ -52,7 +70,7 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
@Override @Override
public IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException { public IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT * " String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ? AND " + "WHERE TENANT_ID = ? AND "
+ "ID = ?"; + "ID = ?";
@ -181,7 +199,6 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e); throw new ApplicationManagementDAOException(msg, e);
} }
} }
@Override @Override
@ -196,7 +213,6 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
+ "AND AP_APP_ID = ? " + "AND AP_APP_ID = ? "
+ "AND IS_ID = ? " + "AND IS_ID = ? "
+ "AND TENANT_ID = ? "; + "AND TENANT_ID = ? ";
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
@ -231,7 +247,6 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
+ "AP_APP_ID, " + "AP_APP_ID, "
+ "IS_ID, TENANT_ID) " + "IS_ID, TENANT_ID) "
+ "VALUES (?, ?, ?, ?)"; + "VALUES (?, ?, ?, ?)";
int mappingId = -1;
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
@ -242,9 +257,9 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
stmt.executeUpdate(); stmt.executeUpdate();
try (ResultSet rs = stmt.getGeneratedKeys()) { try (ResultSet rs = stmt.getGeneratedKeys()) {
if (rs.next()) { if (rs.next()) {
mappingId = rs.getInt(1); return rs.getInt(1);
} }
return mappingId; return -1;
} }
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
@ -286,5 +301,4 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
} }
} }
} }

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.core.dao.impl.application.spapplication; package io.entgra.application.mgt.core.dao.impl.application.spapplication;
import io.entgra.application.mgt.common.IdentityServer; import io.entgra.application.mgt.common.IdentityServer;
@ -24,7 +42,7 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
@Override @Override
public List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException { public List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT * " String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try { try {
@ -52,7 +70,7 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
@Override @Override
public IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException { public IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT * " String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ? AND " + "WHERE TENANT_ID = ? AND "
+ "ID = ?"; + "ID = ?";
@ -231,7 +249,6 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
+ "AP_APP_ID, " + "AP_APP_ID, "
+ "IS_ID, TENANT_ID) " + "IS_ID, TENANT_ID) "
+ "VALUES (?, ?, ?, ?)"; + "VALUES (?, ?, ?, ?)";
int mappingId = -1;
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
@ -242,9 +259,9 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
stmt.executeUpdate(); stmt.executeUpdate();
try (ResultSet rs = stmt.getGeneratedKeys()) { try (ResultSet rs = stmt.getGeneratedKeys()) {
if (rs.next()) { if (rs.next()) {
mappingId = rs.getInt(1); return rs.getInt(1);
} }
return mappingId; return -1;
} }
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.core.dao.impl.application.spapplication; package io.entgra.application.mgt.core.dao.impl.application.spapplication;
import io.entgra.application.mgt.common.IdentityServer; import io.entgra.application.mgt.common.IdentityServer;
@ -24,7 +42,7 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S
@Override @Override
public List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException { public List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT * " String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try { try {
@ -52,7 +70,7 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S
@Override @Override
public IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException { public IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT * " String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ? AND " + "WHERE TENANT_ID = ? AND "
+ "ID = ?"; + "ID = ?";
@ -231,7 +249,6 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S
+ "AP_APP_ID, " + "AP_APP_ID, "
+ "IS_ID, TENANT_ID) " + "IS_ID, TENANT_ID) "
+ "VALUES (?, ?, ?, ?)"; + "VALUES (?, ?, ?, ?)";
int mappingId = -1;
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
@ -242,9 +259,9 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S
stmt.executeUpdate(); stmt.executeUpdate();
try (ResultSet rs = stmt.getGeneratedKeys()) { try (ResultSet rs = stmt.getGeneratedKeys()) {
if (rs.next()) { if (rs.next()) {
mappingId = rs.getInt(1); return rs.getInt(1);
} }
return mappingId; return -1;
} }
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.core.dao.impl.application.spapplication; package io.entgra.application.mgt.core.dao.impl.application.spapplication;
import io.entgra.application.mgt.common.IdentityServer; import io.entgra.application.mgt.common.IdentityServer;
@ -24,7 +42,7 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S
@Override @Override
public List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException { public List<IdentityServer> getIdentityServers(int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT * " String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
try { try {
@ -52,7 +70,7 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S
@Override @Override
public IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException { public IdentityServer getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException {
String sql = "SELECT * " String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD "
+ "FROM AP_IDENTITY_SERVER " + "FROM AP_IDENTITY_SERVER "
+ "WHERE TENANT_ID = ? AND " + "WHERE TENANT_ID = ? AND "
+ "ID = ?"; + "ID = ?";
@ -231,7 +249,6 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S
+ "AP_APP_ID, " + "AP_APP_ID, "
+ "IS_ID, TENANT_ID) " + "IS_ID, TENANT_ID) "
+ "VALUES (?, ?, ?, ?)"; + "VALUES (?, ?, ?, ?)";
int mappingId = -1;
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
@ -242,9 +259,9 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S
stmt.executeUpdate(); stmt.executeUpdate();
try (ResultSet rs = stmt.getGeneratedKeys()) { try (ResultSet rs = stmt.getGeneratedKeys()) {
if (rs.next()) { if (rs.next()) {
mappingId = rs.getInt(1); return rs.getInt(1);
} }
return mappingId; return -1;
} }
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {

View File

@ -19,6 +19,7 @@ package io.entgra.application.mgt.core.impl;
import io.entgra.application.mgt.common.Base64File; import io.entgra.application.mgt.common.Base64File;
import io.entgra.application.mgt.core.dao.SPApplicationDAO; import io.entgra.application.mgt.core.dao.SPApplicationDAO;
import io.entgra.application.mgt.core.util.ApplicationManagementUtil;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringEscapeUtils;
@ -137,112 +138,222 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public ApplicationReleaseDTO uploadEntAppReleaseArtifacts(EntAppReleaseWrapper releaseWrapper, ApplicationArtifact artifact, public <T> Application createApplication(T app) throws ApplicationManagementException {
String deviceType) throws ApplicationManagementException { ApplicationDTO applicationDTO = uploadReleaseArtifactIfExist(app);
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
return uploadEntAppReleaseArtifacts(releaseDTO, artifact, deviceType, tenantId, true);
}
@Override
public ApplicationDTO uploadEntAppReleaseArtifacts(ApplicationWrapper applicationWrapper,
ApplicationArtifact applicationArtifact)
throws ApplicationManagementException{
if (log.isDebugEnabled()) {
log.debug("Ent. Application create request is received. Application name: " + applicationWrapper.getName()
+ " Device type: " + applicationWrapper.getDeviceType());
}
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper);
//uploading application artifacts
ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts(
applicationDTO.getApplicationReleaseDTOs().get(0), applicationArtifact,
applicationWrapper.getDeviceType(), tenantId, false);
applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
return applicationDTO;
}
@Override
public ApplicationReleaseDTO uploadWebAppReleaseArtifacts(WebAppReleaseWrapper releaseWrapper, ApplicationArtifact artifact)
throws ResourceManagementException {
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
return uploadWebAppReleaseArtifacts(releaseDTO, artifact, tenantId);
}
@Override
public ApplicationDTO uploadWebAppReleaseArtifacts(WebAppWrapper webAppWrapper,
ApplicationArtifact applicationArtifact)
throws ApplicationManagementException{
if (log.isDebugEnabled()) {
log.debug("Web clip create request is received. App name: " + webAppWrapper.getName() + " Device type: "
+ Constants.ANY);
}
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper);
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
try { try {
applicationDTO.getApplicationReleaseDTOs().clear(); ConnectionManagerUtil.beginDBTransaction();
applicationDTO.getApplicationReleaseDTOs().add(uploadWebAppReleaseArtifacts(applicationReleaseDTO, applicationArtifact, tenantId)); Application application = addAppDataIntoDB(applicationDTO);
return applicationDTO; ConnectionManagerUtil.commitDBTransaction();
} catch (ResourceManagementException e) { return application;
String msg = "Error Occurred when uploading artifacts of the web clip: " + webAppWrapper.getName(); } catch (DBConnectionException e) {
log.error(msg); String msg = "Error occurred while getting database connection.";
log.error(msg, e);
ApplicationManagementUtil.deleteArtifactIfExist(applicationDTO);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while disabling AutoCommit.";
log.error(msg, e);
ApplicationManagementUtil.deleteArtifactIfExist(applicationDTO);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
ApplicationManagementUtil.deleteArtifactIfExist(applicationDTO);
String msg = "Error occurred while adding application with the name " + applicationDTO.getName() + " to database ";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public ApplicationRelease createEntAppRelease(int appId, EntAppReleaseWrapper releaseWrapper)
throws ApplicationManagementException {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(), releaseWrapper.getScreenshots(),
releaseWrapper.getBinaryFile(), releaseWrapper.getBanner());
ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
releaseDTO = uploadEntAppReleaseArtifacts(releaseDTO, artifact, deviceType.getName(), true);
try {
return createRelease(applicationDTO, releaseDTO, ApplicationType.ENTERPRISE);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating ent app release for application with the name: " + applicationDTO.getName();
log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(releaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
} }
public ApplicationReleaseDTO uploadWebAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO, ApplicationArtifact applicationArtifact, @Override
int tenantId) public ApplicationRelease createWebAppRelease(int appId, WebAppReleaseWrapper releaseWrapper)
throws ApplicationManagementException, ResourceManagementException {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), null, releaseWrapper.getBanner());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
releaseDTO = uploadWebAppReleaseArtifacts(releaseDTO, artifact);
try {
return createRelease(applicationDTO, releaseDTO, ApplicationType.WEB_CLIP);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating web app release for application with the name: " + applicationDTO.getName();
log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(releaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e);
}
}
@Override
public ApplicationRelease createPubAppRelease(int appId, PublicAppReleaseWrapper releaseWrapper) throws
ResourceManagementException, ApplicationManagementException {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), null, releaseWrapper.getBanner());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
releaseDTO = uploadPubAppReleaseArtifacts(releaseDTO, artifact, deviceType.getName());
try {
return createRelease(applicationDTO, releaseDTO, ApplicationType.PUBLIC);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating ent public release for application with the name: " + applicationDTO.getName();
log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(releaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e);
}
}
@Override
public ApplicationRelease createCustomAppRelease(int appId, CustomAppReleaseWrapper releaseWrapper)
throws ResourceManagementException, ApplicationManagementException {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), releaseWrapper.getBinaryFile(), releaseWrapper.getBanner());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
releaseDTO = uploadCustomAppReleaseArtifacts(releaseDTO, artifact, deviceType.getName());
try {
return createRelease(applicationDTO, releaseDTO, ApplicationType.CUSTOM);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating custom app release for application with the name: " + applicationDTO.getName();
log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(releaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e);
}
}
@Override
public <T> ApplicationDTO uploadReleaseArtifactIfExist(T app) throws ApplicationManagementException {
if (ApplicationManagementUtil.isReleaseAvailable(app)) {
return uploadReleaseArtifact(app);
}
return APIUtil.convertToAppDTO(app);
}
/**
* Upload release artifacts depending on the application wrapper type
*
* @param app Application wrapper bean
* @param <T> Application Wrapper class
* @return ApplicationDTO that is constructed after uploading the artifacts
* @throws ApplicationManagementException if any error occurred while uploading artifacts
*/
private <T> ApplicationDTO uploadReleaseArtifact(T app)
throws ApplicationManagementException {
ApplicationArtifact artifact;
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(app);
ApplicationReleaseDTO releaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
if (log.isDebugEnabled()) {
log.debug("Ent. Application create request is received. Application name: " + applicationDTO.getName());
}
try {
if (app instanceof ApplicationWrapper) {
ApplicationWrapper wrapper = (ApplicationWrapper) app;
EntAppReleaseWrapper releaseWrapper = wrapper.getEntAppReleaseWrappers().get(0);
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), releaseWrapper.getBinaryFile(), releaseWrapper.getBanner());
releaseDTO = uploadEntAppReleaseArtifacts(releaseDTO,
artifact, wrapper.getDeviceType(), false);
} else if (app instanceof PublicAppWrapper) {
PublicAppWrapper wrapper = (PublicAppWrapper) app;
PublicAppReleaseWrapper releaseWrapper = wrapper.getPublicAppReleaseWrappers().get(0);
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), null, releaseWrapper.getBanner());
releaseDTO = uploadPubAppReleaseArtifacts(releaseDTO, artifact, wrapper.getDeviceType());
} else if (app instanceof WebAppWrapper) {
WebAppWrapper wrapper = (WebAppWrapper) app;
WebAppReleaseWrapper releaseWrapper = wrapper.getWebAppReleaseWrappers().get(0);
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), null, releaseWrapper.getBanner());
releaseDTO = uploadWebAppReleaseArtifacts(releaseDTO, artifact);
} else if (app instanceof CustomAppWrapper) {
CustomAppWrapper wrapper = (CustomAppWrapper) app;
CustomAppReleaseWrapper releaseWrapper = wrapper.getCustomAppReleaseWrappers().get(0);
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), releaseWrapper.getBinaryFile(), releaseWrapper.getBanner());
try {
releaseDTO = uploadCustomAppReleaseArtifacts(releaseDTO, artifact, wrapper.getDeviceType());
} catch (ResourceManagementException e) {
String msg = "Error Occurred when uploading artifacts of the web clip: " + wrapper.getName();
log.error(msg);
throw new ApplicationManagementException(msg, e);
}
} else {
String msg = "Invalid payload found with the request. Hence verify the request payload object.";
log.error(msg);
throw new ApplicationManagementException(msg);
}
} catch (ResourceManagementException e) {
String msg = "Error Occurred when uploading artifacts of the web clip: " + applicationDTO.getName();
log.error(msg);
throw new ApplicationManagementException(msg, e);
}
applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(releaseDTO);
return applicationDTO;
}
/**
* Upload enterprise application release artifact into file system.
*
* @param releaseDTO Application Release
* @param applicationArtifact Application Release artifacts
* @param deviceTypeName Device Type name
* @param isNewRelease New Release or Not
* @return {@link ApplicationReleaseDTO}
* @throws ApplicationManagementException if error occurred while uploading artifacts into file system.
*/
private ApplicationReleaseDTO uploadEntAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO,
ApplicationArtifact applicationArtifact, String deviceTypeName, boolean isNewRelease)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(deviceTypeName, releaseDTO,
applicationArtifact, isNewRelease);
return addImageArtifacts(applicationReleaseDTO, applicationArtifact, tenantId);
} catch (ResourceManagementException e) {
String msg = "Error occurred while uploading application release artifacts.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
private ApplicationReleaseDTO uploadWebAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO, ApplicationArtifact applicationArtifact)
throws ResourceManagementException { throws ResourceManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
releaseDTO.setUuid(UUID.randomUUID().toString()); releaseDTO.setUuid(UUID.randomUUID().toString());
releaseDTO.setAppHashValue(DigestUtils.md5Hex(releaseDTO.getInstallerName())); releaseDTO.setAppHashValue(DigestUtils.md5Hex(releaseDTO.getInstallerName()));
//uploading application artifacts //uploading application artifacts
return addImageArtifacts(releaseDTO, applicationArtifact, tenantId); return addImageArtifacts(releaseDTO, applicationArtifact, tenantId);
} }
@Override private ApplicationReleaseDTO uploadPubAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO, ApplicationArtifact applicationArtifact,
public ApplicationReleaseDTO uploadPubAppReleaseArtifacts(PublicAppReleaseWrapper releaseWrapper, ApplicationArtifact artifact, String deviceType)
String deviceType) throws ResourceManagementException {
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
return uploadPubAppReleaseArtifacts(releaseDTO, artifact, deviceType, tenantId);
}
@Override
public ApplicationDTO uploadPublicAppReleaseArtifacts(PublicAppWrapper publicAppWrapper,
ApplicationArtifact applicationArtifact)
throws ApplicationManagementException{
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (log.isDebugEnabled()) {
log.debug("Public app creating request is received. App name: " + publicAppWrapper.getName()
+ " Device Type: " + publicAppWrapper.getDeviceType());
}
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(publicAppWrapper);
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
validatePublicAppReleasePackageName(applicationReleaseDTO.getPackageName());
try {
//uploading application artifacts
applicationReleaseDTO = uploadPubAppReleaseArtifacts(applicationReleaseDTO, applicationArtifact,
publicAppWrapper.getDeviceType(), tenantId);
applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
return applicationDTO;
} catch (ResourceManagementException e) {
String msg = "Error Occured when uploading artifacts of the public app: " + publicAppWrapper.getName();
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
public ApplicationReleaseDTO uploadPubAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO, ApplicationArtifact applicationArtifact,
String deviceType, int tenantId)
throws ResourceManagementException { throws ResourceManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String appInstallerUrl = getPublicAppStorePath(deviceType) + releaseDTO.getPackageName(); String appInstallerUrl = getPublicAppStorePath(deviceType) + releaseDTO.getPackageName();
releaseDTO.setInstallerName(appInstallerUrl); releaseDTO.setInstallerName(appInstallerUrl);
releaseDTO.setUuid(UUID.randomUUID().toString()); releaseDTO.setUuid(UUID.randomUUID().toString());
@ -273,38 +384,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
@Override private ApplicationReleaseDTO uploadCustomAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO, ApplicationArtifact applicationArtifact,
public ApplicationReleaseDTO uploadCustomAppReleaseArtifacts(CustomAppReleaseWrapper releaseWrapper, ApplicationArtifact artifact, String deviceType)
String deviceType) throws ResourceManagementException, ApplicationManagementException {
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
return uploadCustomAppReleaseArtifacts(releaseDTO, artifact, deviceType, tenantId);
}
@Override
public ApplicationDTO uploadCustomAppReleaseArtifactsAndConstructAppDTO(CustomAppWrapper customAppWrapper,
ApplicationArtifact applicationArtifact)
throws ApplicationManagementException {
try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(customAppWrapper);
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
applicationReleaseDTO = uploadCustomAppReleaseArtifacts(applicationReleaseDTO, applicationArtifact,
customAppWrapper.getDeviceType(), tenantId);
applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
return applicationDTO;
} catch (ResourceManagementException e) {
String msg = "Error occurred while uploading application artifact into the server. Application name: "
+ customAppWrapper.getName() + " Device type: " + customAppWrapper.getDeviceType();
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
public ApplicationReleaseDTO uploadCustomAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO, ApplicationArtifact applicationArtifact,
String deviceType, int tenantId)
throws ResourceManagementException, ApplicationManagementException { throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
byte[] content = getByteContentOfApp(applicationArtifact); byte[] content = getByteContentOfApp(applicationArtifact);
String md5OfApp = generateMD5OfApp(applicationArtifact, content); String md5OfApp = generateMD5OfApp(applicationArtifact, content);
@ -379,16 +462,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
/** /**
* Delete Application release artifacts * Delete Application release artifacts
* *
* @param directoryPaths Directory paths * @param directoryPaths Directory paths
* @param tenantId Tenant Id
* @throws ApplicationManagementException if error occurred while deleting application release artifacts. * @throws ApplicationManagementException if error occurred while deleting application release artifacts.
*/ */
private void deleteApplicationArtifacts(List<String> directoryPaths, int tenantId) throws ApplicationManagementException { @Override
public void deleteApplicationArtifacts(List<String> directoryPaths) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try { try {
applicationStorageManager.deleteAllApplicationReleaseArtifacts(directoryPaths, tenantId); applicationStorageManager.deleteAllApplicationReleaseArtifacts(directoryPaths, tenantId);
@ -693,7 +775,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
return applicationReleaseDTO; return applicationReleaseDTO;
} }
@Override @Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -950,32 +1031,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public Application persistApplication(ApplicationDTO applicationDTO) throws ApplicationManagementException { public Application addAppDataIntoDB(ApplicationDTO applicationDTO) throws
try {
ConnectionManagerUtil.beginDBTransaction();
Application application = executeApplicationPersistenceTransaction(applicationDTO);
ConnectionManagerUtil.commitDBTransaction();
return application;
} catch (DBConnectionException e) {
String msg = "Error occurred while getting database connection.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while disabling AutoCommit.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while adding application with the name " + applicationDTO.getName() + " to database ";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public Application executeApplicationPersistenceTransaction(ApplicationDTO applicationDTO) throws
ApplicationManagementException { ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationReleaseDTO applicationReleaseDTO = null; ApplicationReleaseDTO applicationReleaseDTO = null;
@ -986,10 +1042,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
// Insert to application table // Insert to application table
int appId = this.applicationDAO.createApplication(applicationDTO, tenantId); int appId = this.applicationDAO.createApplication(applicationDTO, tenantId);
if (appId == -1) { if (appId == -1) {
if (applicationReleaseDTO != null) {
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()),
tenantId);
}
String msg = "Application data storing is Failed."; String msg = "Application data storing is Failed.";
log.error(msg); log.error(msg);
throw new ApplicationManagementDAOException(msg); throw new ApplicationManagementDAOException(msg);
@ -1061,35 +1113,22 @@ public class ApplicationManagerImpl implements ApplicationManager {
String msg = String msg =
"Error occurred while adding lifecycle state. application name: " + applicationDTO.getName() + "."; "Error occurred while adding lifecycle state. application name: " + applicationDTO.getName() + ".";
log.error(msg, e); log.error(msg, e);
try {
APIUtil.getApplicationStorageManager().deleteAllApplicationReleaseArtifacts(
Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId);
} catch (ApplicationStorageManagementException ex) {
String errorLog =
"Error occurred when deleting application artifacts. Application artifacts are tried to "
+ "delete because of lifecycle state adding issue in the application creating operation.";
log.error(errorLog, ex);
throw new ApplicationManagementException(errorLog, ex);
}
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while adding application or application release. application name: " String msg = "Error occurred while adding application or application release. application name: "
+ applicationDTO.getName() + "."; + applicationDTO.getName() + ".";
log.error(msg, e); log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (LifecycleManagementException e) { } catch (LifecycleManagementException e) {
String msg = String msg =
"Error occurred when getting initial lifecycle state. application name: " + applicationDTO.getName() "Error occurred when getting initial lifecycle state. application name: " + applicationDTO.getName()
+ "."; + ".";
log.error(msg, e); log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (VisibilityManagementDAOException e) { } catch (VisibilityManagementDAOException e) {
String msg = "Error occurred while adding unrestricted roles. application name: " + applicationDTO.getName() String msg = "Error occurred while adding unrestricted roles. application name: " + applicationDTO.getName()
+ "."; + ".";
log.error(msg, e); log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
} }
@ -1103,7 +1142,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.debug("Application release creating request is received for the application id: " + applicationDTO.getId()); log.debug("Application release creating request is received for the application id: " + applicationDTO.getId());
} }
if (!type.toString().equals(applicationDTO.getType())) { if (!type.toString().equals(applicationDTO.getType())) {
String msg = "It is possible to add new application release for " + type String msg = "It is possible to add new application release for " + type
+ " app type. But you are requesting to add new application release for " + applicationDTO.getType() + " app type. But you are requesting to add new application release for " + applicationDTO.getType()
@ -1192,31 +1230,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
/**
* Upload enterprise application release artifact into file system.
*
* @param releaseDTO Apllication Release
* @param applicationArtifact Application Release artifacts
* @param deviceTypeName Device Type name
* @param tenantId Tenant Id
* @param isNewRelease New Release or Not
* @return {@link ApplicationReleaseDTO}
* @throws ApplicationManagementException if error occurred while uploading artifacts into file system.
*/
private ApplicationReleaseDTO uploadEntAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO,
ApplicationArtifact applicationArtifact, String deviceTypeName, int tenantId, boolean isNewRelease)
throws ApplicationManagementException {
try {
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(deviceTypeName, releaseDTO,
applicationArtifact, isNewRelease);
return addImageArtifacts(applicationReleaseDTO, applicationArtifact, tenantId);
} catch (ResourceManagementException e) {
String msg = "Error occurred while uploading application release artifacts.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
/** /**
* Check whether given OS range is valid or invalid * Check whether given OS range is valid or invalid
* *
@ -1373,7 +1386,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
@Override @Override
public Application getApplicationByUuid(String releaseUuid, String state) throws ApplicationManagementException { public Application getApplicationByUuid(String releaseUuid, String state) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -1658,9 +1670,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
if (applicationDTO.getApplicationReleaseDTOs().size() == 1) {
deleteApplication(applicationDTO, tenantId);
} else {
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) { for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
if (releaseUuid.equals(applicationReleaseDTO.getUuid())) { if (releaseUuid.equals(applicationReleaseDTO.getUuid())) {
if (!lifecycleStateManager.isDeletableState(applicationReleaseDTO.getCurrentState())) { if (!lifecycleStateManager.isDeletableState(applicationReleaseDTO.getCurrentState())) {
@ -1720,7 +1729,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
} }
}
@Override @Override
public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact) public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact)
@ -3187,9 +3195,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
@Override @Override
public <T> void validateAppCreatingRequest(T param, boolean isReleaseRequired) throws ApplicationManagementException { public <T> void validateAppCreatingRequest(T param) throws ApplicationManagementException, RequestValidatingException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int deviceTypeId = -1; int deviceTypeId = -1;
@ -3223,17 +3230,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationWrapper.getDeviceType()); DeviceType deviceType = APIUtil.getDeviceTypeData(applicationWrapper.getDeviceType());
deviceTypeId = deviceType.getId(); deviceTypeId = deviceType.getId();
List<EntAppReleaseWrapper> entAppReleaseWrappers;
entAppReleaseWrappers = applicationWrapper.getEntAppReleaseWrappers();
if (isReleaseRequired && entAppReleaseWrappers.size() != 1) {
String msg = "Invalid application creating request. Application creating request must have single "
+ "application release. Application name:" + applicationWrapper.getName() + ".";
log.error(msg);
throw new BadRequestException(msg);
}
unrestrictedRoles = applicationWrapper.getUnrestrictedRoles(); unrestrictedRoles = applicationWrapper.getUnrestrictedRoles();
List<EntAppReleaseWrapper> releaseWrappers = applicationWrapper.getEntAppReleaseWrappers();
if (!releaseWrappers.isEmpty()) {
EntAppReleaseWrapper releaseWrapper = releaseWrappers.get(0);
validateEntAppReleaseCreatingRequest(releaseWrapper, applicationWrapper.getDeviceType());
}
} else if (param instanceof WebAppWrapper) { } else if (param instanceof WebAppWrapper) {
WebAppWrapper webAppWrapper = (WebAppWrapper) param; WebAppWrapper webAppWrapper = (WebAppWrapper) param;
appName = webAppWrapper.getName(); appName = webAppWrapper.getName();
@ -3261,17 +3263,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
List<WebAppReleaseWrapper> webAppReleaseWrappers;
webAppReleaseWrappers = webAppWrapper.getWebAppReleaseWrappers();
if (isReleaseRequired && webAppReleaseWrappers.size() != 1) {
String msg = "Invalid web clip creating request. Web clip creating request must have single "
+ "web clip release. Web clip name:" + webAppWrapper.getName() + ".";
log.error(msg);
throw new BadRequestException(msg);
}
unrestrictedRoles = webAppWrapper.getUnrestrictedRoles(); unrestrictedRoles = webAppWrapper.getUnrestrictedRoles();
List<WebAppReleaseWrapper> releaseWrappers = webAppWrapper.getWebAppReleaseWrappers();
if(!releaseWrappers.isEmpty()) {
WebAppReleaseWrapper releaseWrapper = releaseWrappers.get(0);
validateWebAppReleaseCreatingRequest(releaseWrapper);
}
} else if (param instanceof PublicAppWrapper) { } else if (param instanceof PublicAppWrapper) {
PublicAppWrapper publicAppWrapper = (PublicAppWrapper) param; PublicAppWrapper publicAppWrapper = (PublicAppWrapper) param;
appName = publicAppWrapper.getName(); appName = publicAppWrapper.getName();
@ -3298,17 +3295,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
DeviceType deviceType = APIUtil.getDeviceTypeData(publicAppWrapper.getDeviceType()); DeviceType deviceType = APIUtil.getDeviceTypeData(publicAppWrapper.getDeviceType());
deviceTypeId = deviceType.getId(); deviceTypeId = deviceType.getId();
List<PublicAppReleaseWrapper> publicAppReleaseWrappers;
publicAppReleaseWrappers = publicAppWrapper.getPublicAppReleaseWrappers();
if (isReleaseRequired && publicAppReleaseWrappers.size() != 1) {
String msg = "Invalid public app creating request. Request must have single release. Application name:"
+ publicAppWrapper.getName() + ".";
log.error(msg);
throw new BadRequestException(msg);
}
unrestrictedRoles = publicAppWrapper.getUnrestrictedRoles(); unrestrictedRoles = publicAppWrapper.getUnrestrictedRoles();
List<PublicAppReleaseWrapper> releaseWrappers = publicAppWrapper.getPublicAppReleaseWrappers();
if(!releaseWrappers.isEmpty()) {
PublicAppReleaseWrapper releaseWrapper = releaseWrappers.get(0);
validatePublicAppReleaseCreatingRequest(releaseWrapper, publicAppWrapper.getDeviceType());
}
} else if (param instanceof CustomAppWrapper) { } else if (param instanceof CustomAppWrapper) {
CustomAppWrapper customAppWrapper = (CustomAppWrapper) param; CustomAppWrapper customAppWrapper = (CustomAppWrapper) param;
appName = customAppWrapper.getName(); appName = customAppWrapper.getName();
@ -3335,17 +3327,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
DeviceType deviceType = APIUtil.getDeviceTypeData(customAppWrapper.getDeviceType()); DeviceType deviceType = APIUtil.getDeviceTypeData(customAppWrapper.getDeviceType());
deviceTypeId = deviceType.getId(); deviceTypeId = deviceType.getId();
List<CustomAppReleaseWrapper> customAppReleaseWrappers;
customAppReleaseWrappers = customAppWrapper.getCustomAppReleaseWrappers();
if (isReleaseRequired && customAppReleaseWrappers.size() != 1) {
String msg = "Invalid custom app creating request. Application creating request must have single "
+ "application release. Application name:" + customAppWrapper.getName() + ".";
log.error(msg);
throw new BadRequestException(msg);
}
unrestrictedRoles = customAppWrapper.getUnrestrictedRoles(); unrestrictedRoles = customAppWrapper.getUnrestrictedRoles();
List<CustomAppReleaseWrapper> releaseWrappers = customAppWrapper.getCustomAppReleaseWrappers();
if(!releaseWrappers.isEmpty()) {
CustomAppReleaseWrapper releaseWrapper = releaseWrappers.get(0);
validateCustomAppReleaseCreatingRequest(releaseWrapper, customAppWrapper.getDeviceType());
}
} else { } else {
String msg = "Invalid payload found with the request. Hence verify the request payload object."; String msg = "Invalid payload found with the request. Hence verify the request payload object.";
log.error(msg); log.error(msg);
@ -3518,6 +3505,37 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
@Override
public void validateEntAppReleaseCreatingRequest(EntAppReleaseWrapper releaseWrapper, String deviceType)
throws RequestValidatingException, ApplicationManagementException {
validateReleaseCreatingRequest(releaseWrapper, deviceType);
validateBinaryArtifact(releaseWrapper.getBinaryFile());
validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
}
@Override
public void validateCustomAppReleaseCreatingRequest(CustomAppReleaseWrapper releaseWrapper, String deviceType)
throws RequestValidatingException, ApplicationManagementException {
validateReleaseCreatingRequest(releaseWrapper, deviceType);
validateBinaryArtifact(releaseWrapper.getBinaryFile());
validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
}
@Override
public void validateWebAppReleaseCreatingRequest(WebAppReleaseWrapper releaseWrapper)
throws RequestValidatingException, ApplicationManagementException {
validateReleaseCreatingRequest(releaseWrapper, Constants.ANY);
validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
}
@Override
public void validatePublicAppReleaseCreatingRequest(PublicAppReleaseWrapper releaseWrapper, String deviceType)
throws RequestValidatingException, ApplicationManagementException {
validateReleaseCreatingRequest(releaseWrapper, deviceType);
validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
validatePublicAppReleasePackageName(releaseWrapper.getPackageName());
}
@Override @Override
public void validateImageArtifacts(Base64File iconFile, List<Base64File> screenshots) public void validateImageArtifacts(Base64File iconFile, List<Base64File> screenshots)
throws RequestValidatingException { throws RequestValidatingException {

View File

@ -1,25 +1,33 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.core.impl; package io.entgra.application.mgt.core.impl;
import io.entgra.application.mgt.common.ApplicationArtifact;
import io.entgra.application.mgt.common.IdentityServer; import io.entgra.application.mgt.common.IdentityServer;
import io.entgra.application.mgt.common.IdentityServerList; import io.entgra.application.mgt.common.IdentityServerList;
import io.entgra.application.mgt.common.SPApplication; import io.entgra.application.mgt.common.SPApplication;
import io.entgra.application.mgt.common.dto.ApplicationDTO; import io.entgra.application.mgt.common.dto.ApplicationDTO;
import io.entgra.application.mgt.common.exception.ApplicationManagementException; import io.entgra.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.application.mgt.common.exception.DBConnectionException; import io.entgra.application.mgt.common.exception.DBConnectionException;
import io.entgra.application.mgt.common.exception.RequestValidatingException;
import io.entgra.application.mgt.common.exception.TransactionManagementException; import io.entgra.application.mgt.common.exception.TransactionManagementException;
import io.entgra.application.mgt.common.response.Application; import io.entgra.application.mgt.common.response.Application;
import io.entgra.application.mgt.common.services.ApplicationManager; import io.entgra.application.mgt.common.services.ApplicationManager;
import io.entgra.application.mgt.common.services.SPApplicationManager; import io.entgra.application.mgt.common.services.SPApplicationManager;
import io.entgra.application.mgt.common.wrapper.ApplicationWrapper;
import io.entgra.application.mgt.common.wrapper.CustomAppReleaseWrapper;
import io.entgra.application.mgt.common.wrapper.CustomAppWrapper;
import io.entgra.application.mgt.common.wrapper.EntAppReleaseWrapper;
import io.entgra.application.mgt.common.wrapper.PublicAppReleaseWrapper;
import io.entgra.application.mgt.common.wrapper.PublicAppWrapper;
import io.entgra.application.mgt.common.wrapper.WebAppReleaseWrapper;
import io.entgra.application.mgt.common.wrapper.WebAppWrapper;
import io.entgra.application.mgt.core.dao.ApplicationDAO; import io.entgra.application.mgt.core.dao.ApplicationDAO;
import io.entgra.application.mgt.core.dao.SPApplicationDAO; import io.entgra.application.mgt.core.dao.SPApplicationDAO;
import io.entgra.application.mgt.core.dao.VisibilityDAO; import io.entgra.application.mgt.core.dao.VisibilityDAO;
@ -31,12 +39,9 @@ import io.entgra.application.mgt.core.lifecycle.LifecycleStateManager;
import io.entgra.application.mgt.core.util.APIUtil; import io.entgra.application.mgt.core.util.APIUtil;
import io.entgra.application.mgt.core.util.ApplicationManagementUtil; import io.entgra.application.mgt.core.util.ApplicationManagementUtil;
import io.entgra.application.mgt.core.util.ConnectionManagerUtil; import io.entgra.application.mgt.core.util.ConnectionManagerUtil;
import io.entgra.application.mgt.core.util.Constants;
import io.entgra.application.mgt.core.util.SPApplicationManagementUtil;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -218,7 +223,6 @@ public class SPApplicationManagerImpl implements SPApplicationManager {
} }
} }
public void detachSPApplications(int identityServerId, String spUID, List<Integer> appIds) throws ApplicationManagementException { public void detachSPApplications(int identityServerId, String spUID, List<Integer> appIds) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
@ -239,54 +243,40 @@ public class SPApplicationManagerImpl implements SPApplicationManager {
} }
@Override @Override
public <T> Application createSPApplication(T app, int identityServerId, String spId) throws ApplicationManagementException, public <T> Application createSPApplication(T app, int identityServerId, String spId) throws ApplicationManagementException {
RequestValidatingException {
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance(); ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
applicationManager.validateAppCreatingRequest(app, false); ApplicationDTO applicationDTO = applicationManager.uploadReleaseArtifactIfExist(app);
ApplicationDTO applicationDTO = constructApplicationDTO(app); if (log.isDebugEnabled()) {
log.debug("Application release create request is received. Application name: " + applicationDTO.getName()
+ " Device type ID: " + applicationDTO.getDeviceTypeId());
}
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
Application createdApp = createSPApplication(applicationDTO); Application createdApp = applicationManager.addAppDataIntoDB(applicationDTO);
attachCreatedSPApplication(createdApp, identityServerId, spId); attachCreatedSPApplication(createdApp, identityServerId, spId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return createdApp; return createdApp;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occurred while getting database connection."; String msg = "Error occurred while getting database connection.";
log.error(msg, e); log.error(msg, e);
ApplicationManagementUtil.deleteArtifactIfExist(applicationDTO);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
String msg = "Error occurred while disabling AutoCommit."; String msg = "Error occurred while disabling AutoCommit.";
log.error(msg, e); log.error(msg, e);
ApplicationManagementUtil.deleteArtifactIfExist(applicationDTO);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while creating and attaching application with the name " + applicationDTO.getName() ; String msg = "Error occurred while creating and attaching application with the name " + applicationDTO.getName() ;
log.error(msg, e); log.error(msg, e);
ApplicationManagementUtil.deleteArtifactIfExist(applicationDTO);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
} }
private <T> ApplicationDTO constructApplicationDTO(T app) throws ApplicationManagementException,
RequestValidatingException {
if (ApplicationManagementUtil.isReleaseAvailable(app)) {
return uploadReleaseArtifactAndConstructApplicationDTO(app);
}
return APIUtil.convertToAppDTO(app);
}
public Application createSPApplication(ApplicationDTO applicationDTO) throws ApplicationManagementException {
if (log.isDebugEnabled()) {
log.debug("Application release create request is received. Application name: " + applicationDTO.getName()
+ " Device type ID: " + applicationDTO.getDeviceTypeId());
}
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
return applicationManager.executeApplicationPersistenceTransaction(applicationDTO);
}
public void attachCreatedSPApplication(Application createdApp, int identityServerId, String spUID) throws ApplicationManagementException { public void attachCreatedSPApplication(Application createdApp, int identityServerId, String spUID) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
@ -298,50 +288,4 @@ public class SPApplicationManagerImpl implements SPApplicationManager {
} }
} }
public <T> ApplicationDTO uploadReleaseArtifactAndConstructApplicationDTO(T app) throws ApplicationManagementException,
RequestValidatingException {
ApplicationArtifact artifact;
ApplicationDTO applicationDTO;
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
if (app instanceof ApplicationWrapper) {
ApplicationWrapper wrapper = (ApplicationWrapper) app;
EntAppReleaseWrapper releaseWrapper = wrapper.getEntAppReleaseWrappers().get(0);
applicationManager.validateReleaseCreatingRequest(releaseWrapper, wrapper.getDeviceType());
applicationManager.validateBinaryArtifact(releaseWrapper.getBinaryFile());
applicationManager.validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), releaseWrapper.getBinaryFile(), null);
applicationDTO = applicationManager.uploadEntAppReleaseArtifacts(wrapper, artifact);
} else if (app instanceof PublicAppWrapper) {
PublicAppWrapper wrapper = (PublicAppWrapper) app;
PublicAppReleaseWrapper releaseWrapper = wrapper.getPublicAppReleaseWrappers().get(0);
applicationManager.validateReleaseCreatingRequest(releaseWrapper, wrapper.getDeviceType());
applicationManager.validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), null, null);
applicationDTO = applicationManager.uploadPublicAppReleaseArtifacts(wrapper, artifact);
} else if (app instanceof WebAppWrapper) {
WebAppWrapper wrapper = (WebAppWrapper) app;
WebAppReleaseWrapper releaseWrapper = wrapper.getWebAppReleaseWrappers().get(0);
applicationManager.validateReleaseCreatingRequest(releaseWrapper, Constants.ANY);
applicationManager.validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), null, null);
applicationDTO = applicationManager.uploadWebAppReleaseArtifacts(wrapper, artifact);
} else if (app instanceof CustomAppWrapper) {
CustomAppWrapper wrapper = (CustomAppWrapper) app;
CustomAppReleaseWrapper releaseWrapper = wrapper.getCustomAppReleaseWrappers().get(0);
applicationManager.validateReleaseCreatingRequest(releaseWrapper, wrapper.getDeviceType());
applicationManager.validateBinaryArtifact(releaseWrapper.getBinaryFile());
applicationManager.validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), releaseWrapper.getBinaryFile(), null);
applicationDTO = applicationManager.uploadCustomAppReleaseArtifactsAndConstructAppDTO(wrapper, artifact);
} else {
String msg = "Invalid payload found with the request. Hence verify the request payload object.";
log.error(msg);
throw new ApplicationManagementException(msg);
}
return applicationDTO;
}
} }

View File

@ -18,12 +18,13 @@
package io.entgra.application.mgt.core.util; package io.entgra.application.mgt.core.util;
import io.entgra.application.mgt.common.ApplicationArtifact; import io.entgra.application.mgt.common.ApplicationArtifact;
import io.entgra.application.mgt.common.ApplicationSubscriptionType;
import io.entgra.application.mgt.common.ApplicationType;
import io.entgra.application.mgt.common.Base64File; import io.entgra.application.mgt.common.Base64File;
import io.entgra.application.mgt.common.FileDataHolder; import io.entgra.application.mgt.common.FileDataHolder;
import io.entgra.application.mgt.common.dto.ApplicationDTO;
import io.entgra.application.mgt.common.dto.ApplicationReleaseDTO;
import io.entgra.application.mgt.common.exception.ApplicationManagementException; import io.entgra.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.application.mgt.common.exception.RequestValidatingException; import io.entgra.application.mgt.common.exception.RequestValidatingException;
import io.entgra.application.mgt.common.exception.ResourceManagementException;
import io.entgra.application.mgt.common.services.SPApplicationManager; import io.entgra.application.mgt.common.services.SPApplicationManager;
import io.entgra.application.mgt.common.wrapper.ApplicationWrapper; import io.entgra.application.mgt.common.wrapper.ApplicationWrapper;
import io.entgra.application.mgt.common.wrapper.CustomAppReleaseWrapper; import io.entgra.application.mgt.common.wrapper.CustomAppReleaseWrapper;
@ -46,11 +47,10 @@ import io.entgra.application.mgt.core.config.Extension;
import io.entgra.application.mgt.core.lifecycle.LifecycleStateManager; import io.entgra.application.mgt.core.lifecycle.LifecycleStateManager;
import org.wso2.carbon.device.mgt.core.common.util.FileUtil; import org.wso2.carbon.device.mgt.core.common.util.FileUtil;
import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.ArrayList; import java.util.Collections;
import java.util.Base64; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
@ -63,6 +63,16 @@ public class ApplicationManagementUtil {
private static Log log = LogFactory.getLog(ApplicationManagementUtil.class); private static Log log = LogFactory.getLog(ApplicationManagementUtil.class);
/**
* Construct ApplicationArtifact from given base64 artifact files
*
* @param iconBase64 icon of the application
* @param screenshotsBase64 screenshots of the application
* @param binaryFileBase64 binary file of the application
* @param bannerFileBase64 banner of the application
* @return ApplicationArtifact the give base64 release artifact files
* @throws BadRequestException if any invalid payload is found
*/
public static ApplicationArtifact constructApplicationArtifact(Base64File iconBase64, List<Base64File> screenshotsBase64, public static ApplicationArtifact constructApplicationArtifact(Base64File iconBase64, List<Base64File> screenshotsBase64,
Base64File binaryFileBase64, Base64File bannerFileBase64) Base64File binaryFileBase64, Base64File bannerFileBase64)
throws BadRequestException { throws BadRequestException {
@ -107,6 +117,8 @@ public class ApplicationManagementUtil {
if (screenshotsBase64 != null) { if (screenshotsBase64 != null) {
Map<String, InputStream> screenshotData = new TreeMap<>(); Map<String, InputStream> screenshotData = new TreeMap<>();
// This is to handle cases in which multiple screenshots have the same name
Map<String, Integer> screenshotNameCount = new HashMap<>();
for (Base64File screenshot : screenshotsBase64) { for (Base64File screenshot : screenshotsBase64) {
try { try {
applicationManager.validateBase64File(screenshot); applicationManager.validateBase64File(screenshot);
@ -116,13 +128,21 @@ public class ApplicationManagementUtil {
throw new BadRequestException(msg, e); throw new BadRequestException(msg, e);
} }
FileDataHolder screenshotFile = base64FileToFileDataHolder(screenshot); FileDataHolder screenshotFile = base64FileToFileDataHolder(screenshot);
screenshotData.put(screenshotFile.getName(), screenshotFile.getFile()); String screenshotName = screenshotFile.getName();
screenshotNameCount.put(screenshotName, screenshotNameCount.getOrDefault(screenshotName, 0) + 1);
screenshotName = FileUtil.generateDuplicateFileName(screenshotName, screenshotNameCount.get(screenshotName));
screenshotData.put(screenshotName, screenshotFile.getFile());
} }
applicationArtifact.setScreenshots(screenshotData); applicationArtifact.setScreenshots(screenshotData);
} }
return applicationArtifact; return applicationArtifact;
} }
/**
*
* @param base64File Base64File that should be converted to FileDataHolder bean
* @return FileDataHolder bean which contains input stream and name of the file
*/
public static FileDataHolder base64FileToFileDataHolder(Base64File base64File) { public static FileDataHolder base64FileToFileDataHolder(Base64File base64File) {
InputStream stream = FileUtil.base64ToInputStream(base64File.getBase64String()); InputStream stream = FileUtil.base64ToInputStream(base64File.getBase64String());
return new FileDataHolder(base64File.getName(), stream); return new FileDataHolder(base64File.getName(), stream);
@ -165,6 +185,27 @@ public class ApplicationManagementUtil {
return getInstance(extension, LifecycleStateManager.class); return getInstance(extension, LifecycleStateManager.class);
} }
/**
* This is useful to delete application artifacts if any error occurred while creating release/application
* after uploading the artifacts
*
* @param app ApplicationDTO of the application of which the artifacts should be deleted
* @throws ApplicationManagementException if error occurred while deleting artifacts
*/
public static <T> void deleteArtifactIfExist(ApplicationDTO app) throws ApplicationManagementException {
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
if (!app.getApplicationReleaseDTOs().isEmpty()) {
applicationManager.deleteApplicationArtifacts(Collections.singletonList(app.getApplicationReleaseDTOs().get(0).getAppHashValue()));
}
}
/**
* Check if application release available for a given application wrapper. This is useful since
* if a release is available for an application that needs to handled separately
*
* @param appWrapper Application wrapper bean of the application
* @return if release is available or not
*/
public static <T> boolean isReleaseAvailable(T appWrapper) { public static <T> boolean isReleaseAvailable(T appWrapper) {
if (appWrapper instanceof ApplicationWrapper) { if (appWrapper instanceof ApplicationWrapper) {
List<EntAppReleaseWrapper> entAppReleaseWrappers = ((ApplicationWrapper) appWrapper).getEntAppReleaseWrappers(); List<EntAppReleaseWrapper> entAppReleaseWrappers = ((ApplicationWrapper) appWrapper).getEntAppReleaseWrappers();

View File

@ -194,7 +194,7 @@ public class DAOUtil {
* To create application object from the result set retrieved from the Database. * To create application object from the result set retrieved from the Database.
* *
* @param rs ResultSet * @param rs ResultSet
* @return List of Applications that is retrieved from the Database. * @return List of Identity Servers that is retrieved from the Database.
* @throws SQLException SQL Exception * @throws SQLException SQL Exception
* @throws JSONException JSONException. * @throws JSONException JSONException.
*/ */
@ -215,7 +215,6 @@ public class DAOUtil {
return identityServers; return identityServers;
} }
/** /**
* To create application object from the result set retrieved from the Database. * To create application object from the result set retrieved from the Database.
* *

View File

@ -1,40 +0,0 @@
/*
* Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.ArrayList;
import java.util.List;
/**
* This DAOUtil class is responsible for making sure single instance of each Extension Manager is used throughout for
* all the tasks.
*/
public class SPApplicationManagementUtil {
private static Log log = LogFactory.getLog(SPApplicationManagementUtil.class);
private static List<String> getDefaultSPAppCategories() {
List<String> categories = new ArrayList<>();
categories.add(Constants.SP_APP_CATEGORY);
return categories;
}
}

View File

@ -122,8 +122,7 @@ public class ApplicationManagementTest extends BaseTestCase {
applicationArtifact.setScreenshots(screenshots); applicationArtifact.setScreenshots(screenshots);
ApplicationManager manager = new ApplicationManagerImpl(); ApplicationManager manager = new ApplicationManagerImpl();
ApplicationDTO applicationDTO = manager.uploadEntAppReleaseArtifacts(applicationWrapper, applicationArtifact); manager.createApplication(applicationWrapper);
manager.persistApplication(applicationDTO);
} }
@DataProvider(name = "applicationIdDataProvider") @DataProvider(name = "applicationIdDataProvider")

View File

@ -17,6 +17,7 @@
*/ */
package io.entgra.application.mgt.publisher.api.services; package io.entgra.application.mgt.publisher.api.services;
import io.entgra.application.mgt.common.Base64File;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
@ -27,8 +28,6 @@ import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info; import io.swagger.annotations.Info;
import io.swagger.annotations.SwaggerDefinition; import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag; import io.swagger.annotations.Tag;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.apimgt.annotations.api.Scopes;
import io.entgra.application.mgt.common.ApplicationList; import io.entgra.application.mgt.common.ApplicationList;
@ -284,7 +283,7 @@ public interface ApplicationManagementPublisherAPI {
@POST @POST
@Path("/ent-app") @Path("/ent-app")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -318,42 +317,12 @@ public interface ApplicationManagementPublisherAPI {
name = "application", name = "application",
value = "The application that need to be created.", value = "The application that need to be created.",
required = true) required = true)
@Multipart("application") ApplicationWrapper application, ApplicationWrapper application);
@ApiParam(
name = "binaryFile",
value = "Binary file of uploading application",
required = true)
@Multipart(value = "binaryFile") Attachment binaryFile,
@ApiParam(
name = "icon",
value = "Icon of the uploading application",
required = true)
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "Banner of the uploading application")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "Screen Shots of the uploading application",
required = true)
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Screen Shots of the uploading application",
required = false)
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Screen Shots of the uploading application",
required = false)
@Multipart(value = "screenshot3") Attachment screenshot3
);
@POST @POST
@Path("/web-app") @Path("/web-app")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -387,37 +356,13 @@ public interface ApplicationManagementPublisherAPI {
name = "webapp", name = "webapp",
value = "The web app that need to be created.", value = "The web app that need to be created.",
required = true) required = true)
@Multipart("webapp") WebAppWrapper webAppWrapper, WebAppWrapper webAppWrapper
@ApiParam(
name = "icon",
value = "Icon of the uploading web app",
required = true)
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "Banner of the uploading web app")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "Screen Shots of the uploading web app",
required = true)
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Screen Shots of the uploading web app",
required = false)
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Screen Shots of the uploading web app",
required = false)
@Multipart(value = "screenshot3") Attachment screenshot3
); );
@POST @POST
@Path("/public-app") @Path("/public-app")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -451,35 +396,13 @@ public interface ApplicationManagementPublisherAPI {
name = "public-app", name = "public-app",
value = "The public app that need to be created.", value = "The public app that need to be created.",
required = true) required = true)
@Multipart("public-app") PublicAppWrapper publicAppWrapper, PublicAppWrapper publicAppWrapper
@ApiParam(
name = "icon",
value = "Icon of the uploading public app",
required = true)
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "Banner of the uploading public app")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "Screen Shots of the uploading public app",
required = true)
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Screen Shots of the uploading public app")
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Screen Shots of the uploading public app")
@Multipart(value = "screenshot3") Attachment screenshot3
); );
@POST @POST
@Path("/custom-app") @Path("/custom-app")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -513,41 +436,12 @@ public interface ApplicationManagementPublisherAPI {
name = "application", name = "application",
value = "The application that need to be created.", value = "The application that need to be created.",
required = true) required = true)
@Multipart("application") CustomAppWrapper customAppWrapper, CustomAppWrapper customAppWrapper
@ApiParam(
name = "binaryFile",
value = "Binary file of uploading application",
required = true)
@Multipart(value = "binaryFile") Attachment binaryFile,
@ApiParam(
name = "icon",
value = "Icon of the uploading application",
required = true)
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "Banner of the uploading application")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "Screen Shots of the uploading application",
required = true)
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Screen Shots of the uploading application",
required = false)
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Screen Shots of the uploading application",
required = false)
@Multipart(value = "screenshot3") Attachment screenshot3
); );
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/{deviceType}/ent-app/{appId}") @Path("/{deviceType}/ent-app/{appId}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
@ -592,41 +486,12 @@ public interface ApplicationManagementPublisherAPI {
name = "applicationRelease", name = "applicationRelease",
value = "The application release that need to be created.", value = "The application release that need to be created.",
required = true) required = true)
@Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper, EntAppReleaseWrapper entAppReleaseWrapper
@ApiParam(
name = "binaryFile",
value = "Binary file of uploading application",
required = true)
@Multipart(value = "binaryFile") Attachment binaryFile,
@ApiParam(
name = "icon",
value = "Icon of the uploading application",
required = true)
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "Banner of the uploading application")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "Screen Shots of the uploading application",
required = true)
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Screen Shots of the uploading application",
required = false)
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Screen Shots of the uploading application",
required = false)
@Multipart(value = "screenshot3") Attachment screenshot3
); );
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/{deviceType}/public-app/{appId}") @Path("/{deviceType}/public-app/{appId}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
@ -671,36 +536,12 @@ public interface ApplicationManagementPublisherAPI {
name = "applicationRelease", name = "applicationRelease",
value = "The application release that need to be created.", value = "The application release that need to be created.",
required = true) required = true)
@Multipart("applicationRelease") PublicAppReleaseWrapper publicAppReleaseWrapper, PublicAppReleaseWrapper publicAppReleaseWrapper
@ApiParam(
name = "icon",
value = "Icon of the uploading application",
required = true)
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "Banner of the uploading application")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "Screen Shots of the uploading application",
required = true)
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Screen Shots of the uploading application",
required = false)
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Screen Shots of the uploading application",
required = false)
@Multipart(value = "screenshot3") Attachment screenshot3
); );
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/web-app/{appId}") @Path("/web-app/{appId}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
@ -740,36 +581,12 @@ public interface ApplicationManagementPublisherAPI {
name = "applicationRelease", name = "applicationRelease",
value = "The application release that need to be created.", value = "The application release that need to be created.",
required = true) required = true)
@Multipart("applicationRelease") WebAppReleaseWrapper webAppReleaseWrapper, WebAppReleaseWrapper webAppReleaseWrapper
@ApiParam(
name = "icon",
value = "Icon of the uploading application",
required = true)
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "Banner of the uploading application")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "Screen Shots of the uploading application",
required = true)
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Screen Shots of the uploading application",
required = false)
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Screen Shots of the uploading application",
required = false)
@Multipart(value = "screenshot3") Attachment screenshot3
); );
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/{deviceType}/custom-app/{appId}") @Path("/{deviceType}/custom-app/{appId}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
@ -814,42 +631,13 @@ public interface ApplicationManagementPublisherAPI {
name = "applicationRelease", name = "applicationRelease",
value = "The application release that need to be created.", value = "The application release that need to be created.",
required = true) required = true)
@Multipart("applicationRelease") CustomAppReleaseWrapper customAppReleaseWrapper, CustomAppReleaseWrapper customAppReleaseWrapper
@ApiParam(
name = "binaryFile",
value = "Binary file of uploading application",
required = true)
@Multipart(value = "binaryFile") Attachment binaryFile,
@ApiParam(
name = "icon",
value = "Icon of the uploading application",
required = true)
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "Banner of the uploading application")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "Screen Shots of the uploading application",
required = true)
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Screen Shots of the uploading application",
required = false)
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Screen Shots of the uploading application",
required = false)
@Multipart(value = "screenshot3") Attachment screenshot3
); );
@PUT @PUT
@Path("/image-artifacts/{uuid}") @Path("/image-artifacts/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA, consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -885,23 +673,15 @@ public interface ApplicationManagementPublisherAPI {
@ApiParam( @ApiParam(
name = "icon", name = "icon",
value = "Icon of the uploading application") value = "Icon of the uploading application")
@Multipart(value = "icon") Attachment iconFile, Base64File iconFile,
@ApiParam( @ApiParam(
name = "banner", name = "banner",
value = "Banner of the uploading application") value = "Banner of the uploading application")
@Multipart(value = "banner") Attachment bannerFile, Base64File bannerFile,
@ApiParam( @ApiParam(
name = "screenshot1", name = "screenshot1",
value = "Screen Shots of the uploading application") value = "Screen Shots of the uploading application")
@Multipart(value = "screenshot1") Attachment screenshot1, List<Base64File> screenshots
@ApiParam(
name = "screenshot2",
value = "Screen Shots of the uploading application")
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Screen Shots of the uploading application")
@Multipart(value = "screenshot3") Attachment screenshot3
); );
@GET @GET
@ -951,7 +731,7 @@ public interface ApplicationManagementPublisherAPI {
@PUT @PUT
@Path("/ent-app-artifacts/{deviceType}/{appId}/{uuid}") @Path("/ent-app-artifacts/{deviceType}/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA, consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -994,13 +774,13 @@ public interface ApplicationManagementPublisherAPI {
value = "UUID of the application", value = "UUID of the application",
required = true) required = true)
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@Multipart("binaryFile") Attachment binaryFile Base64File binaryFile
); );
@PUT @PUT
@Path("/ent-app-release/{uuid}") @Path("/ent-app-release/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA, consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -1039,39 +819,12 @@ public interface ApplicationManagementPublisherAPI {
name = "entAppReleaseWrapper", name = "entAppReleaseWrapper",
value = "Application release wrapper which is going to update.", value = "Application release wrapper which is going to update.",
required = true) required = true)
@Multipart( EntAppReleaseWrapper entAppReleaseWrapper);
value = "entAppReleaseWrapper",
type = "application/json") EntAppReleaseWrapper entAppReleaseWrapper,
@ApiParam(
name = "binaryFile",
value = "Application installer file.",
required = true)
@Multipart(value = "binaryFile") Attachment binaryFile,
@ApiParam(
name = "icon",
value = "Icon file of the application release.")
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "banner file of the application release.")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "First screenshot of the uploading application")
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Second screenshot 2 of the uploading application")
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Third screenshot of the uploading application")
@Multipart(value = "screenshot3") Attachment screenshot3);
@PUT @PUT
@Path("/public-app-release/{uuid}") @Path("/public-app-release/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA, consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -1110,34 +863,12 @@ public interface ApplicationManagementPublisherAPI {
name = "pubAppReleaseWrapper", name = "pubAppReleaseWrapper",
value = "Application release wrapper which is going to update.", value = "Application release wrapper which is going to update.",
required = true) required = true)
@Multipart( PublicAppReleaseWrapper publicAppReleaseWrapper);
value = "pubAppReleaseWrapper",
type = "application/json") PublicAppReleaseWrapper publicAppReleaseWrapper,
@ApiParam(
name = "icon",
value = "Icon file of the application release.")
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "banner file of the application release.")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "First screenshot of the uploading application")
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Second screenshot 2 of the uploading application")
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Third screenshot of the uploading application")
@Multipart(value = "screenshot3") Attachment screenshot3);
@PUT @PUT
@Path("/web-app-release/{uuid}") @Path("/web-app-release/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA, consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -1176,34 +907,13 @@ public interface ApplicationManagementPublisherAPI {
name = "pubAppReleaseWrapper", name = "pubAppReleaseWrapper",
value = "Application release wrapper which is going to update.", value = "Application release wrapper which is going to update.",
required = true) required = true)
@Multipart( WebAppReleaseWrapper webAppReleaseWrapper
value = "pubAppReleaseWrapper", );
type = "application/json") WebAppReleaseWrapper webAppReleaseWrapper,
@ApiParam(
name = "icon",
value = "Icon file of the application release.")
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "banner file of the application release.")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "First screenshot of the uploading application")
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Second screenshot 2 of the uploading application")
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Third screenshot of the uploading application")
@Multipart(value = "screenshot3") Attachment screenshot3);
@PUT @PUT
@Path("/custom-app-release/{uuid}") @Path("/custom-app-release/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA, consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -1242,34 +952,7 @@ public interface ApplicationManagementPublisherAPI {
name = "entAppReleaseWrapper", name = "entAppReleaseWrapper",
value = "Application release wrapper which is going to update.", value = "Application release wrapper which is going to update.",
required = true) required = true)
@Multipart( CustomAppReleaseWrapper customAppReleaseWrapper);
value = "entAppReleaseWrapper",
type = "application/json") CustomAppReleaseWrapper customAppReleaseWrapper,
@ApiParam(
name = "binaryFile",
value = "Application installer file.",
required = true)
@Multipart(value = "binaryFile") Attachment binaryFile,
@ApiParam(
name = "icon",
value = "Icon file of the application release.")
@Multipart(value = "icon") Attachment iconFile,
@ApiParam(
name = "banner",
value = "banner file of the application release.")
@Multipart(value = "banner") Attachment bannerFile,
@ApiParam(
name = "screenshot1",
value = "First screenshot of the uploading application")
@Multipart(value = "screenshot1") Attachment screenshot1,
@ApiParam(
name = "screenshot2",
value = "Second screenshot 2 of the uploading application")
@Multipart(value = "screenshot2") Attachment screenshot2,
@ApiParam(
name = "screenshot3",
value = "Third screenshot of the uploading application")
@Multipart(value = "screenshot3") Attachment screenshot3);
@GET @GET
@Path("/life-cycle/state-changes/{uuid}") @Path("/life-cycle/state-changes/{uuid}")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
@ -38,20 +38,14 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.List; import java.util.List;
/**
* This is the application registration service that exposed for apimApplicationRegistration
*/
@SwaggerDefinition( @SwaggerDefinition(
info = @Info( info = @Info(
version = "1.0.0", version = "1.0.0",
title = "Service Provider Application Management Publisher Service", title = "Service Provider Application Management Service",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = "name", value = "SPApplicationService"), @ExtensionProperty(name = "name", value = "SPApplicationService"),
@ -67,28 +61,28 @@ import java.util.List;
scopes = { scopes = {
@Scope( @Scope(
name = "view a service provider applications", name = "view a service provider applications",
description = "Get application details", description = "Get service provider application details",
key = "perm:app:publisher:service-provider:view", key = "perm:app:publisher:service-provider:view",
roles = {"Internal/devicemgt-user"}, roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/publisher/service-provider/application/view"} permissions = {"/app-mgt/publisher/service-provider/application/view"}
), ),
@Scope( @Scope(
name = "Create a service provider application", name = "Create a service provider application",
description = "Update an application", description = "Create an application and attach (map) to service provider",
key = "perm:app:publisher:service-provider:create", key = "perm:app:publisher:service-provider:create",
roles = {"Internal/devicemgt-user"}, roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/publisher/service-provider/application/create"} permissions = {"/app-mgt/publisher/service-provider/application/create"}
), ),
@Scope( @Scope(
name = "Attach a service provider application", name = "Attach a service provider application",
description = "Update an application", description = "Map an application to service provider",
key = "perm:app:publisher:service-provider:attach", key = "perm:app:publisher:service-provider:attach",
roles = {"Internal/devicemgt-user"}, roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/publisher/service-provider/application/attach"} permissions = {"/app-mgt/publisher/service-provider/application/attach"}
), ),
@Scope( @Scope(
name = "Detach a service provider application", name = "Detach a service provider application",
description = "Update an application", description = "Remove an application from service provider",
key = "perm:app:publisher:service-provider:detach", key = "perm:app:publisher:service-provider:detach",
roles = {"Internal/devicemgt-user"}, roles = {"Internal/devicemgt-user"},
permissions = {"/app-mgt/publisher/service-provider/application/detach"} permissions = {"/app-mgt/publisher/service-provider/application/detach"}
@ -102,18 +96,14 @@ public interface SPApplicationService {
String SCOPE = "scope"; String SCOPE = "scope";
/**
* This method is used to register an APIM application for tenant domain.
*/
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/identity-servers") @Path("/identity-servers")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "get the application of requesting application id and state", value = "get all identity servers",
notes = "This will get the application identified by the application id and state, if exists", tags = "Identity Server Management",
tags = "ApplicationDTO Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view") @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
@ -128,9 +118,8 @@ public interface SPApplicationService {
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "get the application of requesting application id and state", value = "get identity server by id",
notes = "This will get the application identified by the application id and state, if exists", tags = "Identity Server Management",
tags = "ApplicationDTO Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view") @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
@ -148,9 +137,9 @@ public interface SPApplicationService {
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "get the application of requesting application id and state", value = "get service providers by identity server id",
notes = "This will get the application identified by the application id and state, if exists", notes = "This will get service providers with the existing applications",
tags = "ApplicationDTO Management", tags = "Service Provider Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view") @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:view")
@ -160,15 +149,15 @@ public interface SPApplicationService {
Response getServiceProviders(@QueryParam("limit") Integer limit, @QueryParam("offset") Integer offset, Response getServiceProviders(@QueryParam("limit") Integer limit, @QueryParam("offset") Integer offset,
@PathParam("identity-server-id") int identityServerId); @PathParam("identity-server-id") int identityServerId);
@Path("/{identity-server-id}/{service-provider-id}/attach") @Path("/{identity-server-id}/service-provider/{service-provider-id}/applications")
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "get the application of requesting application id and state", value = "map application to service provider",
notes = "This will get the application identified by the application id and state, if exists", notes = "This will map a given list application ids with the given service provider id",
tags = "ApplicationDTO Management", tags = "Service Provider Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:attach") @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:attach")
@ -181,15 +170,15 @@ public interface SPApplicationService {
/** /**
* This method is used to register an APIM application for tenant domain. * This method is used to register an APIM application for tenant domain.
*/ */
@Path("/{identity-server-id}/{service-provider-id}/detach") @Path("/{identity-server-id}/service-provider/{service-provider-id}/delete/applications")
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "get the application of requesting application id and state", value = "Remove mapping with service provider of the given application ids",
notes = "This will get the application identified by the application id and state, if exists", notes = "This will remove applications from service provider",
tags = "ApplicationDTO Management", tags = "Service Provider Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:detach") @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:detach")
@ -202,15 +191,15 @@ public interface SPApplicationService {
/** /**
* This method is used to register an APIM application for tenant domain. * This method is used to register an APIM application for tenant domain.
*/ */
@Path("/{identity-server-id}/{service-provider-id}/create/ent-app") @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/ent-app")
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "get the application of requesting application id and state", value = "Create enterprise application and attach to service provider",
notes = "This will get the application identified by the application id and state, if exists", notes = "This will get create an enterprise application and map with service provider",
tags = "ApplicationDTO Management", tags = "Service Provider Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create") @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create")
@ -220,19 +209,18 @@ public interface SPApplicationService {
Response createEntApp(@PathParam("identity-server-id") int identityServerId, Response createEntApp(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, ApplicationWrapper app); @PathParam("service-provider-id") String serviceProviderId, ApplicationWrapper app);
/** /**
* This method is used to register an APIM application for tenant domain. * This method is used to register an APIM application for tenant domain.
*/ */
@Path("/{identity-server-id}/{service-provider-id}/create/public-app") @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/public-app")
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "get the application of requesting application id and state", value = "Create public application and attach to service provider",
notes = "This will get the application identified by the application id and state, if exists", notes = "This will get create a public application and map with service provider",
tags = "ApplicationDTO Management", tags = "Service Provider Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create") @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create")
@ -242,15 +230,15 @@ public interface SPApplicationService {
Response createPubApp(@PathParam("identity-server-id") int identityServerId, Response createPubApp(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, PublicAppWrapper app); @PathParam("service-provider-id") String serviceProviderId, PublicAppWrapper app);
@Path("/{identity-server-id}/{service-provider-id}/create/web-app") @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/web-app")
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "get the application of requesting application id and state", value = "Create web application and attach to service provider",
notes = "This will get the application identified by the application id and state, if exists", notes = "This will get create a web application and map with service provider",
tags = "ApplicationDTO Management", tags = "Service Provider Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create") @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create")
@ -260,15 +248,15 @@ public interface SPApplicationService {
Response createWebApp(@PathParam("identity-server-id") int identityServerId, Response createWebApp(@PathParam("identity-server-id") int identityServerId,
@PathParam("service-provider-id") String serviceProviderId, WebAppWrapper app); @PathParam("service-provider-id") String serviceProviderId, WebAppWrapper app);
@Path("/{identity-server-id}/{service-provider-id}/create/custom-app") @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/custom-app")
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "get the application of requesting application id and state", value = "Create custom application and attach to service provider",
notes = "This will get the application identified by the application id and state, if exists", notes = "This will get create an custom application and map with service provider",
tags = "ApplicationDTO Management", tags = "Service Provider Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create") @ExtensionProperty(name = SCOPE, value = "perm:app:publisher:service-provider:create")

View File

@ -16,14 +16,15 @@
*/ */
package io.entgra.application.mgt.publisher.api.services.impl; package io.entgra.application.mgt.publisher.api.services.impl;
import io.entgra.application.mgt.common.dto.ApplicationDTO; import io.entgra.application.mgt.common.ApplicationArtifact;
import io.entgra.application.mgt.common.dto.ApplicationReleaseDTO; import io.entgra.application.mgt.common.ApplicationList;
import io.entgra.application.mgt.common.Base64File;
import io.entgra.application.mgt.common.Filter;
import io.entgra.application.mgt.common.LifecycleChanger;
import io.entgra.application.mgt.common.exception.ResourceManagementException; import io.entgra.application.mgt.common.exception.ResourceManagementException;
import io.entgra.application.mgt.core.util.ApplicationManagementUtil;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import io.entgra.application.mgt.common.*;
import io.entgra.application.mgt.common.LifecycleState; import io.entgra.application.mgt.common.LifecycleState;
import io.entgra.application.mgt.common.exception.LifecycleManagementException; import io.entgra.application.mgt.common.exception.LifecycleManagementException;
import io.entgra.application.mgt.common.exception.RequestValidatingException; import io.entgra.application.mgt.common.exception.RequestValidatingException;
@ -45,20 +46,12 @@ import io.entgra.application.mgt.core.exception.BadRequestException;
import io.entgra.application.mgt.core.exception.ForbiddenException; import io.entgra.application.mgt.core.exception.ForbiddenException;
import io.entgra.application.mgt.core.exception.UnexpectedServerErrorException; import io.entgra.application.mgt.core.exception.UnexpectedServerErrorException;
import io.entgra.application.mgt.core.util.APIUtil; import io.entgra.application.mgt.core.util.APIUtil;
import io.entgra.application.mgt.core.util.Constants;
import io.entgra.application.mgt.publisher.api.services.ApplicationManagementPublisherAPI; import io.entgra.application.mgt.publisher.api.services.ApplicationManagementPublisherAPI;
import io.entgra.application.mgt.common.exception.ApplicationManagementException; import io.entgra.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.application.mgt.common.services.ApplicationManager; import io.entgra.application.mgt.common.services.ApplicationManager;
import io.entgra.application.mgt.core.exception.NotFoundException; import io.entgra.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.activation.DataHandler;
import javax.validation.Valid; import javax.validation.Valid;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
@ -173,36 +166,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
@POST @POST
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/ent-app") @Path("/ent-app")
public Response createEntApp( public Response createEntApp(
@Multipart("application") ApplicationWrapper applicationWrapper, ApplicationWrapper applicationWrapper) {
@Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1,
@Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
applicationManager.validateAppCreatingRequest(applicationWrapper, true); return createApplication(applicationWrapper);
applicationManager.validateReleaseCreatingRequest(applicationWrapper.getEntAppReleaseWrappers().get(0),
applicationWrapper.getDeviceType());
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new Ent App
ApplicationDTO applicationDTO = applicationManager.uploadEntAppReleaseArtifacts(applicationWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList));
Application application = applicationManager.persistApplication(applicationDTO);
if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build();
} else {
String msg = "Application creation is failed";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = "Found incompatible payload with ent. app creating request."; String msg = "Found incompatible payload with ent. app creating request.";
log.error(msg, e); log.error(msg, e);
@ -219,34 +188,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
@POST @POST
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/web-app") @Path("/web-app")
public Response createWebApp( public Response createWebApp(
@Multipart("webapp") WebAppWrapper webAppWrapper, WebAppWrapper webAppWrapper) {
@Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1,
@Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
applicationManager.validateAppCreatingRequest(webAppWrapper, true); return createApplication(webAppWrapper);
applicationManager
.validateReleaseCreatingRequest(webAppWrapper.getWebAppReleaseWrappers().get(0), Constants.ANY);
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new Web App
ApplicationDTO applicationDTO = applicationManager.uploadWebAppReleaseArtifacts(webAppWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, attachmentList));
Application application = applicationManager.persistApplication(applicationDTO);
if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build();
} else {
String msg = "Web app creation is failed";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = "Found incompatible payload with web app creating request."; String msg = "Found incompatible payload with web app creating request.";
log.error(msg, e); log.error(msg, e);
@ -263,34 +210,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
@POST @POST
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/public-app") @Path("/public-app")
public Response createPubApp( public Response createPubApp(
@Multipart("public-app") PublicAppWrapper publicAppWrapper, PublicAppWrapper publicAppWrapper) {
@Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1,
@Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
applicationManager.validateAppCreatingRequest(publicAppWrapper, true); return createApplication(publicAppWrapper);
applicationManager.validateReleaseCreatingRequest(publicAppWrapper.getPublicAppReleaseWrappers().get(0),
publicAppWrapper.getDeviceType());
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new Public App
ApplicationDTO applicationDTO = applicationManager.uploadPublicAppReleaseArtifacts(publicAppWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, attachmentList));
Application application = applicationManager.persistApplication(applicationDTO);
if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build();
} else {
String msg = "Web app creation is failed";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = "Found incompatible payload with pub app creating request."; String msg = "Found incompatible payload with pub app creating request.";
log.error(msg, e); log.error(msg, e);
@ -307,36 +232,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
@POST @POST
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/custom-app") @Path("/custom-app")
public Response createCustomApp( public Response createCustomApp(
@Multipart("application") CustomAppWrapper customAppWrapper, CustomAppWrapper customAppWrapper) {
@Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1,
@Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
applicationManager.validateAppCreatingRequest(customAppWrapper, true); return createApplication(customAppWrapper);
applicationManager.validateReleaseCreatingRequest(customAppWrapper.getCustomAppReleaseWrappers().get(0),
customAppWrapper.getDeviceType());
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new Custom App
ApplicationDTO applicationDTO = applicationManager.uploadCustomAppReleaseArtifactsAndConstructAppDTO(customAppWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList));
Application application = applicationManager.persistApplication(applicationDTO);
if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build();
} else {
String msg = "Custom app creation is failed";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = "Found incompatible payload with custom app creating request."; String msg = "Found incompatible payload with custom app creating request.";
log.error(msg, e); log.error(msg, e);
@ -353,28 +254,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
@POST @POST
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/{deviceType}/ent-app/{appId}") @Path("/{deviceType}/ent-app/{appId}")
public Response createEntAppRelease( public Response createEntAppRelease(
@PathParam("deviceType") String deviceTypeName, @PathParam("deviceType") String deviceTypeName,
@PathParam("appId") int appId, @PathParam("appId") int appId,
@Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper, EntAppReleaseWrapper entAppReleaseWrapper) {
@Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1,
@Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) {
try { try {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateBinaryArtifact(binaryFile); applicationManager.validateEntAppReleaseCreatingRequest(entAppReleaseWrapper, deviceTypeName);
ApplicationDTO applicationDTO = applicationManager.getApplication(appId); ApplicationRelease release = applicationManager.createEntAppRelease(appId, entAppReleaseWrapper);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
ApplicationArtifact artifact = constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList);
ApplicationReleaseDTO applicationReleaseDTO = applicationManager.uploadEntAppReleaseArtifacts(
entAppReleaseWrapper, artifact, deviceType.getName());
ApplicationRelease release = applicationManager.createRelease(applicationDTO, applicationReleaseDTO, ApplicationType.ENTERPRISE);
return Response.status(Response.Status.CREATED).entity(release).build(); return Response.status(Response.Status.CREATED).entity(release).build();
} catch (RequestValidatingException e) { } catch (RequestValidatingException e) {
String msg = "Error occurred while validating binaryArtifact"; String msg = "Error occurred while validating binaryArtifact";
@ -388,29 +277,19 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
@POST @POST
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/{deviceType}/public-app/{appId}") @Path("/{deviceType}/public-app/{appId}")
@Override @Override
public Response createPubAppRelease( public Response createPubAppRelease(
@PathParam("deviceType") String deviceTypeName, @PathParam("deviceType") String deviceTypeName,
@PathParam("appId") int appId, @PathParam("appId") int appId,
@Multipart("applicationRelease") PublicAppReleaseWrapper publicAppReleaseWrapper, PublicAppReleaseWrapper publicAppReleaseWrapper) {
@Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1,
@Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) {
try { try {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationDTO applicationDTO = applicationManager.getApplication(appId); applicationManager.validatePublicAppReleaseCreatingRequest(publicAppReleaseWrapper, deviceTypeName);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); ApplicationRelease applicationRelease = applicationManager.createPubAppRelease(appId, publicAppReleaseWrapper);
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
ApplicationArtifact artifact = constructApplicationArtifact(null, iconFile, bannerFile, attachmentList);
ApplicationReleaseDTO applicationReleaseDTO = applicationManager.uploadPubAppReleaseArtifacts(
publicAppReleaseWrapper, artifact, deviceType.getName());
ApplicationRelease release = applicationManager.createRelease(applicationDTO, applicationReleaseDTO, ApplicationType.PUBLIC);
return Response.status(Response.Status.CREATED).entity(release).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while creating application release for the application with the id " + appId; String msg = "Error occurred while creating application release for the application with the id " + appId;
log.error(msg, e); log.error(msg, e);
@ -419,29 +298,25 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
String msg = "Error occurred while uploading application release artifacts"; String msg = "Error occurred while uploading application release artifacts";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = "Invalid payload found in public app release create request";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} }
} }
@POST @POST
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/web-app/{appId}") @Path("/web-app/{appId}")
@Override @Override
public Response createWebAppRelease( public Response createWebAppRelease(
@PathParam("appId") int appId, @PathParam("appId") int appId,
@Multipart("applicationRelease") WebAppReleaseWrapper webAppReleaseWrapper, WebAppReleaseWrapper webAppReleaseWrapper) {
@Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1,
@Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) {
try { try {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationDTO applicationDTO = applicationManager.getApplication(appId); applicationManager.validateWebAppReleaseCreatingRequest(webAppReleaseWrapper);
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); ApplicationRelease applicationRelease= applicationManager.createWebAppRelease(appId, webAppReleaseWrapper);
ApplicationArtifact artifact = constructApplicationArtifact(null, iconFile, bannerFile, attachmentList); return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
ApplicationReleaseDTO applicationReleaseDTO = applicationManager.uploadWebAppReleaseArtifacts(webAppReleaseWrapper, artifact);
ApplicationRelease release = applicationManager.createRelease(applicationDTO, applicationReleaseDTO, ApplicationType.WEB_CLIP);
return Response.status(Response.Status.CREATED).entity(release).build();
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
String msg = "Error occurred while uploading application release artifacts"; String msg = "Error occurred while uploading application release artifacts";
log.error(msg, e); log.error(msg, e);
@ -450,33 +325,25 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
String msg = "Error occurred while creating application release for the application with the id " + appId; String msg = "Error occurred while creating application release for the application with the id " + appId;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = "Invalid payload found in web app release create request";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} }
} }
@POST @POST
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/{deviceType}/custom-app/{appId}") @Path("/{deviceType}/custom-app/{appId}")
@Override @Override
public Response createCustomAppRelease( public Response createCustomAppRelease(
@PathParam("deviceType") String deviceTypeName, @PathParam("deviceType") String deviceTypeName,
@PathParam("appId") int appId, @PathParam("appId") int appId,
@Multipart("applicationRelease") CustomAppReleaseWrapper customAppReleaseWrapper, CustomAppReleaseWrapper customAppReleaseWrapper) {
@Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1,
@Multipart("screenshot2") Attachment screenshot2,
@Multipart("screenshot3") Attachment screenshot3) {
try { try {
APIUtil.getApplicationManager().validateBinaryArtifact(binaryFile);
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationDTO applicationDTO = applicationManager.getApplication(appId); applicationManager.validateCustomAppReleaseCreatingRequest(customAppReleaseWrapper, deviceTypeName);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); ApplicationRelease release = applicationManager.createCustomAppRelease(appId, customAppReleaseWrapper);
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
ApplicationArtifact artifact = constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList);
ApplicationReleaseDTO applicationReleaseDTO = applicationManager.uploadCustomAppReleaseArtifacts(
customAppReleaseWrapper, artifact, deviceType.getName());
ApplicationRelease release = applicationManager.createRelease(applicationDTO, applicationReleaseDTO, ApplicationType.CUSTOM);
return Response.status(Response.Status.CREATED).entity(release).build(); return Response.status(Response.Status.CREATED).entity(release).build();
} catch (RequestValidatingException e) { } catch (RequestValidatingException e) {
String msg = "Error occurred while validating binaryArtifact"; String msg = "Error occurred while validating binaryArtifact";
@ -521,21 +388,20 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override @Override
@PUT @PUT
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/image-artifacts/{uuid}") @Path("/image-artifacts/{uuid}")
public Response updateApplicationImageArtifacts( public Response updateApplicationImageArtifacts(
@PathParam("uuid") String applicationReleaseUuid, @PathParam("uuid") String applicationReleaseUuid,
@Multipart(value = "icon", required = false) Attachment iconFile, Base64File iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile, Base64File bannerFile,
@Multipart(value = "screenshot1", required = false) Attachment screenshot1, List<Base64File> screenshots) {
@Multipart(value = "screenshot2", required = false) Attachment screenshot2,
@Multipart(value = "screenshot3", required = false) Attachment screenshot3) {
try { try {
List<Attachment> attachments = constructAttachmentList(screenshot1, screenshot2, screenshot3); ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(iconFile, screenshots,
null, bannerFile);
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.updateApplicationImageArtifact(applicationReleaseUuid, applicationManager.updateApplicationImageArtifact(applicationReleaseUuid,
constructApplicationArtifact(null, iconFile, bannerFile, attachments)); artifact);
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationReleaseUuid).build(); .entity("Successfully uploaded artifacts for the application " + applicationReleaseUuid).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
@ -554,18 +420,19 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override @Override
@PUT @PUT
@Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Consumes(MediaType.APPLICATION_JSON)
@Path("/ent-app-artifact/{deviceType}/{uuid}") @Path("/ent-app-artifact/{deviceType}/{uuid}")
public Response updateApplicationArtifact( public Response updateApplicationArtifact(
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@PathParam("uuid") String applicationReleaseUuid, @PathParam("uuid") String applicationReleaseUuid,
@Multipart("binaryFile") Attachment binaryFile) { Base64File binaryFile) {
try { try {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateBinaryArtifact(binaryFile); applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.updateApplicationArtifact(deviceType, applicationReleaseUuid, applicationManager.updateApplicationArtifact(deviceType, applicationReleaseUuid,
constructApplicationArtifact(binaryFile, null, null, null)); ApplicationManagementUtil.constructApplicationArtifact(null, null,
binaryFile, null));
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application release. UUID is " .entity("Successfully uploaded artifacts for the application release. UUID is "
+ applicationReleaseUuid).build(); + applicationReleaseUuid).build();
@ -622,19 +489,13 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Path("/ent-app-release/{uuid}") @Path("/ent-app-release/{uuid}")
public Response updateEntAppRelease( public Response updateEntAppRelease(
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper, EntAppReleaseWrapper entAppReleaseWrapper) {
@Multipart(value = "binaryFile", required = false) Attachment binaryFile,
@Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart(value = "screenshot1", required = false) Attachment screenshot1,
@Multipart(value = "screenshot2", required = false) Attachment screenshot2,
@Multipart(value = "screenshot3", required = false) Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(entAppReleaseWrapper.getIcon(),
entAppReleaseWrapper.getScreenshots(), entAppReleaseWrapper.getBinaryFile(), entAppReleaseWrapper.getBanner());
ApplicationRelease applicationRelease = applicationManager ApplicationRelease applicationRelease = applicationManager
.updateEntAppRelease(applicationUUID, entAppReleaseWrapper, .updateEntAppRelease(applicationUUID, entAppReleaseWrapper, artifact);
constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots));
if (applicationRelease == null) { if (applicationRelease == null) {
String msg ="Ent app release updating is failed. Please contact the administrator. Application release " String msg ="Ent app release updating is failed. Please contact the administrator. Application release "
+ "UUID: " + applicationUUID; + "UUID: " + applicationUUID;
@ -669,18 +530,13 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Path("/public-app-release/{uuid}") @Path("/public-app-release/{uuid}")
public Response updatePubAppRelease( public Response updatePubAppRelease(
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") PublicAppReleaseWrapper publicAppReleaseWrapper, PublicAppReleaseWrapper publicAppReleaseWrapper) {
@Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart(value = "screenshot1", required = false) Attachment screenshot1,
@Multipart(value = "screenshot2", required = false) Attachment screenshot2,
@Multipart(value = "screenshot3", required = false) Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(publicAppReleaseWrapper.getIcon(),
publicAppReleaseWrapper.getScreenshots(), null, publicAppReleaseWrapper.getBanner());
ApplicationRelease applicationRelease = applicationManager ApplicationRelease applicationRelease = applicationManager
.updatePubAppRelease(applicationUUID, publicAppReleaseWrapper, .updatePubAppRelease(applicationUUID, publicAppReleaseWrapper, artifact);
constructApplicationArtifact(null, iconFile, bannerFile, screenshots));
if (applicationRelease == null) { if (applicationRelease == null) {
String msg ="Public app release updating is failed. Please contact the administrator. " String msg ="Public app release updating is failed. Please contact the administrator. "
+ "Application release UUID: " + applicationUUID + ", Supported device type:"; + "Application release UUID: " + applicationUUID + ", Supported device type:";
@ -714,18 +570,13 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Path("/web-app-release/{uuid}") @Path("/web-app-release/{uuid}")
public Response updateWebAppRelease( public Response updateWebAppRelease(
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") WebAppReleaseWrapper webAppReleaseWrapper, WebAppReleaseWrapper webAppReleaseWrapper) {
@Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart(value = "screenshot1", required = false) Attachment screenshot1,
@Multipart(value = "screenshot2", required = false) Attachment screenshot2,
@Multipart(value = "screenshot3", required = false) Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(webAppReleaseWrapper.getIcon(),
webAppReleaseWrapper.getScreenshots(), null, webAppReleaseWrapper.getBanner());
ApplicationRelease applicationRelease = applicationManager ApplicationRelease applicationRelease = applicationManager
.updateWebAppRelease(applicationUUID, webAppReleaseWrapper, .updateWebAppRelease(applicationUUID, webAppReleaseWrapper, artifact);
constructApplicationArtifact(null, iconFile, bannerFile, screenshots));
if (applicationRelease == null) { if (applicationRelease == null) {
String msg ="web app release updating is failed. Please contact the administrator. Application " String msg ="web app release updating is failed. Please contact the administrator. Application "
+ "release UUID: " + applicationUUID; + "release UUID: " + applicationUUID;
@ -758,19 +609,13 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Path("/custom-app-release/{uuid}") @Path("/custom-app-release/{uuid}")
public Response updateCustomAppRelease( public Response updateCustomAppRelease(
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") CustomAppReleaseWrapper customAppReleaseWrapper, CustomAppReleaseWrapper customAppReleaseWrapper) {
@Multipart(value = "binaryFile", required = false) Attachment binaryFile,
@Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart(value = "screenshot1", required = false) Attachment screenshot1,
@Multipart(value = "screenshot2", required = false) Attachment screenshot2,
@Multipart(value = "screenshot3", required = false) Attachment screenshot3) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(customAppReleaseWrapper.getIcon(),
customAppReleaseWrapper.getScreenshots(), customAppReleaseWrapper.getBinaryFile(), customAppReleaseWrapper.getBanner());
ApplicationRelease applicationRelease = applicationManager ApplicationRelease applicationRelease = applicationManager
.updateCustomAppRelease(applicationUUID, customAppReleaseWrapper, .updateCustomAppRelease(applicationUUID, customAppReleaseWrapper, artifact);
constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots));
if (applicationRelease == null) { if (applicationRelease == null) {
String msg ="Custom app release updating is failed. Please contact the administrator. Application " String msg ="Custom app release updating is failed. Please contact the administrator. Application "
+ "release UUID: " + applicationUUID; + "release UUID: " + applicationUUID;
@ -1019,134 +864,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
} }
/*** public <T> Response createApplication(T appWrapper) throws ApplicationManagementException, RequestValidatingException {
* Construct the screenshot list by evaluating the availability of each screenshot. ApplicationManager applicationManager = APIUtil.getApplicationManager();
* applicationManager.validateAppCreatingRequest(appWrapper);
* @param screenshot1 First Screenshot Application application = applicationManager.createApplication(appWrapper);
* @param screenshot2 Second Screenshot if (application != null) {
* @param screenshot3 Third Screenshot return Response.status(Response.Status.CREATED).entity(application).build();
* @return List of {@link Attachment} } else {
*/ String msg = "Application creation is failed";
private List<Attachment> constructAttachmentList(Attachment screenshot1, Attachment screenshot2,
Attachment screenshot3) {
List<Attachment> attachments = new ArrayList<>();
if (screenshot1 != null) {
attachments.add(screenshot1);
}
if (screenshot2 != null) {
attachments.add(screenshot2);
}
if (screenshot3 != null) {
attachments.add(screenshot3);
}
return attachments;
}
/***
* This method can be used to construct {@link ApplicationArtifact}
*
* @param binaryFile binary file of the application release
* @param iconFile icon file of the application release
* @param bannerFile banner file of the application release
* @param attachmentList list of screenshot of the application release
* @return {@link ApplicationArtifact}
* @throws ApplicationManagementException if an error occurs when reading the attached data.
*/
private ApplicationArtifact constructApplicationArtifact(Attachment binaryFile, Attachment iconFile,
Attachment bannerFile, List<Attachment> attachmentList) throws ApplicationManagementException {
try {
ApplicationArtifact applicationArtifact = new ApplicationArtifact();
DataHandler dataHandler;
if (binaryFile != null) {
dataHandler = binaryFile.getDataHandler();
InputStream installerStream = dataHandler.getInputStream();
String installerFileName = dataHandler.getName();
if (installerStream == null) {
String msg = "Stream of the application release installer is null. Hence can't proceed. Please "
+ "verify the installer file.";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
if (installerFileName == null) {
String msg = "Installer file name retrieving is failed.. Hence can't proceed. Please verify the "
+ "installer file.";
log.error(msg);
throw new BadRequestException(msg);
}
applicationArtifact.setInstallerName(installerFileName.replaceAll("\\s", ""));
applicationArtifact.setInstallerStream(installerStream);
}
if (iconFile != null) {
dataHandler = iconFile.getDataHandler();
String iconFileName = dataHandler.getName();
InputStream iconStream = dataHandler.getInputStream();
if (iconStream == null) {
String msg = "Stream of the application release icon is null. Hence can't proceed. Please "
+ "verify the uploaded icon file.";
log.error(msg);
throw new BadRequestException(msg);
}
if (iconFileName == null) {
String msg = "Icon file name retrieving is failed.. Hence can't proceed. Please verify the "
+ "icon file.";
log.error(msg);
throw new BadRequestException(msg);
}
applicationArtifact.setIconName(iconFileName);
applicationArtifact.setIconStream(iconStream);
}
if (bannerFile != null) {
dataHandler = bannerFile.getDataHandler();
String bannerFileName = dataHandler.getName();
InputStream bannerStream = dataHandler.getInputStream();
if (bannerStream == null) {
String msg = "Stream of the application release banner is null. Hence can't proceed. Please "
+ "verify the uploaded banner file.";
log.error(msg);
throw new BadRequestException(msg);
}
if (bannerFileName == null) {
String msg = "Banner file name retrieving is failed.. Hence can't proceed. Please verify the "
+ "banner file.";
log.error(msg);
throw new BadRequestException(msg);
}
applicationArtifact.setBannerName(bannerFileName);
applicationArtifact.setBannerStream(bannerStream);
}
if (attachmentList != null && !attachmentList.isEmpty()) {
Map<String, InputStream> screenshotData = new TreeMap<>();
for (Attachment sc : attachmentList) {
dataHandler = sc.getDataHandler();
String screenshotFileName = dataHandler.getName();
InputStream screenshotStream = dataHandler.getInputStream();
if (screenshotStream == null) {
String msg =
"Stream of one of the application release screenshot is null. Hence can't proceed. Please "
+ "verify the uploaded screenshots.";
log.error(msg);
throw new BadRequestException(msg);
}
if (screenshotFileName == null) {
String msg =
"Screenshot file name retrieving is failed for one screenshot. Hence can't proceed. "
+ "Please verify the screenshots.";
log.error(msg);
throw new BadRequestException(msg);
}
screenshotData.put(screenshotFileName, screenshotStream);
}
applicationArtifact.setScreenshots(screenshotData);
}
return applicationArtifact;
} catch (IOException e) {
String msg = "Error occurred when reading attachment data.";
log.error(msg, e);
throw new ApplicationManagementException(msg);
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
@ -35,7 +35,6 @@ import io.entgra.application.mgt.publisher.api.services.SPApplicationService;
import io.entgra.application.mgt.publisher.api.services.util.SPAppRequestHandlerUtil; import io.entgra.application.mgt.publisher.api.services.util.SPAppRequestHandlerUtil;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
@ -46,7 +45,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/identity-server-applications") @Path("/identity-server-applications")
public class SPApplicationServiceImpl implements SPApplicationService { public class SPApplicationServiceImpl implements SPApplicationService {
@ -90,7 +88,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
try { try {
SPApplicationManager spAppManager = APIUtil.getSPApplicationManager(); SPApplicationManager spAppManager = APIUtil.getSPApplicationManager();
SPApplicationListResponse applications = SPAppRequestHandlerUtil. SPApplicationListResponse applications = SPAppRequestHandlerUtil.
getServiceProvidersFromIdentityServer(identityServerId, limit, offset); retrieveSPApplications(identityServerId, limit, offset);
spAppManager.addExistingApps(identityServerId, applications.getApplications()); spAppManager.addExistingApps(identityServerId, applications.getApplications());
return Response.status(Response.Status.OK).entity(applications).build(); return Response.status(Response.Status.OK).entity(applications).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
@ -100,7 +98,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
} }
} }
@Path("/{identity-server-id}/{service-provider-id}/attach") @Path("/{identity-server-id}/service-provider/{service-provider-id}/applications")
@POST @POST
@Override @Override
public Response attachApps(@PathParam("identity-server-id") int identityServerId, public Response attachApps(@PathParam("identity-server-id") int identityServerId,
@ -118,7 +116,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} }
@Path("/{identity-server-id}/{service-provider-id}/detach") @Path("/{identity-server-id}/service-provider/{service-provider-id}/delete/applications")
@POST @POST
@Override @Override
public Response detachApps(@PathParam("identity-server-id") int identityServerId, public Response detachApps(@PathParam("identity-server-id") int identityServerId,
@ -136,7 +134,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} }
@Path("/{identity-server-id}/{service-provider-id}/create/ent-app") @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/ent-app")
@POST @POST
@Override @Override
public Response createEntApp(@PathParam("identity-server-id") int identityServerId, public Response createEntApp(@PathParam("identity-server-id") int identityServerId,
@ -144,7 +142,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
return createSPApplication(identityServerId, serviceProviderId, app); return createSPApplication(identityServerId, serviceProviderId, app);
} }
@Path("/{identity-server-id}/{service-provider-id}/create/public-app") @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/public-app")
@POST @POST
@Override @Override
public Response createPubApp(@PathParam("identity-server-id") int identityServerId, public Response createPubApp(@PathParam("identity-server-id") int identityServerId,
@ -152,7 +150,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
return createSPApplication(identityServerId, serviceProviderId, app); return createSPApplication(identityServerId, serviceProviderId, app);
} }
@Path("/{identity-server-id}/{service-provider-id}/create/web-app") @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/web-app")
@POST @POST
@Override @Override
public Response createWebApp(@PathParam("identity-server-id") int identityServerId, public Response createWebApp(@PathParam("identity-server-id") int identityServerId,
@ -160,7 +158,7 @@ public class SPApplicationServiceImpl implements SPApplicationService {
return createSPApplication(identityServerId, serviceProviderId, app); return createSPApplication(identityServerId, serviceProviderId, app);
} }
@Path("/{identity-server-id}/{service-provider-id}/create/custom-app") @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/custom-app")
@POST @POST
@Override @Override
public Response createCustomApp(@PathParam("identity-server-id") int identityServerId, public Response createCustomApp(@PathParam("identity-server-id") int identityServerId,
@ -168,11 +166,20 @@ public class SPApplicationServiceImpl implements SPApplicationService {
return createSPApplication(identityServerId, serviceProviderId, app); return createSPApplication(identityServerId, serviceProviderId, app);
} }
private <T> Response createSPApplication(int identityServerId, String serviceProviderId, T appWrapper) { /**
* Validates and creates service provider application
*
* @param identityServerId id of the identity server
* @param spUID uid of the service provider
* @param appWrapper application wrapper
* @param <T> application wrapper class
* @return Response
*/
private <T> Response createSPApplication(int identityServerId, String spUID, T appWrapper) {
try { try {
validateServiceProviderUID(identityServerId, serviceProviderId); validateServiceProviderUID(identityServerId, spUID);
SPApplicationManager spApplicationManager = APIUtil.getSPApplicationManager(); SPApplicationManager spApplicationManager = APIUtil.getSPApplicationManager();
Application createdApp = spApplicationManager.createSPApplication(appWrapper, identityServerId, serviceProviderId); Application createdApp = spApplicationManager.createSPApplication(appWrapper, identityServerId, spUID);
return Response.status(Response.Status.CREATED).entity(createdApp).build(); return Response.status(Response.Status.CREATED).entity(createdApp).build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = "Found incompatible payload with create service provider app request."; String msg = "Found incompatible payload with create service provider app request.";
@ -190,6 +197,13 @@ public class SPApplicationServiceImpl implements SPApplicationService {
} }
} }
/**
* Responsible for validating service provider in requests
*
* @param identityServerId identity server id of the service provider
* @param spUID uid of the service provider
* @throws ApplicationManagementException
*/
private void validateServiceProviderUID(int identityServerId, String spUID) throws private void validateServiceProviderUID(int identityServerId, String spUID) throws
ApplicationManagementException { ApplicationManagementException {
try { try {
@ -207,5 +221,4 @@ public class SPApplicationServiceImpl implements SPApplicationService {
} }
} }
} }

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.application.mgt.publisher.api.services.util; package io.entgra.application.mgt.publisher.api.services.util;
import com.google.gson.Gson; import com.google.gson.Gson;
@ -27,19 +45,26 @@ public class SPAppRequestHandlerUtil {
private static final Log log = LogFactory.getLog(SPAppRequestHandlerUtil.class); private static final Log log = LogFactory.getLog(SPAppRequestHandlerUtil.class);
/**
* Check if service provider application exists
*
* @param identityServerId id of the identity server
* @param spAppId uid of the service provider
* @return if service provider exist
* @throws ApplicationManagementException
*/
public static boolean isSPApplicationExist(int identityServerId, String spAppId) throws ApplicationManagementException { public static boolean isSPApplicationExist(int identityServerId, String spAppId) throws ApplicationManagementException {
SPApplication application = retrieveSPApplication(identityServerId, spAppId); SPApplication application = retrieveSPApplication(identityServerId, spAppId);
if (application == null) { return application != null;
return false;
}
return true;
}
public static SPApplicationListResponse getServiceProvidersFromIdentityServer(int identityServerId, Integer limit, Integer offSet)
throws ApplicationManagementException {
return retrieveSPApplications(identityServerId, limit, offSet);
} }
/**
* Get service provider by identity server id and service provider uid
* @param identityServerId id of the identity server
* @param spAppId uid of service provider to be retrieved
* @return {@link SPApplication}
* @throws ApplicationManagementException
*/
public static SPApplication retrieveSPApplication(int identityServerId, String spAppId) public static SPApplication retrieveSPApplication(int identityServerId, String spAppId)
throws ApplicationManagementException { throws ApplicationManagementException {
IdentityServer identityServer = getIdentityServer(identityServerId); IdentityServer identityServer = getIdentityServer(identityServerId);
@ -74,7 +99,13 @@ public class SPAppRequestHandlerUtil {
} }
} }
/**
* Retrieve service provider apps from identity server
*
* @param identityServerId id of the identity server
* @return {@link SPApplicationListResponse}
* @throws ApplicationManagementException
*/
public static SPApplicationListResponse retrieveSPApplications(int identityServerId, Integer limit, Integer offset) public static SPApplicationListResponse retrieveSPApplications(int identityServerId, Integer limit, Integer offset)
throws ApplicationManagementException { throws ApplicationManagementException {
IdentityServer identityServer = getIdentityServer(identityServerId); IdentityServer identityServer = getIdentityServer(identityServerId);
@ -113,17 +144,23 @@ public class SPAppRequestHandlerUtil {
} }
} }
/**
*
* @param identityServerId id of the identity server
* @return {@link IdentityServer}
* @throws ApplicationManagementException
*/
public static IdentityServer getIdentityServer(int identityServerId) throws ApplicationManagementException { public static IdentityServer getIdentityServer(int identityServerId) throws ApplicationManagementException {
SPApplicationManager spApplicationManager = APIUtil.getSPApplicationManager(); SPApplicationManager spApplicationManager = APIUtil.getSPApplicationManager();
return spApplicationManager.getIdentityServer(identityServerId); return spApplicationManager.getIdentityServer(identityServerId);
} }
public static HttpResponse invokeISAPI(IdentityServer identityServer, HttpClient client, HttpRequestBase request) throws IOException { private static HttpResponse invokeISAPI(IdentityServer identityServer, HttpClient client, HttpRequestBase request) throws IOException {
setBasicAuthHeader(identityServer, request); setBasicAuthHeader(identityServer, request);
return client.execute(request); return client.execute(request);
} }
public static void setBasicAuthHeader(IdentityServer identityServer, HttpRequestBase request) { private static void setBasicAuthHeader(IdentityServer identityServer, HttpRequestBase request) {
String basicAuthHeader = HttpUtil.getBasicAuthBase64Header(identityServer.getUserName(), String basicAuthHeader = HttpUtil.getBasicAuthBase64Header(identityServer.getUserName(),
identityServer.getPassword()); identityServer.getPassword());
request.setHeader(HttpHeaders.AUTHORIZATION, basicAuthHeader); request.setHeader(HttpHeaders.AUTHORIZATION, basicAuthHeader);

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.core.common; package org.wso2.carbon.device.mgt.core.common;
public class Constants { public class Constants {

View File

@ -1,3 +1,21 @@
/*
* Copyright (c) 2022, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.core.common.util; package org.wso2.carbon.device.mgt.core.common.util;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -20,5 +38,47 @@ public class FileUtil {
return new ByteArrayInputStream(base64Bytes); return new ByteArrayInputStream(base64Bytes);
} }
/**
* This generates file name with a suffix depending on the duplicate name count, useful when saving
* files with the same name
*
* @param fileNameCount File count
* @return generated file name with suffix
*/
public static String generateDuplicateFileName(String fileName, int fileNameCount) {
String suffix = generateDuplicateFileNameSuffix(fileNameCount);
String fileNameWithoutExtension = extractFileNameWithoutExtension(fileName);
String fileNameWithSuffix = fileNameWithoutExtension + suffix;
fileNameWithSuffix = fileNameWithSuffix + '.' + extractFileExtension(fileName);
return fileNameWithSuffix;
}
/**
* This generates file name suffix for duplicate file names. For example,
* if it's the first file, the count is 1 in which case the name doesn't have any suffix
* else it adds suffix with (count - 1)
*
* @param fileNameCount File count
* @return generated file name suffix
*/
private static String generateDuplicateFileNameSuffix(int fileNameCount) {
String suffix = "";
if (fileNameCount < 1) {
throw new IllegalArgumentException("file name count must be above 0");
}
if (fileNameCount > 1) {
suffix = "(" + (fileNameCount - 1) + ")";
}
return suffix;
}
private static String extractFileExtension(String fileName) {
return fileName.substring(fileName.lastIndexOf('.') + 1);
}
private static String extractFileNameWithoutExtension(String fileName) {
return fileName.substring(0, fileName.lastIndexOf('.'));
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * Copyright (c) 2022, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* Entgra (pvt) Ltd. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except