Add query param to publish an app directly

temp
Gimhan-minion 3 years ago
parent 87808ec9df
commit 8bdffc90c6

@ -51,19 +51,20 @@ public interface ApplicationManager {
* *
* @param applicationWrapper Application that need to be created. * @param applicationWrapper Application that need to be created.
* @param applicationArtifact contains artifact data. i.e image name and stream, icon name and stream etc. * @param applicationArtifact contains artifact data. i.e image name and stream, icon name and stream etc.
* @param isPublished checks if application should be published
* @return {@link Application} * @return {@link Application}
* @throws ApplicationManagementException Catch all other throwing exceptions and throw {@link ApplicationManagementException} * @throws ApplicationManagementException Catch all other throwing exceptions and throw {@link ApplicationManagementException}
*/ */
Application createEntApp(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact) Application createEntApp(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact, boolean isPublished)
throws ApplicationManagementException; throws ApplicationManagementException;
Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact, boolean isPublished)
throws ApplicationManagementException; throws ApplicationManagementException;
Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact) Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact, boolean isPublished)
throws ApplicationManagementException; throws ApplicationManagementException;
Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact) Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact, boolean isPublished)
throws ApplicationManagementException; throws ApplicationManagementException;
/** /**

@ -135,7 +135,7 @@ ApplicationManagerImpl implements ApplicationManager {
@Override @Override
public Application createEntApp(ApplicationWrapper applicationWrapper, public Application createEntApp(ApplicationWrapper applicationWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException { ApplicationArtifact applicationArtifact, boolean isPublished) throws ApplicationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Ent. Application create request is received. Application name: " + applicationWrapper.getName() log.debug("Ent. Application create request is received. Application name: " + applicationWrapper.getName()
+ " Device type: " + applicationWrapper.getDeviceType()); + " Device type: " + applicationWrapper.getDeviceType());
@ -149,11 +149,11 @@ ApplicationManagerImpl implements ApplicationManager {
applicationWrapper.getDeviceType(), tenantId, false); applicationWrapper.getDeviceType(), tenantId, false);
applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
return addAppDataIntoDB(applicationDTO, tenantId); return addAppDataIntoDB(applicationDTO, tenantId, isPublished);
} }
@Override @Override
public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact, boolean isPublished)
throws ApplicationManagementException { throws ApplicationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Web clip create request is received. App name: " + webAppWrapper.getName() + " Device type: " log.debug("Web clip create request is received. App name: " + webAppWrapper.getName() + " Device type: "
@ -175,11 +175,11 @@ ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
//insert application data into database //insert application data into database
return addAppDataIntoDB(applicationDTO, tenantId); return addAppDataIntoDB(applicationDTO, tenantId, isPublished);
} }
@Override @Override
public Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact) public Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact, boolean isPublished)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -231,11 +231,11 @@ ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
//insert application data into database //insert application data into database
return addAppDataIntoDB(applicationDTO, tenantId); return addAppDataIntoDB(applicationDTO, tenantId, isPublished);
} }
@Override @Override
public Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact) public Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact, boolean isPublished)
throws ApplicationManagementException { throws ApplicationManagementException {
try { try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -282,7 +282,7 @@ ApplicationManagerImpl implements ApplicationManager {
applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact, tenantId); applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact, tenantId);
applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
return addAppDataIntoDB(applicationDTO, tenantId); return addAppDataIntoDB(applicationDTO, tenantId, isPublished);
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
String msg = "Error occurred while uploading application artifact into the server. Application name: " String msg = "Error occurred while uploading application artifact into the server. Application name: "
+ customAppWrapper.getName() + " Device type: " + customAppWrapper.getDeviceType(); + customAppWrapper.getName() + " Device type: " + customAppWrapper.getDeviceType();
@ -872,7 +872,7 @@ ApplicationManagerImpl implements 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.
*/ */
private Application addAppDataIntoDB(ApplicationDTO applicationDTO, int tenantId) throws ApplicationManagementException { private Application addAppDataIntoDB(ApplicationDTO applicationDTO, int tenantId, boolean isPublished) throws ApplicationManagementException {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
List<String> unrestrictedRoles = applicationDTO.getUnrestrictedRoles(); List<String> unrestrictedRoles = applicationDTO.getUnrestrictedRoles();
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
@ -939,11 +939,18 @@ ApplicationManagerImpl implements ApplicationManager {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Creating a new release. App Id:" + appId); log.debug("Creating a new release. App Id:" + appId);
} }
String initialLifecycleState = lifecycleStateManager.getInitialState();
applicationReleaseDTO.setCurrentState(initialLifecycleState); String lifeCycleState;
if(isPublished){
lifeCycleState = lifecycleStateManager.getInstallableState();
} else {
lifeCycleState = lifecycleStateManager.getInitialState();
}
applicationReleaseDTO.setCurrentState(lifeCycleState);
applicationReleaseDTO = this.applicationReleaseDAO applicationReleaseDTO = this.applicationReleaseDAO
.createRelease(applicationReleaseDTO, appId, tenantId); .createRelease(applicationReleaseDTO, appId, tenantId);
LifecycleState lifecycleState = getLifecycleStateInstance(initialLifecycleState, initialLifecycleState); LifecycleState lifecycleState = getLifecycleStateInstance(lifeCycleState, lifeCycleState);
this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
applicationReleaseEntities.add(applicationReleaseDTO); applicationReleaseEntities.add(applicationReleaseDTO);
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);

