mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'application-mgt-new' into 'application-mgt-new'
Add public app and web clip support for APPM See merge request entgra/carbon-device-mgt!122
This commit is contained in:
commit
4829d69733
@ -23,6 +23,6 @@ package org.wso2.carbon.device.application.mgt.common;
|
||||
* Application Types.
|
||||
*/
|
||||
public enum ApplicationType {
|
||||
ENTERPRISE, PUBLIC, WEB, WEB_CLIP
|
||||
ENTERPRISE, PUBLIC, WEB_APP, WEB_CLIP
|
||||
}
|
||||
|
||||
|
||||
@ -81,10 +81,6 @@ public class ApplicationRelease {
|
||||
required = true)
|
||||
private String metaData;
|
||||
|
||||
@ApiModelProperty(name = "url",
|
||||
value = "URL which is used for WEB-CLIP")
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty(name = "supportedOsVersions",
|
||||
value = "ApplicationDTO release supported OS versions")
|
||||
private String supportedOsVersions;
|
||||
@ -125,14 +121,6 @@ public class ApplicationRelease {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getDescription() { return description; }
|
||||
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
@ -35,6 +35,8 @@ import org.wso2.carbon.device.application.mgt.common.response.Tag;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -53,6 +55,12 @@ public interface ApplicationManager {
|
||||
Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact)
|
||||
throws ApplicationManagementException, RequestValidatingException;
|
||||
|
||||
Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact)
|
||||
throws ApplicationManagementException;
|
||||
|
||||
Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact)
|
||||
throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Updates an already existing application.
|
||||
*
|
||||
@ -203,19 +211,14 @@ public interface ApplicationManager {
|
||||
/***
|
||||
* To validate the application creating request
|
||||
*
|
||||
* @param applicationWrapper {@link ApplicationDTO}
|
||||
* @throws RequestValidatingException if the payload contains invalid inputs.
|
||||
*/
|
||||
void validateAppCreatingRequest(ApplicationWrapper applicationWrapper) throws RequestValidatingException;
|
||||
<T> void validateAppCreatingRequest(T param) throws ApplicationManagementException;
|
||||
|
||||
/***
|
||||
*
|
||||
* @param applicationReleaseWrapper {@link ApplicationReleaseDTO}
|
||||
* @param applicationType Type of the application
|
||||
* @throws RequestValidatingException throws if payload does not satisfy requrements.
|
||||
*/
|
||||
void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, String applicationType)
|
||||
throws RequestValidatingException;
|
||||
<T> void validateReleaseCreatingRequest(T param) throws ApplicationManagementException;
|
||||
|
||||
/***
|
||||
*
|
||||
@ -227,7 +230,7 @@ public interface ApplicationManager {
|
||||
void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List<Attachment> attachmentList)
|
||||
throws RequestValidatingException;
|
||||
|
||||
void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException;
|
||||
void validateBinaryArtifact(Attachment binaryFile) throws RequestValidatingException;
|
||||
|
||||
void addAplicationCategories(List<String> categories) throws ApplicationManagementException;
|
||||
|
||||
|
||||
@ -19,27 +19,33 @@ package org.wso2.carbon.device.application.mgt.common.wrapper;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store")
|
||||
public class ApplicationReleaseWrapper {
|
||||
|
||||
@ApiModelProperty(name = "description",
|
||||
value = "Description of the application release")
|
||||
@NotNull
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty(name = "releaseType",
|
||||
value = "Release type of the application release",
|
||||
required = true,
|
||||
example = "alpha, beta etc")
|
||||
@NotNull
|
||||
private String releaseType;
|
||||
|
||||
@ApiModelProperty(name = "price",
|
||||
value = "Price of the application release",
|
||||
required = true)
|
||||
@NotNull
|
||||
private Double price;
|
||||
|
||||
@ApiModelProperty(name = "isSharedWithAllTenants",
|
||||
value = "If application release is shared with all tenants it is eqal to 1 otherwise 0",
|
||||
required = true)
|
||||
@NotNull
|
||||
private boolean isSharedWithAllTenants;
|
||||
|
||||
@ApiModelProperty(name = "metaData",
|
||||
@ -47,12 +53,9 @@ public class ApplicationReleaseWrapper {
|
||||
required = true)
|
||||
private String metaData;
|
||||
|
||||
@ApiModelProperty(name = "url",
|
||||
value = "URL which is used for WEB-CLIP")
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty(name = "supportedOsVersions",
|
||||
value = "ApplicationDTO release supported OS versions")
|
||||
@NotNull
|
||||
private String supportedOsVersions;
|
||||
|
||||
public String getReleaseType() {
|
||||
@ -87,14 +90,6 @@ public class ApplicationReleaseWrapper {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getDescription() { return description; }
|
||||
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
@ -19,6 +19,7 @@ package org.wso2.carbon.device.application.mgt.common.wrapper;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "ApplicationWrapper", description = "ApplicationWrapper represents the an ApplicationDTO in ApplicationDTO Store")
|
||||
@ -28,29 +29,28 @@ public class ApplicationWrapper {
|
||||
@ApiModelProperty(name = "name",
|
||||
value = "Name of the application",
|
||||
required = true)
|
||||
@NotNull
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(name = "description",
|
||||
value = "Description of the application",
|
||||
required = true)
|
||||
@NotNull
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty(name = "appCategories",
|
||||
value = "CategoryDTO of the application",
|
||||
required = true,
|
||||
example = "Educational, Gaming, Travel, Entertainment etc")
|
||||
@NotNull
|
||||
private List<String> appCategories;
|
||||
|
||||
@ApiModelProperty(name = "type",
|
||||
value = "Type of the application",
|
||||
required = true,
|
||||
example = "ENTERPRISE, PUBLIC, WEB, WEB_CLIP etc")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(name = "subType",
|
||||
value = "Subscription type of the application",
|
||||
required = true,
|
||||
example = "PAID, FREE")
|
||||
@NotNull
|
||||
private String subType;
|
||||
|
||||
@ApiModelProperty(name = "paymentCurrency",
|
||||
@ -61,21 +61,25 @@ public class ApplicationWrapper {
|
||||
|
||||
@ApiModelProperty(name = "tags",
|
||||
value = "List of application tags")
|
||||
@NotNull
|
||||
private List<String> tags;
|
||||
|
||||
@ApiModelProperty(name = "unrestrictedRoles",
|
||||
value = "List of roles that users should have to access the application")
|
||||
@NotNull
|
||||
private List<String> unrestrictedRoles;
|
||||
|
||||
@ApiModelProperty(name = "deviceType",
|
||||
value = "Related device type of the application",
|
||||
required = true,
|
||||
example = "IoS, Android, Arduino, RaspberryPi etc")
|
||||
@NotNull
|
||||
private String deviceType;
|
||||
|
||||
@ApiModelProperty(name = "applicationReleaseWrappers",
|
||||
value = "List of application releases",
|
||||
required = true)
|
||||
@NotNull
|
||||
private List<ApplicationReleaseWrapper> applicationReleaseWrappers;
|
||||
|
||||
|
||||
@ -95,10 +99,6 @@ public class ApplicationWrapper {
|
||||
|
||||
public void setTags(List<String> tags) { this.tags = tags; }
|
||||
|
||||
public String getType() { return type; }
|
||||
|
||||
public void setType(String type) { this.type = type; }
|
||||
|
||||
public String getSubType() { return subType; }
|
||||
|
||||
public void setSubType(String subType) { this.subType = subType; }
|
||||
|
||||
@ -0,0 +1,124 @@
|
||||
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.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.application.mgt.common.wrapper;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel(value = "Public App Release Wrapper", description = "This class holds the details when releasing an Public App"
|
||||
+ " Release to application store")
|
||||
public class PublicAppReleaseWrapper {
|
||||
|
||||
@ApiModelProperty(name = "description",
|
||||
value = "Description of the public app release")
|
||||
@NotNull
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty(name = "releaseType",
|
||||
value = "Release type of the public app release",
|
||||
required = true,
|
||||
example = "alpha, beta etc")
|
||||
@NotNull
|
||||
private String releaseType;
|
||||
|
||||
@ApiModelProperty(name = "price",
|
||||
value = "Price of the public app release",
|
||||
required = true)
|
||||
private Double price;
|
||||
|
||||
@ApiModelProperty(name = "isSharedWithAllTenants",
|
||||
value = "If public app release is shared with all tenants it is equal to 1 otherwise 0",
|
||||
required = true)
|
||||
@NotNull
|
||||
private boolean isSharedWithAllTenants;
|
||||
|
||||
@ApiModelProperty(name = "metaData",
|
||||
value = "Meta data of the public app release",
|
||||
required = true)
|
||||
private String metaData;
|
||||
|
||||
@ApiModelProperty(name = "version",
|
||||
value = "Version of the public app release.",
|
||||
required = true)
|
||||
@NotNull
|
||||
private String version;
|
||||
|
||||
@ApiModelProperty(name = "packageName",
|
||||
value = "Package name of the public app release.",
|
||||
required = true)
|
||||
@NotNull
|
||||
private String packageName;
|
||||
|
||||
@ApiModelProperty(name = "supportedOsVersions",
|
||||
value = "ApplicationDTO release supported OS versions")
|
||||
@NotNull
|
||||
private String supportedOsVersions;
|
||||
|
||||
public String getReleaseType() {
|
||||
return releaseType;
|
||||
}
|
||||
|
||||
public void setReleaseType(String releaseType) {
|
||||
this.releaseType = releaseType;
|
||||
}
|
||||
|
||||
public void setIsSharedWithAllTenants(boolean isSharedWithAllTenants) {
|
||||
this.isSharedWithAllTenants = isSharedWithAllTenants;
|
||||
}
|
||||
|
||||
public void setMetaData(String metaData) {
|
||||
this.metaData = metaData;
|
||||
}
|
||||
|
||||
public Double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(Double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public boolean getIsSharedWithAllTenants() {
|
||||
return isSharedWithAllTenants;
|
||||
}
|
||||
|
||||
public String getMetaData() {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public String getDescription() { return description; }
|
||||
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public boolean isSharedWithAllTenants() { return isSharedWithAllTenants; }
|
||||
|
||||
public void setSharedWithAllTenants(boolean sharedWithAllTenants) { isSharedWithAllTenants = sharedWithAllTenants; }
|
||||
|
||||
public String getVersion() { return version; }
|
||||
|
||||
public void setVersion(String version) { this.version = version; }
|
||||
|
||||
public String getPackageName() { return packageName; }
|
||||
|
||||
public void setPackageName(String packageName) { this.packageName = packageName; }
|
||||
|
||||
public String getSupportedOsVersions() { return supportedOsVersions; }
|
||||
|
||||
public void setSupportedOsVersions(String supportedOsVersions) { this.supportedOsVersions = supportedOsVersions; }
|
||||
}
|
||||
@ -0,0 +1,121 @@
|
||||
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.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.application.mgt.common.wrapper;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "PublicAppWrapper", description = "PublicAppWrapper represents an Application in App Store")
|
||||
public class PublicAppWrapper {
|
||||
|
||||
@ApiModelProperty(name = "name",
|
||||
value = "Name of the public app",
|
||||
required = true)
|
||||
@NotNull
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(name = "description",
|
||||
value = "Description of the public app",
|
||||
required = true)
|
||||
@NotNull
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty(name = "categories",
|
||||
value = "List of Categories",
|
||||
required = true,
|
||||
example = "Educational, Gaming, Travel, Entertainment etc")
|
||||
@NotNull
|
||||
private List<String> categories;
|
||||
|
||||
@ApiModelProperty(name = "subType",
|
||||
value = "Subscription method of the public app",
|
||||
required = true,
|
||||
example = "PAID, FREE")
|
||||
@NotNull
|
||||
private String subMethod;
|
||||
|
||||
@ApiModelProperty(name = "deviceType",
|
||||
value = "Related device type of the public app",
|
||||
required = true,
|
||||
example = "IoS, Android, Arduino, RaspberryPi etc")
|
||||
@NotNull
|
||||
private String deviceType;
|
||||
|
||||
@ApiModelProperty(name = "paymentCurrency",
|
||||
value = "Payment currency of the web clip",
|
||||
required = true,
|
||||
example = "$")
|
||||
private String paymentCurrency;
|
||||
|
||||
@ApiModelProperty(name = "tags",
|
||||
value = "List of tags")
|
||||
@NotNull
|
||||
private List<String> tags;
|
||||
|
||||
@ApiModelProperty(name = "unrestrictedRoles",
|
||||
value = "List of roles that users should have to view the public app")
|
||||
@NotNull
|
||||
private List<String> unrestrictedRoles;
|
||||
|
||||
@ApiModelProperty(name = "applicationReleaseWrappers",
|
||||
value = "List of public app releases",
|
||||
required = true)
|
||||
@NotNull
|
||||
private List<PublicAppReleaseWrapper> publicAppReleaseWrappers;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public List<String> getTags() { return tags; }
|
||||
|
||||
public void setTags(List<String> tags) { this.tags = tags; }
|
||||
|
||||
public String getDeviceType() { return deviceType; }
|
||||
|
||||
public void setDeviceType(String deviceType) { this.deviceType = deviceType; }
|
||||
|
||||
public String getPaymentCurrency() { return paymentCurrency; }
|
||||
|
||||
public void setPaymentCurrency(String paymentCurrency) { this.paymentCurrency = paymentCurrency; }
|
||||
|
||||
public List<String> getUnrestrictedRoles() { return unrestrictedRoles; }
|
||||
|
||||
public void setUnrestrictedRoles(List<String> unrestrictedRoles) { this.unrestrictedRoles = unrestrictedRoles; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public List<PublicAppReleaseWrapper> getPublicAppReleaseWrappers() { return publicAppReleaseWrappers; }
|
||||
|
||||
public void setPublicAppReleaseWrappers(List<PublicAppReleaseWrapper> publicAppReleaseWrappers) {
|
||||
this.publicAppReleaseWrappers = publicAppReleaseWrappers; }
|
||||
|
||||
public List<String> getCategories() { return categories; }
|
||||
|
||||
public void setCategories(List<String> categories) { this.categories = categories; }
|
||||
|
||||
public String getSubMethod() { return subMethod; }
|
||||
|
||||
public void setSubMethod(String subMethod) { this.subMethod = subMethod; }
|
||||
}
|
||||
@ -0,0 +1,117 @@
|
||||
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.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.application.mgt.common.wrapper;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store")
|
||||
public class WebAppReleaseWrapper {
|
||||
|
||||
@ApiModelProperty(name = "description",
|
||||
value = "Description of the web clip release")
|
||||
@NotNull
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty(name = "releaseType",
|
||||
value = "Release type of the web clip release",
|
||||
required = true,
|
||||
example = "alpha, beta etc")
|
||||
@NotNull
|
||||
private String releaseType;
|
||||
|
||||
@ApiModelProperty(name = "price",
|
||||
value = "Price of the web clip release",
|
||||
required = true)
|
||||
private Double price;
|
||||
|
||||
@ApiModelProperty(name = "isSharedWithAllTenants",
|
||||
value = "If web clip release is shared with all tenants it is equal to 1 otherwise 0",
|
||||
required = true)
|
||||
@NotNull
|
||||
private boolean isSharedWithAllTenants;
|
||||
|
||||
@ApiModelProperty(name = "metaData",
|
||||
value = "Meta data of the web clip release",
|
||||
required = true)
|
||||
private String metaData;
|
||||
|
||||
@ApiModelProperty(name = "version",
|
||||
value = "Version of the web app release.",
|
||||
required = true)
|
||||
@NotNull
|
||||
private String version;
|
||||
|
||||
@ApiModelProperty(name = "url",
|
||||
value = "URL which is used for WEB-CLIP")
|
||||
@NotNull
|
||||
private String url;
|
||||
|
||||
public String getReleaseType() {
|
||||
return releaseType;
|
||||
}
|
||||
|
||||
public void setReleaseType(String releaseType) {
|
||||
this.releaseType = releaseType;
|
||||
}
|
||||
|
||||
public void setIsSharedWithAllTenants(boolean isSharedWithAllTenants) {
|
||||
this.isSharedWithAllTenants = isSharedWithAllTenants;
|
||||
}
|
||||
|
||||
public void setMetaData(String metaData) {
|
||||
this.metaData = metaData;
|
||||
}
|
||||
|
||||
public Double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(Double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public boolean getIsSharedWithAllTenants() {
|
||||
return isSharedWithAllTenants;
|
||||
}
|
||||
|
||||
public String getMetaData() {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getDescription() { return description; }
|
||||
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public boolean isSharedWithAllTenants() { return isSharedWithAllTenants; }
|
||||
|
||||
public void setSharedWithAllTenants(boolean sharedWithAllTenants) { isSharedWithAllTenants = sharedWithAllTenants; }
|
||||
|
||||
public String getVersion() { return version; }
|
||||
|
||||
public void setVersion(String version) { this.version = version; }
|
||||
}
|
||||
@ -0,0 +1,121 @@
|
||||
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.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.application.mgt.common.wrapper;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "WebAppWrapper", description = "WebAppWrapper represents an ApplicationDTO in ApplicationDTO Store")
|
||||
public class WebAppWrapper {
|
||||
|
||||
@ApiModelProperty(name = "name",
|
||||
value = "Name of the web clip",
|
||||
required = true)
|
||||
@NotNull
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(name = "description",
|
||||
value = "Description of the web clip",
|
||||
required = true)
|
||||
@NotNull
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty(name = "categories",
|
||||
value = "List of Categories",
|
||||
required = true,
|
||||
example = "Educational, Gaming, Travel, Entertainment etc")
|
||||
@NotNull
|
||||
private List<String> categories;
|
||||
|
||||
@ApiModelProperty(name = "subType",
|
||||
value = "Subscription method of the web clip",
|
||||
required = true,
|
||||
example = "PAID, FREE")
|
||||
@NotNull
|
||||
private String subMethod;
|
||||
|
||||
@ApiModelProperty(name = "Web App Type",
|
||||
value = "Type of the web app",
|
||||
required = true,
|
||||
example = "WEB_APP, WEB_CLIP")
|
||||
@NotNull
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(name = "paymentCurrency",
|
||||
value = "Payment currency of the web clip",
|
||||
required = true,
|
||||
example = "$")
|
||||
private String paymentCurrency;
|
||||
|
||||
@ApiModelProperty(name = "tags",
|
||||
value = "List of tags")
|
||||
@NotNull
|
||||
private List<String> tags;
|
||||
|
||||
@ApiModelProperty(name = "unrestrictedRoles",
|
||||
value = "List of roles that users should have to view the web clip")
|
||||
@NotNull
|
||||
private List<String> unrestrictedRoles;
|
||||
|
||||
@ApiModelProperty(name = "applicationReleaseWrappers",
|
||||
value = "List of web clip releases",
|
||||
required = true)
|
||||
@NotNull
|
||||
private List<WebAppReleaseWrapper> webAppReleaseWrappers;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public List<String> getTags() { return tags; }
|
||||
|
||||
public void setTags(List<String> tags) { this.tags = tags; }
|
||||
|
||||
public String getPaymentCurrency() { return paymentCurrency; }
|
||||
|
||||
public void setPaymentCurrency(String paymentCurrency) { this.paymentCurrency = paymentCurrency; }
|
||||
|
||||
public List<String> getUnrestrictedRoles() { return unrestrictedRoles; }
|
||||
|
||||
public void setUnrestrictedRoles(List<String> unrestrictedRoles) { this.unrestrictedRoles = unrestrictedRoles; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public List<WebAppReleaseWrapper> getWebAppReleaseWrappers() { return webAppReleaseWrappers; }
|
||||
|
||||
public void setWebAppReleaseWrappers(List<WebAppReleaseWrapper> webAppReleaseWrappers) {
|
||||
this.webAppReleaseWrappers = webAppReleaseWrappers; }
|
||||
|
||||
public List<String> getCategories() { return categories; }
|
||||
|
||||
public void setCategories(List<String> categories) { this.categories = categories; }
|
||||
|
||||
public String getSubMethod() { return subMethod; }
|
||||
|
||||
public void setSubMethod(String subMethod) { this.subMethod = subMethod; }
|
||||
|
||||
public String getType() { return type; }
|
||||
|
||||
public void setType(String type) { this.type = type; }
|
||||
}
|
||||
@ -83,6 +83,9 @@ public interface ApplicationDAO {
|
||||
|
||||
List<CategoryDTO> getAllCategories(int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
List<Integer> getCategoryIdsForCategoryNames(List<String> CatgeoryNames, int tenantId)
|
||||
throws ApplicationManagementDAOException;
|
||||
|
||||
List<Integer> getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException;
|
||||
|
||||
CategoryDTO getCategoryForCategoryName(String categoryName, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
@ -805,6 +805,40 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getCategoryIdsForCategoryNames(List<String> categoryNames, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to get tag ids for given tag names");
|
||||
}
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
int index = 1;
|
||||
List<Integer> tagIds = new ArrayList<>();
|
||||
StringJoiner joiner = new StringJoiner(",",
|
||||
"SELECT AP_APP_CATEGORY.ID AS ID FROM AP_APP_CATEGORY WHERE AP_APP_CATEGORY.CATEGORY IN (", ") AND TENANT_ID = ?");
|
||||
categoryNames.stream().map(ignored -> "?").forEach(joiner::add);
|
||||
String query = joiner.toString();
|
||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||
for (String categoryName : categoryNames) {
|
||||
ps.setObject(index++, categoryName);
|
||||
}
|
||||
ps.setInt(index, tenantId);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
tagIds.add(rs.getInt("ID"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return tagIds;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ApplicationManagementDAOException(
|
||||
"Error occurred while obtaining the DB connection when getting categories", e);
|
||||
} catch (SQLException e) {
|
||||
throw new ApplicationManagementDAOException("Error occurred while getting categories", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
@ -994,7 +1028,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
Connection conn;
|
||||
String sql = "UPDATE " +
|
||||
"AP_APP_CATEGORY cat " +
|
||||
"SET cat.CATEGORY_NAME = ? " +
|
||||
"SET cat.CATEGORY = ? " +
|
||||
"WHERE " +
|
||||
"cat.ID = ? AND " +
|
||||
"cat.TENANT_ID = ?";
|
||||
@ -1002,8 +1036,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setString(1, categoryDTO.getCategoryName());
|
||||
stmt.setInt(1, categoryDTO.getId());
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.setInt(2, categoryDTO.getId());
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
|
||||
@ -549,7 +549,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
||||
sql += "GROUP_NAME = ? ";
|
||||
}
|
||||
|
||||
sql += "AND AP_APP_RELEASE_ID = ? AND AND TENANT_ID = ?";
|
||||
sql += "AND AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
|
||||
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
package org.wso2.carbon.device.application.mgt.core.impl;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.validator.routines.UrlValidator;
|
||||
@ -28,6 +29,7 @@ import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact;
|
||||
import org.wso2.carbon.device.application.mgt.common.ApplicationInstaller;
|
||||
import org.wso2.carbon.device.application.mgt.common.DeviceTypes;
|
||||
import org.wso2.carbon.device.application.mgt.common.LifecycleChanger;
|
||||
import org.wso2.carbon.device.application.mgt.common.Pagination;
|
||||
import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration;
|
||||
@ -57,6 +59,10 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppReleaseWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
|
||||
@ -64,6 +70,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.DAOUtil;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
|
||||
@ -141,94 +148,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
+ userName);
|
||||
}
|
||||
|
||||
ApplicationDTO applicationDTO;
|
||||
List<String> unrestrictedRoles;
|
||||
List<Integer> categoryIds = new ArrayList<>();
|
||||
List<String> tags;
|
||||
|
||||
//validating and verifying application data
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
applicationDTO = appWrapperToAppDTO(applicationWrapper);
|
||||
unrestrictedRoles = applicationWrapper.getUnrestrictedRoles();
|
||||
tags = applicationWrapper.getTags();
|
||||
|
||||
if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) {
|
||||
if (!isValidRestrictedRole(unrestrictedRoles)) {
|
||||
String msg = "Unrestricted role list contain role/roles which are not in the user store.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
if (!hasUserRole(unrestrictedRoles, userName)) {
|
||||
String msg = "You are trying to restrict the visibility of the application for a role set, but "
|
||||
+ "in order to perform the action at least one role should be assigned to user: "
|
||||
+ userName;
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
Filter filter = new Filter();
|
||||
filter.setFullMatch(true);
|
||||
filter.setAppName(applicationDTO.getName().trim());
|
||||
filter.setOffset(0);
|
||||
filter.setLimit(1);
|
||||
List<ApplicationDTO> applicationList = applicationDAO
|
||||
.getApplications(filter, applicationDTO.getDeviceTypeId(), tenantId);
|
||||
if (!applicationList.isEmpty()) {
|
||||
String msg = "Already an application registered with same name - " + applicationList.get(0).getName()
|
||||
+ " for the device type " + applicationWrapper.getDeviceType();
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
}
|
||||
|
||||
List<CategoryDTO> registeredCategories = this.applicationDAO.getAllCategories(tenantId);
|
||||
List<String> appCategories = applicationWrapper.getAppCategories();
|
||||
|
||||
if (registeredCategories.isEmpty()) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Registered application category set is empty. Since it is mandatory to add application "
|
||||
+ "category when adding new application, registered application category list shouldn't be null.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
for (String cat : appCategories) {
|
||||
boolean isValidCategory = false;
|
||||
for (CategoryDTO obj : registeredCategories) {
|
||||
if (cat.equals(obj.getCategoryName())) {
|
||||
categoryIds.add(obj.getId());
|
||||
isValidCategory = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isValidCategory) {
|
||||
String msg = "Application Creating request contains invalid categories. Hence please verify the "
|
||||
+ "application creating payload.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while getting database connection.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (UnexpectedServerErrorException e) {
|
||||
String msg = "Error occurred when getting Device Type data.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg = "Error occurred while getting data which is related to application. application name: "
|
||||
+ applicationWrapper.getName() + " and application type: " + applicationWrapper.getType();
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (UserStoreException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred when validating the unrestricted roles given for the application";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper);
|
||||
|
||||
//uploading application artifacts
|
||||
try {
|
||||
@ -243,133 +163,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
|
||||
//insert application data into database
|
||||
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
|
||||
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
||||
try {
|
||||
List<ApplicationReleaseDTO> applicationReleaseEntities = new ArrayList<>();
|
||||
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
// Insert to application table
|
||||
int appId = this.applicationDAO.createApplication(applicationDTO, tenantId);
|
||||
if (appId == -1) {
|
||||
log.error("Application data storing is Failed.");
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
|
||||
return null;
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("New ApplicationDTO entry added to AP_APP table. App Id:" + appId);
|
||||
}
|
||||
//add application categories
|
||||
this.applicationDAO.addCategoryMapping(categoryIds, appId, tenantId);
|
||||
|
||||
//adding application unrestricted roles
|
||||
if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) {
|
||||
this.visibilityDAO.addUnrestrictedRoles(unrestrictedRoles, appId, tenantId);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("New restricted roles to app ID mapping added to AP_UNRESTRICTED_ROLE table."
|
||||
+ " App Id:" + appId);
|
||||
}
|
||||
}
|
||||
|
||||
//adding application tags
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
List<TagDTO> registeredTags = applicationDAO.getAllTags(tenantId);
|
||||
List<String> registeredTagNames = new ArrayList<>();
|
||||
List<Integer> tagIds = new ArrayList<>();
|
||||
|
||||
for (TagDTO tagDTO : registeredTags) {
|
||||
registeredTagNames.add(tagDTO.getTagName());
|
||||
}
|
||||
List<String> newTags = getDifference(tags, registeredTagNames);
|
||||
if (!newTags.isEmpty()) {
|
||||
this.applicationDAO.addTags(newTags, tenantId);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("New tags entry added to AP_APP_TAG table. App Id:" + appId);
|
||||
}
|
||||
tagIds = this.applicationDAO.getTagIdsForTagNames(tags, tenantId);
|
||||
} else {
|
||||
for (TagDTO tagDTO : registeredTags) {
|
||||
for (String tagName : tags) {
|
||||
if (tagName.equals(tagDTO.getTagName())) {
|
||||
tagIds.add(tagDTO.getId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.applicationDAO.addTagMapping(tagIds, appId, tenantId);
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Creating a new release. App Id:" + appId);
|
||||
}
|
||||
String initialLifecycleState = lifecycleStateManager.getInitialState();
|
||||
applicationReleaseDTO.setCurrentState(initialLifecycleState);
|
||||
applicationReleaseDTO = this.applicationReleaseDAO
|
||||
.createRelease(applicationReleaseDTO, appId, tenantId);
|
||||
LifecycleState lifecycleState = getLifecycleStateInstance(initialLifecycleState,
|
||||
initialLifecycleState);
|
||||
this.lifecycleStateDAO
|
||||
.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
||||
applicationReleaseEntities.add(applicationReleaseDTO);
|
||||
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
|
||||
Application application = appDtoToAppResponse(applicationDTO);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return application;
|
||||
}
|
||||
} catch (LifeCycleManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg =
|
||||
"Error occurred while adding lifecycle state. application name: " + applicationWrapper.getName()
|
||||
+ " application type: is " + applicationWrapper.getType();
|
||||
log.error(msg);
|
||||
try {
|
||||
applicationStorageManager.deleteAllApplicationReleaseArtifacts(
|
||||
Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
|
||||
} 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);
|
||||
throw new ApplicationManagementException(errorLog, e);
|
||||
}
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while adding application or application release. application name: "
|
||||
+ applicationWrapper.getName() + " application type: " + applicationWrapper.getType();
|
||||
log.error(msg);
|
||||
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (LifecycleManagementException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred when getting initial lifecycle state. application name: " + applicationWrapper
|
||||
.getName() + " application type: is " + applicationWrapper.getType();
|
||||
log.error(msg);
|
||||
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while getting database connection.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (VisibilityManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg =
|
||||
"Error occurred while adding unrestricted roles. application name: " + applicationWrapper.getName()
|
||||
+ " application type: " + applicationWrapper.getType();
|
||||
log.error(msg);
|
||||
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Error occurred while disabling AutoCommit.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
return addAppDataIntoDB(applicationDTO, tenantId);
|
||||
}
|
||||
|
||||
private void deleteApplicationArtifacts(List<String> directoryPaths) throws ApplicationManagementException {
|
||||
@ -617,6 +411,80 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
return applicationReleaseDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact)
|
||||
throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Web clip create request is received for the tenant : " + tenantId + " From" + " the user : "
|
||||
+ userName);
|
||||
}
|
||||
|
||||
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper);
|
||||
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
//todo check installer name exists or not, do it in the validation method
|
||||
String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName());
|
||||
applicationReleaseDTO.setUuid(uuid);
|
||||
applicationReleaseDTO.setAppHashValue(md5);
|
||||
|
||||
//uploading application artifacts
|
||||
try {
|
||||
applicationDTO.getApplicationReleaseDTOs().clear();
|
||||
applicationDTO.getApplicationReleaseDTOs().add(addImageArtifacts(applicationReleaseDTO, applicationArtifact));
|
||||
} catch (ResourceManagementException e) {
|
||||
String msg = "Error Occured when uploading artifacts of the web clip: " + webAppWrapper.getName();
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
|
||||
//insert application data into database
|
||||
return addAppDataIntoDB(applicationDTO, tenantId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact)
|
||||
throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
String publicAppStorePath = "";
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Public app creating request is received for the tenant : " + tenantId + " From" + " the user : "
|
||||
+ userName);
|
||||
}
|
||||
|
||||
if (DeviceTypes.ANDROID.toString().equals(publicAppWrapper.getDeviceType())) {
|
||||
publicAppStorePath = Constants.GOOGLE_PLAY_STORE_URL;
|
||||
} else if (DeviceTypes.IOS.toString().equals(publicAppWrapper.getDeviceType())) {
|
||||
publicAppStorePath = Constants.APPLE_STORE_URL;
|
||||
}
|
||||
|
||||
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(publicAppWrapper);
|
||||
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String appInstallerUrl = publicAppStorePath + applicationReleaseDTO.getPackageName();
|
||||
//todo check app package name exist or not, do it in validation method
|
||||
applicationReleaseDTO.setInstallerName(appInstallerUrl);
|
||||
String md5 = DigestUtils.md5Hex(appInstallerUrl);
|
||||
applicationReleaseDTO.setUuid(uuid);
|
||||
applicationReleaseDTO.setAppHashValue(md5);
|
||||
|
||||
//uploading application artifacts
|
||||
try {
|
||||
applicationDTO.getApplicationReleaseDTOs().clear();
|
||||
applicationDTO.getApplicationReleaseDTOs()
|
||||
.add(addImageArtifacts(applicationReleaseDTO, applicationArtifact));
|
||||
} catch (ResourceManagementException e) {
|
||||
String msg = "Error Occured when uploading artifacts of the public app: " + publicAppWrapper.getName();
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
}
|
||||
|
||||
//insert application data into database
|
||||
return addAppDataIntoDB(applicationDTO, tenantId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
@ -688,7 +556,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
}
|
||||
|
||||
for (ApplicationDTO appDTO : filteredApplications) {
|
||||
applications.add(appDtoToAppResponse(appDTO));
|
||||
applications.add(APIUtil.appDtoToAppResponse(appDTO));
|
||||
}
|
||||
|
||||
Pagination pagination = new Pagination();
|
||||
@ -731,6 +599,145 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
/***
|
||||
* 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.
|
||||
*
|
||||
* @param applicationDTO Application DTO object.
|
||||
* @param tenantId Tenant Id
|
||||
* @return {@link Application}
|
||||
* @throws ApplicationManagementException which throws if error occurs while during application management.
|
||||
*/
|
||||
private Application addAppDataIntoDB(ApplicationDTO applicationDTO, int tenantId)
|
||||
throws ApplicationManagementException {
|
||||
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
|
||||
List<String> unrestrictedRoles = applicationDTO.getUnrestrictedRoles();
|
||||
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
||||
List<String> categories = applicationDTO.getAppCategories();
|
||||
List<String> tags = applicationDTO.getTags();
|
||||
List<ApplicationReleaseDTO> applicationReleaseEntities = new ArrayList<>();
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
// Insert to application table
|
||||
int appId = this.applicationDAO.createApplication(applicationDTO, tenantId);
|
||||
if (appId == -1) {
|
||||
log.error("Application data storing is Failed.");
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
|
||||
return null;
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("New ApplicationDTO entry added to AP_APP table. App Id:" + appId);
|
||||
}
|
||||
//add application categories
|
||||
|
||||
List<Integer> categoryIds = applicationDAO.getCategoryIdsForCategoryNames(categories, tenantId);
|
||||
this.applicationDAO.addCategoryMapping(categoryIds, appId, tenantId);
|
||||
|
||||
//adding application unrestricted roles
|
||||
if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) {
|
||||
this.visibilityDAO.addUnrestrictedRoles(unrestrictedRoles, appId, tenantId);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("New restricted roles to app ID mapping added to AP_UNRESTRICTED_ROLE table."
|
||||
+ " App Id:" + appId);
|
||||
}
|
||||
}
|
||||
|
||||
//adding application tags
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
List<TagDTO> registeredTags = applicationDAO.getAllTags(tenantId);
|
||||
List<String> registeredTagNames = new ArrayList<>();
|
||||
List<Integer> tagIds = new ArrayList<>();
|
||||
|
||||
for (TagDTO tagDTO : registeredTags) {
|
||||
registeredTagNames.add(tagDTO.getTagName());
|
||||
}
|
||||
List<String> newTags = getDifference(tags, registeredTagNames);
|
||||
if (!newTags.isEmpty()) {
|
||||
this.applicationDAO.addTags(newTags, tenantId);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("New tags entry added to AP_APP_TAG table. App Id:" + appId);
|
||||
}
|
||||
tagIds = this.applicationDAO.getTagIdsForTagNames(tags, tenantId);
|
||||
} else {
|
||||
for (TagDTO tagDTO : registeredTags) {
|
||||
for (String tagName : tags) {
|
||||
if (tagName.equals(tagDTO.getTagName())) {
|
||||
tagIds.add(tagDTO.getId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.applicationDAO.addTagMapping(tagIds, appId, tenantId);
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Creating a new release. App Id:" + appId);
|
||||
}
|
||||
String initialLifecycleState = lifecycleStateManager.getInitialState();
|
||||
applicationReleaseDTO.setCurrentState(initialLifecycleState);
|
||||
applicationReleaseDTO = this.applicationReleaseDAO
|
||||
.createRelease(applicationReleaseDTO, appId, tenantId);
|
||||
LifecycleState lifecycleState = getLifecycleStateInstance(initialLifecycleState, initialLifecycleState);
|
||||
this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
||||
applicationReleaseEntities.add(applicationReleaseDTO);
|
||||
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
|
||||
Application application = APIUtil.appDtoToAppResponse(applicationDTO);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return application;
|
||||
}
|
||||
} catch (LifeCycleManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg =
|
||||
"Error occurred while adding lifecycle state. application name: " + applicationDTO.getName() + ".";
|
||||
log.error(msg);
|
||||
try {
|
||||
applicationStorageManager.deleteAllApplicationReleaseArtifacts(
|
||||
Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
|
||||
} 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);
|
||||
throw new ApplicationManagementException(errorLog, e);
|
||||
}
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while adding application or application release. application name: "
|
||||
+ applicationDTO.getName() + ".";
|
||||
log.error(msg);
|
||||
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (LifecycleManagementException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg =
|
||||
"Error occurred when getting initial lifecycle state. application name: " + applicationDTO.getName()
|
||||
+ ".";
|
||||
log.error(msg);
|
||||
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while getting database connection.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (VisibilityManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred while adding unrestricted roles. application name: " + applicationDTO.getName()
|
||||
+ ".";
|
||||
log.error(msg);
|
||||
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()));
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Error occurred while disabling AutoCommit.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationRelease createRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper,
|
||||
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
|
||||
@ -752,7 +759,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
.createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId);
|
||||
this.lifecycleStateDAO
|
||||
.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
||||
applicationRelease = releaseDtoToRelease(applicationReleaseDTO);
|
||||
applicationRelease = APIUtil.releaseDtoToRelease(applicationReleaseDTO);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return applicationRelease;
|
||||
} catch (TransactionManagementException e) {
|
||||
@ -807,7 +814,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
try {
|
||||
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
||||
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(),
|
||||
deviceType.getName(), releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact,
|
||||
deviceType.getName(), APIUtil.releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact,
|
||||
true);
|
||||
return addImageArtifacts(applicationReleaseDTO, applicationArtifact);
|
||||
} catch (ResourceManagementException e) {
|
||||
@ -861,7 +868,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
log.error(msg);
|
||||
throw new ForbiddenException(msg);
|
||||
}
|
||||
return appDtoToAppResponse(applicationDTO);
|
||||
return APIUtil.appDtoToAppResponse(applicationDTO);
|
||||
} catch (LifecycleManagementException e){
|
||||
String msg = "Error occurred when getting the last state of the application lifecycle flow";
|
||||
log.error(msg);
|
||||
@ -911,7 +918,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
log.error(msg);
|
||||
throw new ForbiddenException(msg);
|
||||
}
|
||||
return releaseDtoToRelease(applicationReleaseDTO);
|
||||
return APIUtil.releaseDtoToRelease(applicationReleaseDTO);
|
||||
} catch (LifecycleManagementException e) {
|
||||
String msg = "Error occurred when getting the end state of the application lifecycle flow";
|
||||
log.error(msg);
|
||||
@ -977,7 +984,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
log.error(msg);
|
||||
throw new ForbiddenException(msg);
|
||||
}
|
||||
return appDtoToAppResponse(applicationDTO);
|
||||
return APIUtil.appDtoToAppResponse(applicationDTO);
|
||||
} catch (LifecycleManagementException e) {
|
||||
String msg = "Error occurred when getting the last state of the application lifecycle flow";
|
||||
log.error(msg);
|
||||
@ -1542,7 +1549,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
}
|
||||
this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return releaseDtoToRelease(applicationReleaseDTO);
|
||||
return APIUtil.releaseDtoToRelease(applicationReleaseDTO);
|
||||
} else {
|
||||
String msg = "Invalid lifecycle state transition from '" + applicationReleaseDTO.getCurrentState() + "'"
|
||||
+ " to '" + lifecycleChanger.getAction() + "'";
|
||||
@ -2267,77 +2274,263 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
|
||||
|
||||
@Override
|
||||
public void validateAppCreatingRequest(ApplicationWrapper applicationWrapper) throws RequestValidatingException {
|
||||
public <T> void validateAppCreatingRequest(T param) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
int deviceTypeId = -1;
|
||||
String appName;
|
||||
List<String> appCategories;
|
||||
List<String> unrestrictedRoles;
|
||||
|
||||
String applicationType = applicationWrapper.getType();
|
||||
|
||||
if (StringUtils.isEmpty(applicationWrapper.getName())) {
|
||||
if (param instanceof ApplicationWrapper) {
|
||||
ApplicationWrapper applicationWrapper = (ApplicationWrapper) param;
|
||||
appName = applicationWrapper.getName();
|
||||
if (StringUtils.isEmpty(appName)) {
|
||||
String msg = "Application name cannot be empty.";
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (applicationWrapper.getAppCategories() == null) {
|
||||
appCategories = applicationWrapper.getAppCategories();
|
||||
if (appCategories == null) {
|
||||
String msg = "Application category can't be null.";
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (applicationWrapper.getAppCategories().isEmpty()) {
|
||||
if (appCategories.isEmpty()) {
|
||||
String msg = "Application category can't be empty.";
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
}
|
||||
if (StringUtils.isEmpty(applicationType)) {
|
||||
String msg = "Application type can't be empty.";
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (StringUtils.isEmpty(applicationWrapper.getDeviceType())) {
|
||||
String msg = "Device type can't be empty for the application.";
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType());
|
||||
deviceTypeId = deviceType.getId();
|
||||
|
||||
List<ApplicationReleaseWrapper> applicationReleaseWrappers;
|
||||
applicationReleaseWrappers = applicationWrapper.getApplicationReleaseWrappers();
|
||||
|
||||
if (applicationReleaseWrappers == null || applicationReleaseWrappers.size() != 1) {
|
||||
String msg =
|
||||
"Invalid application creating request. ApplicationDTO creating request must have single application "
|
||||
+ "release. ApplicationDTO name:" + applicationWrapper.getName() + " and type: " + applicationWrapper
|
||||
.getType();
|
||||
String msg = "Invalid application creating request. Application creating request must have single "
|
||||
+ "application release. Application name:" + applicationWrapper.getName() + ".";
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
unrestrictedRoles = applicationWrapper.getUnrestrictedRoles();
|
||||
} else if (param instanceof WebAppWrapper) {
|
||||
WebAppWrapper webAppWrapper = (WebAppWrapper) param;
|
||||
appName = webAppWrapper.getName();
|
||||
if (StringUtils.isEmpty(appName)) {
|
||||
String msg = "Web Clip name cannot be empty.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
appCategories = webAppWrapper.getCategories();
|
||||
if (appCategories == null) {
|
||||
String msg = "Web Clip category can't be null.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (appCategories.isEmpty()) {
|
||||
String msg = "Web clip category can't be empty.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (StringUtils.isEmpty(webAppWrapper.getType()) || (!ApplicationType.WEB_CLIP.toString()
|
||||
.equals(webAppWrapper.getType()) && !ApplicationType.WEB_APP.toString()
|
||||
.equals(webAppWrapper.getType()))) {
|
||||
String msg = "Web app wrapper contains invalid application type with the request. Hence please verify "
|
||||
+ "the request payload..";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
|
||||
List<WebAppReleaseWrapper> webAppReleaseWrappers;
|
||||
webAppReleaseWrappers = webAppWrapper.getWebAppReleaseWrappers();
|
||||
|
||||
if (webAppReleaseWrappers == null || 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();
|
||||
} else if (param instanceof PublicAppWrapper) {
|
||||
PublicAppWrapper publicAppWrapper = (PublicAppWrapper) param;
|
||||
appName = publicAppWrapper.getName();
|
||||
if (StringUtils.isEmpty(appName)) {
|
||||
String msg = "Application name cannot be empty for public app.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
appCategories = publicAppWrapper.getCategories();
|
||||
if (appCategories == null) {
|
||||
String msg = "Application category can't be null.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (appCategories.isEmpty()) {
|
||||
String msg = "Application category can't be empty.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (StringUtils.isEmpty(publicAppWrapper.getDeviceType())) {
|
||||
String msg = "Device type can't be empty for the public application.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
DeviceType deviceType = getDeviceTypeData(publicAppWrapper.getDeviceType());
|
||||
deviceTypeId = deviceType.getId();
|
||||
|
||||
List<PublicAppReleaseWrapper> publicAppReleaseWrappers;
|
||||
publicAppReleaseWrappers = publicAppWrapper.getPublicAppReleaseWrappers();
|
||||
|
||||
if (publicAppReleaseWrappers == null || 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();
|
||||
} else {
|
||||
String msg = "Invalid payload found with the request. Hence verify the request payload object.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) {
|
||||
if (!isValidRestrictedRole(unrestrictedRoles)) {
|
||||
String msg = "Unrestricted role list contain role/roles which are not in the user store.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
if (!hasUserRole(unrestrictedRoles, userName)) {
|
||||
String msg = "You are trying to restrict the visibility of the application for a role set, but "
|
||||
+ "in order to perform the action at least one role should be assigned to user: "
|
||||
+ userName;
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
Filter filter = new Filter();
|
||||
filter.setFullMatch(true);
|
||||
filter.setAppName(appName);
|
||||
filter.setOffset(0);
|
||||
filter.setLimit(1);
|
||||
List<ApplicationDTO> applicationList = applicationDAO.getApplications(filter, deviceTypeId, tenantId);
|
||||
if (!applicationList.isEmpty()) {
|
||||
String msg =
|
||||
"Already an application registered with same name - " + applicationList.get(0).getName() + ".";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
|
||||
List<CategoryDTO> registeredCategories = this.applicationDAO.getAllCategories(tenantId);
|
||||
|
||||
if (registeredCategories.isEmpty()) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Registered application category set is empty. Since it is mandatory to add application "
|
||||
+ "category when adding new application, registered application category list shouldn't be null.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
for (String cat : appCategories) {
|
||||
boolean isValidCategory = false;
|
||||
for (CategoryDTO obj : registeredCategories) {
|
||||
if (cat.equals(obj.getCategoryName())) {
|
||||
isValidCategory = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isValidCategory) {
|
||||
String msg = "Application Creating request contains invalid categories. Hence please verify the "
|
||||
+ "application creating payload.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "Error occurred while getting database connection.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg =
|
||||
"Error occurred while getting data which is related to web clip. web clip name: " + appName + ".";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (UserStoreException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Error occurred when validating the unrestricted roles given for the web clip";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper,
|
||||
String applicationType) throws RequestValidatingException {
|
||||
|
||||
if (applicationReleaseWrapper == null){
|
||||
String msg = "Application Release shouldn't be null.";
|
||||
public <T> void validateReleaseCreatingRequest(T param) throws ApplicationManagementException {
|
||||
if (param == null) {
|
||||
String msg = "In order to validate release creating request param shouldn't be null.";
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
|
||||
if (ApplicationType.WEB_CLIP.toString().equals(applicationType)) {
|
||||
UrlValidator urlValidator = new UrlValidator();
|
||||
if (StringUtils
|
||||
.isEmpty(applicationReleaseWrapper.getUrl())){
|
||||
String msg = "URL should't be null for the application release creating request for application type WEB_CLIP";
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
}
|
||||
if (!urlValidator.isValid(applicationReleaseWrapper.getUrl())){
|
||||
String msg = "Request payload contains an invalid Web Clip URL.";
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
}
|
||||
}
|
||||
if (param instanceof ApplicationReleaseWrapper) {
|
||||
ApplicationReleaseWrapper applicationReleaseWrapper = (ApplicationReleaseWrapper) param;
|
||||
if (StringUtils.isEmpty(applicationReleaseWrapper.getSupportedOsVersions())) {
|
||||
String msg = "Supported OS Version shouldn't be null or empty.";
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
if (param instanceof WebAppReleaseWrapper) {
|
||||
WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param;
|
||||
UrlValidator urlValidator = new UrlValidator();
|
||||
if (StringUtils.isEmpty(webAppReleaseWrapper.getVersion())) {
|
||||
String msg = "Version shouldn't be empty or null for the WEB CLIP release creating request.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (StringUtils.isEmpty(webAppReleaseWrapper.getUrl())) {
|
||||
String msg = "URL should't be null for the application release creating request for application type "
|
||||
+ "WEB_CLIP";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (!urlValidator.isValid(webAppReleaseWrapper.getUrl())) {
|
||||
String msg = "Request payload contains an invalid Web Clip URL.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
} else if (param instanceof PublicAppReleaseWrapper) {
|
||||
PublicAppReleaseWrapper publicAppReleaseWrapper = (PublicAppReleaseWrapper) param;
|
||||
if (StringUtils.isEmpty(publicAppReleaseWrapper.getSupportedOsVersions())) {
|
||||
String msg = "Supported OS Version shouldn't be null or empty for public app release creating request.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (StringUtils.isEmpty(publicAppReleaseWrapper.getVersion())) {
|
||||
String msg = "Version shouldn't be empty or null for the Public App release creating request.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (StringUtils.isEmpty(publicAppReleaseWrapper.getPackageName())) {
|
||||
String msg = "Package name shouldn't be empty or null for the Public App release creating request.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
|
||||
} else {
|
||||
String msg = "Invalid payload found with the release creating request. Hence verify the release creating "
|
||||
+ "request payload object.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2350,6 +2543,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
}
|
||||
//todo remove this check, because banner is not mandatory to have
|
||||
if (bannerFile == null) {
|
||||
String msg = "Banner file is not found with the application release creating request.";
|
||||
log.error(msg);
|
||||
@ -2363,116 +2557,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException {
|
||||
public void validateBinaryArtifact(Attachment binaryFile) throws RequestValidatingException {
|
||||
|
||||
if (StringUtils.isEmpty(applicationType)) {
|
||||
String msg = "Application type can't be empty.";
|
||||
if (binaryFile == null) {
|
||||
String msg = "Binary file is not found with the application release creating request for ENTERPRISE app "
|
||||
+ "creating request.";
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
}
|
||||
if (!isValidAppType(applicationType)) {
|
||||
String msg = "App Type contains in the application creating payload doesn't match with supported app types.";
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
}
|
||||
if (binaryFile == null && ApplicationType.ENTERPRISE.toString().equals(applicationType)) {
|
||||
String msg = "Binary file is not found with the application release creating request. ApplicationDTO type: "
|
||||
+ applicationType;
|
||||
log.error(msg);
|
||||
throw new RequestValidatingException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ApplicationDTO appWrapperToAppDTO(ApplicationWrapper applicationWrapper)
|
||||
throws BadRequestException, UnexpectedServerErrorException {
|
||||
|
||||
DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType());
|
||||
ApplicationDTO applicationDTO = new ApplicationDTO();
|
||||
applicationDTO.setName(applicationWrapper.getName());
|
||||
applicationDTO.setDescription(applicationWrapper.getDescription());
|
||||
applicationDTO.setAppCategories(applicationWrapper.getAppCategories());
|
||||
applicationDTO.setType(applicationWrapper.getType());
|
||||
applicationDTO.setSubType(applicationWrapper.getSubType());
|
||||
applicationDTO.setPaymentCurrency(applicationWrapper.getPaymentCurrency());
|
||||
applicationDTO.setTags(applicationWrapper.getTags());
|
||||
applicationDTO.setUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles());
|
||||
applicationDTO.setDeviceTypeId(deviceType.getId());
|
||||
List<ApplicationReleaseDTO> applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers()
|
||||
.stream().map(this::releaseWrapperToReleaseDTO).collect(Collectors.toList());
|
||||
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
|
||||
return applicationDTO;
|
||||
}
|
||||
|
||||
private ApplicationReleaseDTO releaseWrapperToReleaseDTO(ApplicationReleaseWrapper applicationReleaseWrapper){
|
||||
ApplicationReleaseDTO applicationReleaseDTO = new ApplicationReleaseDTO();
|
||||
applicationReleaseDTO.setDescription(applicationReleaseWrapper.getDescription());
|
||||
applicationReleaseDTO.setReleaseType(applicationReleaseWrapper.getReleaseType());
|
||||
applicationReleaseDTO.setPrice(applicationReleaseWrapper.getPrice());
|
||||
applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseWrapper.getIsSharedWithAllTenants());
|
||||
applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData());
|
||||
applicationReleaseDTO.setUrl(applicationReleaseWrapper.getUrl());
|
||||
applicationReleaseDTO.setSupportedOsVersions(applicationReleaseWrapper.getSupportedOsVersions());
|
||||
return applicationReleaseDTO;
|
||||
}
|
||||
|
||||
private Application appDtoToAppResponse(ApplicationDTO applicationDTO)
|
||||
throws BadRequestException, UnexpectedServerErrorException {
|
||||
|
||||
Application application = new Application();
|
||||
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
||||
application.setId(applicationDTO.getId());
|
||||
application.setName(applicationDTO.getName());
|
||||
application.setDescription(applicationDTO.getDescription());
|
||||
application.setAppCategories(applicationDTO.getAppCategories());
|
||||
application.setType(applicationDTO.getType());
|
||||
application.setSubType(applicationDTO.getSubType());
|
||||
application.setPaymentCurrency(applicationDTO.getPaymentCurrency());
|
||||
application.setTags(applicationDTO.getTags());
|
||||
application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles());
|
||||
application.setDeviceType(deviceType.getName());
|
||||
application.setRating(applicationDTO.getAppRating());
|
||||
List<ApplicationRelease> applicationReleases = applicationDTO.getApplicationReleaseDTOs()
|
||||
.stream().map(this::releaseDtoToRelease).collect(Collectors.toList());
|
||||
application.setApplicationReleases(applicationReleases);
|
||||
return application;
|
||||
}
|
||||
|
||||
private ApplicationRelease releaseDtoToRelease(ApplicationReleaseDTO applicationReleaseDTO){
|
||||
String artifactDownloadEndpoint = ConfigurationManager.getInstance().getConfiguration()
|
||||
.getArtifactDownloadEndpoint();
|
||||
String basePath = artifactDownloadEndpoint + Constants.FORWARD_SLASH + applicationReleaseDTO.getUuid()
|
||||
+ Constants.FORWARD_SLASH;
|
||||
List<String> screenshotPaths = new ArrayList<>();
|
||||
ApplicationRelease applicationRelease = new ApplicationRelease();
|
||||
applicationRelease.setDescription(applicationReleaseDTO.getDescription());
|
||||
applicationRelease.setVersion(applicationReleaseDTO.getVersion());
|
||||
applicationRelease.setUuid(applicationReleaseDTO.getUuid());
|
||||
applicationRelease.setReleaseType(applicationReleaseDTO.getReleaseType());
|
||||
applicationRelease.setPrice(applicationReleaseDTO.getPrice());
|
||||
applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants());
|
||||
applicationRelease.setMetaData(applicationReleaseDTO.getMetaData());
|
||||
applicationRelease.setUrl(applicationReleaseDTO.getUrl());
|
||||
applicationRelease.setCurrentStatus(applicationReleaseDTO.getCurrentState());
|
||||
applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants());
|
||||
applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions());
|
||||
applicationRelease.setRating(applicationReleaseDTO.getRating());
|
||||
applicationRelease
|
||||
.setInstallerPath(basePath + applicationReleaseDTO.getInstallerName());
|
||||
applicationRelease.setIconPath(basePath + applicationReleaseDTO.getIconName());
|
||||
applicationRelease.setBannerPath(basePath + applicationReleaseDTO.getBannerName());
|
||||
|
||||
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) {
|
||||
screenshotPaths.add(basePath + applicationReleaseDTO.getScreenshotName1());
|
||||
}
|
||||
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName2())) {
|
||||
screenshotPaths.add(basePath + applicationReleaseDTO.getScreenshotName2());
|
||||
}
|
||||
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName3())) {
|
||||
screenshotPaths.add(basePath + applicationReleaseDTO.getScreenshotName3());
|
||||
}
|
||||
applicationRelease.setScreenshots(screenshotPaths);
|
||||
return applicationRelease;
|
||||
}
|
||||
|
||||
private <T> DeviceType getDeviceTypeData( T deviceTypeAttr)
|
||||
|
||||
@ -21,13 +21,22 @@ package org.wso2.carbon.device.application.mgt.core.util;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.validator.routines.UrlValidator;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
|
||||
import org.wso2.carbon.device.application.mgt.common.DeviceTypes;
|
||||
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
|
||||
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
|
||||
import org.wso2.carbon.device.application.mgt.common.response.Application;
|
||||
import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.*;
|
||||
import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppReleaseWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||
@ -212,11 +221,102 @@ public class APIUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> ApplicationDTO convertToAppDTO(T param)
|
||||
throws BadRequestException, UnexpectedServerErrorException {
|
||||
ApplicationDTO applicationDTO = new ApplicationDTO();
|
||||
|
||||
if (param instanceof ApplicationWrapper){
|
||||
ApplicationWrapper applicationWrapper = (ApplicationWrapper) param;
|
||||
DeviceType deviceType = getDeviceTypeData(applicationWrapper.getDeviceType());
|
||||
applicationDTO.setName(applicationWrapper.getName());
|
||||
applicationDTO.setDescription(applicationWrapper.getDescription());
|
||||
applicationDTO.setAppCategories(applicationWrapper.getAppCategories());
|
||||
applicationDTO.setType(ApplicationType.ENTERPRISE.toString());
|
||||
applicationDTO.setSubType(applicationWrapper.getSubType());
|
||||
applicationDTO.setPaymentCurrency(applicationWrapper.getPaymentCurrency());
|
||||
applicationDTO.setTags(applicationWrapper.getTags());
|
||||
applicationDTO.setUnrestrictedRoles(applicationWrapper.getUnrestrictedRoles());
|
||||
applicationDTO.setDeviceTypeId(deviceType.getId());
|
||||
List<ApplicationReleaseDTO> applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers()
|
||||
.stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList());
|
||||
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
|
||||
} else if (param instanceof WebAppWrapper){
|
||||
WebAppWrapper webAppWrapper = (WebAppWrapper) param;
|
||||
applicationDTO.setName(webAppWrapper.getName());
|
||||
applicationDTO.setDescription(webAppWrapper.getDescription());
|
||||
applicationDTO.setAppCategories(webAppWrapper.getCategories());
|
||||
applicationDTO.setSubType(webAppWrapper.getSubMethod());
|
||||
applicationDTO.setPaymentCurrency(webAppWrapper.getPaymentCurrency());
|
||||
applicationDTO.setType(webAppWrapper.getType());
|
||||
applicationDTO.setTags(webAppWrapper.getTags());
|
||||
applicationDTO.setUnrestrictedRoles(webAppWrapper.getUnrestrictedRoles());
|
||||
List<ApplicationReleaseDTO> applicationReleaseEntities = webAppWrapper.getWebAppReleaseWrappers()
|
||||
.stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList());
|
||||
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
|
||||
} else if (param instanceof PublicAppWrapper) {
|
||||
PublicAppWrapper publicAppWrapper = (PublicAppWrapper) param;
|
||||
DeviceType deviceType = getDeviceTypeData(publicAppWrapper.getDeviceType());
|
||||
applicationDTO.setName(publicAppWrapper.getName());
|
||||
applicationDTO.setDescription(publicAppWrapper.getDescription());
|
||||
applicationDTO.setAppCategories(publicAppWrapper.getCategories());
|
||||
applicationDTO.setType(ApplicationType.PUBLIC.toString());
|
||||
applicationDTO.setSubType(publicAppWrapper.getSubMethod());
|
||||
applicationDTO.setPaymentCurrency(publicAppWrapper.getPaymentCurrency());
|
||||
applicationDTO.setTags(publicAppWrapper.getTags());
|
||||
applicationDTO.setUnrestrictedRoles(publicAppWrapper.getUnrestrictedRoles());
|
||||
applicationDTO.setDeviceTypeId(deviceType.getId());
|
||||
List<ApplicationReleaseDTO> applicationReleaseEntities = publicAppWrapper.getPublicAppReleaseWrappers()
|
||||
.stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList());
|
||||
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
|
||||
}
|
||||
return applicationDTO;
|
||||
}
|
||||
|
||||
public static <T> ApplicationReleaseDTO releaseWrapperToReleaseDTO(T param){
|
||||
ApplicationReleaseDTO applicationReleaseDTO = new ApplicationReleaseDTO();
|
||||
if (param instanceof ApplicationReleaseWrapper){
|
||||
ApplicationReleaseWrapper applicationReleaseWrapper = (ApplicationReleaseWrapper) param;
|
||||
applicationReleaseDTO.setDescription(applicationReleaseWrapper.getDescription());
|
||||
applicationReleaseDTO.setReleaseType(applicationReleaseWrapper.getReleaseType());
|
||||
applicationReleaseDTO.setPrice(applicationReleaseWrapper.getPrice());
|
||||
applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseWrapper.getIsSharedWithAllTenants());
|
||||
applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData());
|
||||
applicationReleaseDTO.setSupportedOsVersions(applicationReleaseWrapper.getSupportedOsVersions());
|
||||
} else if (param instanceof WebAppReleaseWrapper){
|
||||
WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param;
|
||||
applicationReleaseDTO.setDescription(webAppReleaseWrapper.getDescription());
|
||||
applicationReleaseDTO.setReleaseType(webAppReleaseWrapper.getReleaseType());
|
||||
applicationReleaseDTO.setVersion(webAppReleaseWrapper.getVersion());
|
||||
applicationReleaseDTO.setPrice(webAppReleaseWrapper.getPrice());
|
||||
applicationReleaseDTO.setInstallerName(webAppReleaseWrapper.getUrl());
|
||||
applicationReleaseDTO.setIsSharedWithAllTenants(webAppReleaseWrapper.getIsSharedWithAllTenants());
|
||||
applicationReleaseDTO.setSupportedOsVersions(Constants.ANY);
|
||||
applicationReleaseDTO.setPackageName(Constants.DEFAULT_PCK_NAME);
|
||||
applicationReleaseDTO.setMetaData(webAppReleaseWrapper.getMetaData());
|
||||
} else if (param instanceof PublicAppReleaseWrapper) {
|
||||
PublicAppReleaseWrapper publicAppReleaseWrapper = (PublicAppReleaseWrapper) param;
|
||||
applicationReleaseDTO.setDescription(publicAppReleaseWrapper.getDescription());
|
||||
applicationReleaseDTO.setReleaseType(publicAppReleaseWrapper.getReleaseType());
|
||||
applicationReleaseDTO.setVersion(publicAppReleaseWrapper.getVersion());
|
||||
applicationReleaseDTO.setPackageName(publicAppReleaseWrapper.getPackageName());
|
||||
applicationReleaseDTO.setPrice(publicAppReleaseWrapper.getPrice());
|
||||
applicationReleaseDTO.setIsSharedWithAllTenants(publicAppReleaseWrapper.getIsSharedWithAllTenants());
|
||||
applicationReleaseDTO.setMetaData(publicAppReleaseWrapper.getMetaData());
|
||||
applicationReleaseDTO.setSupportedOsVersions(publicAppReleaseWrapper.getSupportedOsVersions());
|
||||
}
|
||||
return applicationReleaseDTO;
|
||||
}
|
||||
|
||||
public static Application appDtoToAppResponse(ApplicationDTO applicationDTO)
|
||||
throws BadRequestException, UnexpectedServerErrorException {
|
||||
|
||||
Application application = new Application();
|
||||
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
|
||||
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
||||
application.setDeviceType(deviceType.getName());
|
||||
} else {
|
||||
application.setDeviceType(Constants.ANY);
|
||||
}
|
||||
application.setId(applicationDTO.getId());
|
||||
application.setName(applicationDTO.getName());
|
||||
application.setDescription(applicationDTO.getDescription());
|
||||
@ -226,7 +326,6 @@ public class APIUtil {
|
||||
application.setPaymentCurrency(applicationDTO.getPaymentCurrency());
|
||||
application.setTags(applicationDTO.getTags());
|
||||
application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles());
|
||||
application.setDeviceType(deviceType.getName());
|
||||
application.setRating(applicationDTO.getAppRating());
|
||||
List<ApplicationRelease> applicationReleases = applicationDTO.getApplicationReleaseDTOs()
|
||||
.stream().map(APIUtil::releaseDtoToRelease).collect(Collectors.toList());
|
||||
@ -239,8 +338,11 @@ public class APIUtil {
|
||||
.getArtifactDownloadEndpoint();
|
||||
String basePath = artifactDownloadEndpoint + Constants.FORWARD_SLASH + applicationReleaseDTO.getUuid()
|
||||
+ Constants.FORWARD_SLASH;
|
||||
|
||||
List<String> screenshotPaths = new ArrayList<>();
|
||||
ApplicationRelease applicationRelease = new ApplicationRelease();
|
||||
UrlValidator urlValidator = new UrlValidator();
|
||||
|
||||
applicationRelease.setDescription(applicationReleaseDTO.getDescription());
|
||||
applicationRelease.setVersion(applicationReleaseDTO.getVersion());
|
||||
applicationRelease.setUuid(applicationReleaseDTO.getUuid());
|
||||
@ -248,16 +350,21 @@ public class APIUtil {
|
||||
applicationRelease.setPrice(applicationReleaseDTO.getPrice());
|
||||
applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants());
|
||||
applicationRelease.setMetaData(applicationReleaseDTO.getMetaData());
|
||||
applicationRelease.setUrl(applicationReleaseDTO.getUrl());
|
||||
applicationRelease.setCurrentStatus(applicationReleaseDTO.getCurrentState());
|
||||
applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants());
|
||||
applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions());
|
||||
applicationRelease.setRating(applicationReleaseDTO.getRating());
|
||||
applicationRelease
|
||||
.setInstallerPath(basePath + applicationReleaseDTO.getInstallerName());
|
||||
applicationRelease.setIconPath(basePath + applicationReleaseDTO.getIconName());
|
||||
applicationRelease.setBannerPath(basePath + applicationReleaseDTO.getBannerName());
|
||||
|
||||
if (urlValidator.isValid(applicationReleaseDTO.getInstallerName())){
|
||||
applicationRelease
|
||||
.setInstallerPath(applicationReleaseDTO.getInstallerName());
|
||||
} else {
|
||||
applicationRelease
|
||||
.setInstallerPath(basePath + applicationReleaseDTO.getInstallerName());
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) {
|
||||
screenshotPaths.add(basePath + applicationReleaseDTO.getScreenshotName1());
|
||||
}
|
||||
|
||||
@ -38,6 +38,11 @@ public class Constants {
|
||||
public static final String APP_EXTENSION = ".app";
|
||||
|
||||
public static final String FORWARD_SLASH = "/";
|
||||
public static final String ANY = "ANY";
|
||||
public static final String DEFAULT_PCK_NAME = "default.app.com";
|
||||
|
||||
public static final String GOOGLE_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=";
|
||||
public static final String APPLE_STORE_URL = "https://itunes.apple.com/country/app/app-name/id";
|
||||
|
||||
/**
|
||||
* Database types supported by Application Management.
|
||||
|
||||
@ -60,7 +60,6 @@ public class ApplicationManagementTest extends BaseTestCase {
|
||||
applicationWrapper.setDeviceType("android");
|
||||
applicationWrapper.setName("Test Application");
|
||||
applicationWrapper.setSubType("Test Sub type");
|
||||
applicationWrapper.setType("ENTERPRISE");
|
||||
|
||||
List<String> tags = new ArrayList<>();
|
||||
tags.add("abc");
|
||||
|
||||
@ -24,8 +24,10 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.json.JSONException;
|
||||
@ -60,6 +62,12 @@ public class HandlerUtil {
|
||||
} else if (httpMethod instanceof HttpGet) {
|
||||
HttpGet method = (HttpGet) httpMethod;
|
||||
response = client.execute(method);
|
||||
} else if (httpMethod instanceof HttpPut) {
|
||||
HttpPut method = (HttpPut) httpMethod;
|
||||
response = client.execute(method);
|
||||
} else if (httpMethod instanceof HttpDelete) {
|
||||
HttpDelete method = (HttpDelete) httpMethod;
|
||||
response = client.execute(method);
|
||||
}
|
||||
|
||||
ProxyResponse proxyResponse = new ProxyResponse();
|
||||
|
||||
@ -42,6 +42,8 @@ import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import javax.validation.Valid;
|
||||
@ -269,6 +271,7 @@ public interface ApplicationManagementPublisherAPI {
|
||||
);
|
||||
|
||||
@POST
|
||||
@Path("/ent-app")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes("multipart/mixed")
|
||||
@ApiOperation(
|
||||
@ -299,7 +302,7 @@ public interface ApplicationManagementPublisherAPI {
|
||||
message = "Internal Server Error. \n Error occurred while creating the application.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response createApplication(
|
||||
Response createEntApp(
|
||||
@ApiParam(
|
||||
name = "application",
|
||||
value = "The application that need to be created.",
|
||||
@ -338,9 +341,137 @@ public interface ApplicationManagementPublisherAPI {
|
||||
);
|
||||
|
||||
@POST
|
||||
@Path("/web-app")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes("multipart/mixed")
|
||||
@Path("/{appType}/{appId}")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Create an web app",
|
||||
notes = "This will create a new web app",
|
||||
tags = "Application Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "OK. \n Successfully created a web application.",
|
||||
response = ApplicationDTO.class),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n " +
|
||||
"Web app creating payload contains unacceptable or vulnerable data"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while creating the web app.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response createWebApp(
|
||||
@ApiParam(
|
||||
name = "webapp",
|
||||
value = "The web app that need to be created.",
|
||||
required = true)
|
||||
@Multipart("webapp") 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",
|
||||
required = true)
|
||||
@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
|
||||
@Path("/public-app")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes("multipart/mixed")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Create an public app",
|
||||
notes = "This will create a new public app",
|
||||
tags = "Application Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:app:publisher:update")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "OK. \n Successfully created a public app.",
|
||||
response = ApplicationDTO.class),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n " +
|
||||
"public app creating payload contains unacceptable or vulnerable data"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while creating the public app.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response createPubApp(
|
||||
@ApiParam(
|
||||
name = "public-app",
|
||||
value = "The public app that need to be created.",
|
||||
required = true)
|
||||
@Multipart("public-app") 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",
|
||||
required = true)
|
||||
@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
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes("multipart/mixed")
|
||||
@Path("/ent-app/{appId}")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
@ -369,12 +500,7 @@ public interface ApplicationManagementPublisherAPI {
|
||||
message = "Internal Server Error. \n Error occurred while creating the application.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response createRelease(
|
||||
@ApiParam(
|
||||
name = "appType",
|
||||
value = "Application Type.",
|
||||
required = true)
|
||||
@PathParam("appType") String appType,
|
||||
Response createEntAppRelease(
|
||||
@ApiParam(
|
||||
name = "appId",
|
||||
value = "Id of the application.",
|
||||
|
||||
@ -32,6 +32,8 @@ import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.PublicAppWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||
@ -167,7 +169,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
|
||||
@POST
|
||||
@Consumes("multipart/mixed")
|
||||
public Response createApplication(
|
||||
@Path("/ent-app")
|
||||
public Response createEntApp(
|
||||
@Multipart("application") ApplicationWrapper applicationWrapper,
|
||||
@Multipart("binaryFile") Attachment binaryFile,
|
||||
@Multipart("icon") Attachment iconFile,
|
||||
@ -179,9 +182,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
|
||||
try {
|
||||
applicationManager.validateAppCreatingRequest(applicationWrapper);
|
||||
applicationManager.validateReleaseCreatingRequest(applicationWrapper.getApplicationReleaseWrappers().get(0),
|
||||
applicationWrapper.getType());
|
||||
applicationManager.validateBinaryArtifact(binaryFile, applicationWrapper.getType());
|
||||
applicationManager.validateReleaseCreatingRequest(applicationWrapper.getApplicationReleaseWrappers().get(0));
|
||||
applicationManager.validateBinaryArtifact(binaryFile);
|
||||
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
|
||||
|
||||
// Created new application entry
|
||||
@ -207,9 +209,84 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
|
||||
@POST
|
||||
@Consumes("multipart/mixed")
|
||||
@Path("/{appType}/{appId}")
|
||||
public Response createRelease(
|
||||
@PathParam("appType") String appType,
|
||||
@Path("/web-app")
|
||||
public Response createWebApp(
|
||||
@Multipart("webapp") WebAppWrapper webAppWrapper,
|
||||
@Multipart("icon") Attachment iconFile,
|
||||
@Multipart("banner") 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 {
|
||||
applicationManager.validateAppCreatingRequest(webAppWrapper);
|
||||
applicationManager.validateReleaseCreatingRequest(webAppWrapper.getWebAppReleaseWrappers().get(0));
|
||||
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
|
||||
|
||||
// Created new application entry
|
||||
Application application = applicationManager.createWebClip(webAppWrapper,
|
||||
constructApplicationArtifact(null, iconFile, bannerFile, attachmentList));
|
||||
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 (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while creating the web application";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (RequestValidatingException e) {
|
||||
String msg = "Error occurred while handling the web app creating request";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes("multipart/mixed")
|
||||
@Path("/public-app")
|
||||
public Response createPubApp(
|
||||
@Multipart("public-app") PublicAppWrapper publicAppWrapper,
|
||||
@Multipart("icon") Attachment iconFile,
|
||||
@Multipart("banner") 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 {
|
||||
applicationManager.validateAppCreatingRequest(publicAppWrapper);
|
||||
applicationManager.validateReleaseCreatingRequest(publicAppWrapper.getPublicAppReleaseWrappers().get(0));
|
||||
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
|
||||
|
||||
// Created new application entry
|
||||
Application application = applicationManager.createPublicApp(publicAppWrapper,
|
||||
constructApplicationArtifact(null, iconFile, bannerFile, attachmentList));
|
||||
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 (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while creating the public app.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (RequestValidatingException e) {
|
||||
String msg = "Error occurred while handling the public app creating request";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes("multipart/mixed")
|
||||
@Path("/ent-app/{appId}")
|
||||
public Response createEntAppRelease(
|
||||
@PathParam("appId") int appId,
|
||||
@Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper,
|
||||
@Multipart("binaryFile") Attachment binaryFile,
|
||||
@ -221,8 +298,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
|
||||
try {
|
||||
applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper, appType);
|
||||
applicationManager.validateBinaryArtifact(binaryFile, appType);
|
||||
applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper);
|
||||
applicationManager.validateBinaryArtifact(binaryFile);
|
||||
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
|
||||
|
||||
// Created new application release
|
||||
@ -301,7 +378,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
}
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
applicationManager.validateBinaryArtifact(binaryFile, appType);
|
||||
//todo check again
|
||||
applicationManager.validateBinaryArtifact(binaryFile);
|
||||
applicationManager.updateApplicationArtifact(deviceType, appType, applicationReleaseUuid,
|
||||
constructApplicationArtifact(binaryFile, null, null, null));
|
||||
return Response.status(Response.Status.OK)
|
||||
@ -364,7 +442,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
|
||||
try {
|
||||
applicationManager.validateBinaryArtifact(binaryFile, appType);
|
||||
//todo check again
|
||||
applicationManager.validateBinaryArtifact(binaryFile);
|
||||
applicationManager.validateImageArtifacts(iconFile, bannerFile, screenshots);
|
||||
if (!applicationManager.updateRelease(deviceType, appType, applicationUUID, applicationReleaseWrapper,
|
||||
constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user