@ -41,7 +41,6 @@ import io.entgra.application.mgt.core.dto.ApplicationsDTO;
import io.entgra.application.mgt.core.impl.ApplicationManagerImpl; import io.entgra.application.mgt.core.impl.ApplicationManagerImpl;
import io.entgra.application.mgt.core.internal.DataHolder; import io.entgra.application.mgt.core.internal.DataHolder;
import io.entgra.application.mgt.core.util.ConnectionManagerUtil; import io.entgra.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion; import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion;
@ -121,9 +120,8 @@ public class ApplicationManagementTest extends BaseTestCase {
screenshots.put("shot3", new FileInputStream(new File("src/test/resources/samples/app1/shot3.png"))); screenshots.put("shot3", new FileInputStream(new File("src/test/resources/samples/app1/shot3.png")));
applicationArtifact.setScreenshots(screenshots); applicationArtifact.setScreenshots(screenshots);
ApplicationManager manager = new ApplicationManagerImpl(); ApplicationManager manager = new ApplicationManagerImpl();
manager.createEntApp(applicationWrapper, applicationArtifact); manager.createEntApp(applicationWrapper, applicationArtifact, false);
} }
@DataProvider(name = "applicationIdDataProvider") @DataProvider(name = "applicationIdDataProvider")
@ -141,6 +139,11 @@ public class ApplicationManagementTest extends BaseTestCase {
return new Object[][] {{"TEST_APP_UUID"}}; return new Object[][] {{"TEST_APP_UUID"}};
} }
@Test(enabled = false)
public void createApplicationAndPublish(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact, boolean isPublish) throws ApplicationManagementException {
}
@Test(enabled = false) @Test(enabled = false)
public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException { public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException {

@ -319,6 +319,11 @@ public interface ApplicationManagementPublisherAPI {
value = "The application that need to be created.", value = "The application that need to be created.",
required = true) required = true)
@Multipart("application") ApplicationWrapper application, @Multipart("application") ApplicationWrapper application,
@ApiParam(
name = "isPublished",
value = "Published state of the application"
)
@QueryParam("is-Published") boolean isPublished,
@ApiParam( @ApiParam(
name = "binaryFile", name = "binaryFile",
value = "Binary file of uploading application", value = "Binary file of uploading application",
@ -388,6 +393,11 @@ public interface ApplicationManagementPublisherAPI {
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, @Multipart("webapp") WebAppWrapper webAppWrapper,
@ApiParam(
name = "isPublished",
value = "Published state of the application"
)
@QueryParam("is-Published") boolean isPublished,
@ApiParam( @ApiParam(
name = "icon", name = "icon",
value = "Icon of the uploading web app", value = "Icon of the uploading web app",
@ -452,6 +462,11 @@ public interface ApplicationManagementPublisherAPI {
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, @Multipart("public-app") PublicAppWrapper publicAppWrapper,
@ApiParam(
name = "isPublished",
value = "Published state of the application"
)
@QueryParam("is-Published") boolean isPublished,
@ApiParam( @ApiParam(
name = "icon", name = "icon",
value = "Icon of the uploading public app", value = "Icon of the uploading public app",
@ -514,6 +529,11 @@ public interface ApplicationManagementPublisherAPI {
value = "The application that need to be created.", value = "The application that need to be created.",
required = true) required = true)
@Multipart("application") CustomAppWrapper customAppWrapper, @Multipart("application") CustomAppWrapper customAppWrapper,
@ApiParam(
name = "isPublished",
value = "Published state of the application"
)
@QueryParam("is-Published") boolean isPublished,
@ApiParam( @ApiParam(
name = "binaryFile", name = "binaryFile",
value = "Binary file of uploading application", value = "Binary file of uploading application",

@ -173,6 +173,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Path("/ent-app") @Path("/ent-app")
public Response createEntApp( public Response createEntApp(
@Multipart("application") ApplicationWrapper applicationWrapper, @Multipart("application") ApplicationWrapper applicationWrapper,
@QueryParam("is-published") boolean isPublished,
@Multipart("binaryFile") Attachment binaryFile, @Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile, @Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile, @Multipart(value = "banner", required = false) Attachment bannerFile,
@ -190,7 +191,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
// Created new Ent App // Created new Ent App
Application application = applicationManager.createEntApp(applicationWrapper, Application application = applicationManager.createEntApp(applicationWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList)); constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList), isPublished);
if (application != null) { if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build(); return Response.status(Response.Status.CREATED).entity(application).build();
} else { } else {
@ -218,6 +219,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Path("/web-app") @Path("/web-app")
public Response createWebApp( public Response createWebApp(
@Multipart("webapp") WebAppWrapper webAppWrapper, @Multipart("webapp") WebAppWrapper webAppWrapper,
@QueryParam("is-published") boolean isPublished,
@Multipart("icon") Attachment iconFile, @Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile, @Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1, @Multipart("screenshot1") Attachment screenshot1,
@ -233,7 +235,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
// Created new Web App // Created new Web App
Application application = applicationManager.createWebClip(webAppWrapper, Application application = applicationManager.createWebClip(webAppWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, attachmentList)); constructApplicationArtifact(null, iconFile, bannerFile, attachmentList), isPublished);
if (application != null) { if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build(); return Response.status(Response.Status.CREATED).entity(application).build();
} else { } else {
@ -261,6 +263,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Path("/public-app") @Path("/public-app")
public Response createPubApp( public Response createPubApp(
@Multipart("public-app") PublicAppWrapper publicAppWrapper, @Multipart("public-app") PublicAppWrapper publicAppWrapper,
@QueryParam("is-published") boolean isPublished,
@Multipart("icon") Attachment iconFile, @Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile, @Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart("screenshot1") Attachment screenshot1, @Multipart("screenshot1") Attachment screenshot1,
@ -276,11 +279,11 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
// Created new Public App // Created new Public App
Application application = applicationManager.createPublicApp(publicAppWrapper, Application application = applicationManager.createPublicApp(publicAppWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, attachmentList)); constructApplicationArtifact(null, iconFile, bannerFile, attachmentList), isPublished);
if (application != null) { if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build(); return Response.status(Response.Status.CREATED).entity(application).build();
} else { } else {
String msg = "Web app creation is failed"; String msg = "Public app creation is failed";
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -304,6 +307,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Path("/custom-app") @Path("/custom-app")
public Response createCustomApp( public Response createCustomApp(
@Multipart("application") CustomAppWrapper customAppWrapper, @Multipart("application") CustomAppWrapper customAppWrapper,
@QueryParam("is-published") boolean isPublished,
@Multipart("binaryFile") Attachment binaryFile, @Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile, @Multipart("icon") Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile, @Multipart(value = "banner", required = false) Attachment bannerFile,
@ -321,7 +325,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
// Created new Custom App // Created new Custom App
Application application = applicationManager.createCustomApp(customAppWrapper, Application application = applicationManager.createCustomApp(customAppWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList)); constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList), isPublished);
if (application != null) { if (application != null) {
return Response.status(Response.Status.CREATED).entity(application).build(); return Response.status(Response.Status.CREATED).entity(application).build();
} else { } else {

Loading…
Cancel
Save