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
feature/appm-store/pbac
Dharmakeerthi Lasantha 5 years ago
commit 4829d69733

@ -23,6 +23,6 @@ package org.wso2.carbon.device.application.mgt.common;
* Application Types. * Application Types.
*/ */
public enum ApplicationType { public enum ApplicationType {
ENTERPRISE, PUBLIC, WEB, WEB_CLIP ENTERPRISE, PUBLIC, WEB_APP, WEB_CLIP
} }

@ -81,10 +81,6 @@ public class ApplicationRelease {
required = true) required = true)
private String metaData; private String metaData;
@ApiModelProperty(name = "url",
value = "URL which is used for WEB-CLIP")
private String url;
@ApiModelProperty(name = "supportedOsVersions", @ApiModelProperty(name = "supportedOsVersions",
value = "ApplicationDTO release supported OS versions") value = "ApplicationDTO release supported OS versions")
private String supportedOsVersions; private String supportedOsVersions;
@ -125,14 +121,6 @@ public class ApplicationRelease {
return metaData; return metaData;
} }
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDescription() { return description; } public String getDescription() { return description; }
public void setDescription(String description) { this.description = 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.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; 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.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 java.util.List;
@ -53,6 +55,12 @@ public interface ApplicationManager {
Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact) Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException, RequestValidatingException; throws ApplicationManagementException, RequestValidatingException;
Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException;
Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException;
/** /**
* Updates an already existing application. * Updates an already existing application.
* *
@ -203,19 +211,14 @@ public interface ApplicationManager {
/*** /***
* To validate the application creating request * 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. * @throws RequestValidatingException throws if payload does not satisfy requrements.
*/ */
void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, String applicationType) <T> void validateReleaseCreatingRequest(T param) throws ApplicationManagementException;
throws RequestValidatingException;
/*** /***
* *
@ -227,7 +230,7 @@ public interface ApplicationManager {
void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List<Attachment> attachmentList) void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List<Attachment> attachmentList)
throws RequestValidatingException; throws RequestValidatingException;
void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException; void validateBinaryArtifact(Attachment binaryFile) throws RequestValidatingException;
void addAplicationCategories(List<String> categories) throws ApplicationManagementException; 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.ApiModel;
import io.swagger.annotations.ApiModelProperty; 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") @ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store")
public class ApplicationReleaseWrapper { public class ApplicationReleaseWrapper {
@ApiModelProperty(name = "description", @ApiModelProperty(name = "description",
value = "Description of the application release") value = "Description of the application release")
@NotNull
private String description; private String description;
@ApiModelProperty(name = "releaseType", @ApiModelProperty(name = "releaseType",
value = "Release type of the application release", value = "Release type of the application release",
required = true, required = true,
example = "alpha, beta etc") example = "alpha, beta etc")
@NotNull
private String releaseType; private String releaseType;
@ApiModelProperty(name = "price", @ApiModelProperty(name = "price",
value = "Price of the application release", value = "Price of the application release",
required = true) required = true)
@NotNull
private Double price; private Double price;
@ApiModelProperty(name = "isSharedWithAllTenants", @ApiModelProperty(name = "isSharedWithAllTenants",
value = "If application release is shared with all tenants it is eqal to 1 otherwise 0", value = "If application release is shared with all tenants it is eqal to 1 otherwise 0",
required = true) required = true)
@NotNull
private boolean isSharedWithAllTenants; private boolean isSharedWithAllTenants;
@ApiModelProperty(name = "metaData", @ApiModelProperty(name = "metaData",
@ -47,12 +53,9 @@ public class ApplicationReleaseWrapper {
required = true) required = true)
private String metaData; private String metaData;
@ApiModelProperty(name = "url",
value = "URL which is used for WEB-CLIP")
private String url;
@ApiModelProperty(name = "supportedOsVersions", @ApiModelProperty(name = "supportedOsVersions",
value = "ApplicationDTO release supported OS versions") value = "ApplicationDTO release supported OS versions")
@NotNull
private String supportedOsVersions; private String supportedOsVersions;
public String getReleaseType() { public String getReleaseType() {
@ -87,14 +90,6 @@ public class ApplicationReleaseWrapper {
return metaData; return metaData;
} }
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDescription() { return description; } public String getDescription() { return description; }
public void setDescription(String description) { this.description = 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.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
@ApiModel(value = "ApplicationWrapper", description = "ApplicationWrapper represents the an ApplicationDTO in ApplicationDTO Store") @ApiModel(value = "ApplicationWrapper", description = "ApplicationWrapper represents the an ApplicationDTO in ApplicationDTO Store")
@ -28,29 +29,28 @@ public class ApplicationWrapper {
@ApiModelProperty(name = "name", @ApiModelProperty(name = "name",
value = "Name of the application", value = "Name of the application",
required = true) required = true)
@NotNull
private String name; private String name;
@ApiModelProperty(name = "description", @ApiModelProperty(name = "description",
value = "Description of the application", value = "Description of the application",
required = true) required = true)
@NotNull
private String description; private String description;
@ApiModelProperty(name = "appCategories", @ApiModelProperty(name = "appCategories",
value = "CategoryDTO of the application", value = "CategoryDTO of the application",
required = true, required = true,
example = "Educational, Gaming, Travel, Entertainment etc") example = "Educational, Gaming, Travel, Entertainment etc")
@NotNull
private List<String> appCategories; 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", @ApiModelProperty(name = "subType",
value = "Subscription type of the application", value = "Subscription type of the application",
required = true, required = true,
example = "PAID, FREE") example = "PAID, FREE")
@NotNull
private String subType; private String subType;
@ApiModelProperty(name = "paymentCurrency", @ApiModelProperty(name = "paymentCurrency",
@ -61,21 +61,25 @@ public class ApplicationWrapper {
@ApiModelProperty(name = "tags", @ApiModelProperty(name = "tags",
value = "List of application tags") value = "List of application tags")
@NotNull
private List<String> tags; private List<String> tags;
@ApiModelProperty(name = "unrestrictedRoles", @ApiModelProperty(name = "unrestrictedRoles",
value = "List of roles that users should have to access the application") value = "List of roles that users should have to access the application")
@NotNull
private List<String> unrestrictedRoles; private List<String> unrestrictedRoles;
@ApiModelProperty(name = "deviceType", @ApiModelProperty(name = "deviceType",
value = "Related device type of the application", value = "Related device type of the application",
required = true, required = true,
example = "IoS, Android, Arduino, RaspberryPi etc") example = "IoS, Android, Arduino, RaspberryPi etc")
@NotNull
private String deviceType; private String deviceType;
@ApiModelProperty(name = "applicationReleaseWrappers", @ApiModelProperty(name = "applicationReleaseWrappers",
value = "List of application releases", value = "List of application releases",
required = true) required = true)
@NotNull
private List<ApplicationReleaseWrapper> applicationReleaseWrappers; private List<ApplicationReleaseWrapper> applicationReleaseWrappers;
@ -95,10 +99,6 @@ public class ApplicationWrapper {
public void setTags(List<String> tags) { this.tags = tags; } 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 String getSubType() { return subType; }
public void setSubType(String subType) { this.subType = 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<CategoryDTO> getAllCategories(int tenantId) throws ApplicationManagementDAOException;
List<Integer> getCategoryIdsForCategoryNames(List<String> CatgeoryNames, int tenantId)
throws ApplicationManagementDAOException;
List<Integer> getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException; List<Integer> getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException;
CategoryDTO getCategoryForCategoryName(String categoryName, int tenantId) 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 @Override
public List<Integer> getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException { public List<Integer> getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -994,7 +1028,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
Connection conn; Connection conn;
String sql = "UPDATE " + String sql = "UPDATE " +
"AP_APP_CATEGORY cat " + "AP_APP_CATEGORY cat " +
"SET cat.CATEGORY_NAME = ? " + "SET cat.CATEGORY = ? " +
"WHERE " + "WHERE " +
"cat.ID = ? AND " + "cat.ID = ? AND " +
"cat.TENANT_ID = ?"; "cat.TENANT_ID = ?";
@ -1002,8 +1036,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
conn = this.getDBConnection(); conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, categoryDTO.getCategoryName()); stmt.setString(1, categoryDTO.getCategoryName());
stmt.setInt(1, categoryDTO.getId()); stmt.setInt(2, categoryDTO.getId());
stmt.setInt(2, tenantId); stmt.setInt(3, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {

@ -549,7 +549,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
sql += "GROUP_NAME = ? "; 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)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();

@ -21,13 +21,22 @@ package org.wso2.carbon.device.application.mgt.core.util;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.validator.routines.UrlValidator;
import org.wso2.carbon.context.PrivilegedCarbonContext; 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.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; 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.Application;
import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease; 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.services.*;
import org.wso2.carbon.device.application.mgt.common.ErrorResponse; 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.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; 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) public static Application appDtoToAppResponse(ApplicationDTO applicationDTO)
throws BadRequestException, UnexpectedServerErrorException { throws BadRequestException, UnexpectedServerErrorException {
Application application = new Application(); Application application = new Application();
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); 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.setId(applicationDTO.getId());
application.setName(applicationDTO.getName()); application.setName(applicationDTO.getName());
application.setDescription(applicationDTO.getDescription()); application.setDescription(applicationDTO.getDescription());
@ -226,7 +326,6 @@ public class APIUtil {
application.setPaymentCurrency(applicationDTO.getPaymentCurrency()); application.setPaymentCurrency(applicationDTO.getPaymentCurrency());
application.setTags(applicationDTO.getTags()); application.setTags(applicationDTO.getTags());
application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles()); application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles());
application.setDeviceType(deviceType.getName());
application.setRating(applicationDTO.getAppRating()); application.setRating(applicationDTO.getAppRating());
List<ApplicationRelease> applicationReleases = applicationDTO.getApplicationReleaseDTOs() List<ApplicationRelease> applicationReleases = applicationDTO.getApplicationReleaseDTOs()
.stream().map(APIUtil::releaseDtoToRelease).collect(Collectors.toList()); .stream().map(APIUtil::releaseDtoToRelease).collect(Collectors.toList());
@ -239,8 +338,11 @@ public class APIUtil {
.getArtifactDownloadEndpoint(); .getArtifactDownloadEndpoint();
String basePath = artifactDownloadEndpoint + Constants.FORWARD_SLASH + applicationReleaseDTO.getUuid() String basePath = artifactDownloadEndpoint + Constants.FORWARD_SLASH + applicationReleaseDTO.getUuid()
+ Constants.FORWARD_SLASH; + Constants.FORWARD_SLASH;
List<String> screenshotPaths = new ArrayList<>(); List<String> screenshotPaths = new ArrayList<>();
ApplicationRelease applicationRelease = new ApplicationRelease(); ApplicationRelease applicationRelease = new ApplicationRelease();
UrlValidator urlValidator = new UrlValidator();
applicationRelease.setDescription(applicationReleaseDTO.getDescription()); applicationRelease.setDescription(applicationReleaseDTO.getDescription());
applicationRelease.setVersion(applicationReleaseDTO.getVersion()); applicationRelease.setVersion(applicationReleaseDTO.getVersion());
applicationRelease.setUuid(applicationReleaseDTO.getUuid()); applicationRelease.setUuid(applicationReleaseDTO.getUuid());
@ -248,16 +350,21 @@ public class APIUtil {
applicationRelease.setPrice(applicationReleaseDTO.getPrice()); applicationRelease.setPrice(applicationReleaseDTO.getPrice());
applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants());
applicationRelease.setMetaData(applicationReleaseDTO.getMetaData()); applicationRelease.setMetaData(applicationReleaseDTO.getMetaData());
applicationRelease.setUrl(applicationReleaseDTO.getUrl());
applicationRelease.setCurrentStatus(applicationReleaseDTO.getCurrentState()); applicationRelease.setCurrentStatus(applicationReleaseDTO.getCurrentState());
applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants());
applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions()); applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions());
applicationRelease.setRating(applicationReleaseDTO.getRating()); applicationRelease.setRating(applicationReleaseDTO.getRating());
applicationRelease
.setInstallerPath(basePath + applicationReleaseDTO.getInstallerName());
applicationRelease.setIconPath(basePath + applicationReleaseDTO.getIconName()); applicationRelease.setIconPath(basePath + applicationReleaseDTO.getIconName());
applicationRelease.setBannerPath(basePath + applicationReleaseDTO.getBannerName()); 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())) { if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) {
screenshotPaths.add(basePath + 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 APP_EXTENSION = ".app";
public static final String FORWARD_SLASH = "/"; 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. * Database types supported by Application Management.

@ -60,7 +60,6 @@ public class ApplicationManagementTest extends BaseTestCase {
applicationWrapper.setDeviceType("android"); applicationWrapper.setDeviceType("android");
applicationWrapper.setName("Test Application"); applicationWrapper.setName("Test Application");
applicationWrapper.setSubType("Test Sub type"); applicationWrapper.setSubType("Test Sub type");
applicationWrapper.setType("ENTERPRISE");
List<String> tags = new ArrayList<>(); List<String> tags = new ArrayList<>();
tags.add("abc"); tags.add("abc");

@ -24,8 +24,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus; 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.HttpGet;
import org.apache.http.client.methods.HttpPost; 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.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.json.JSONException; import org.json.JSONException;
@ -60,6 +62,12 @@ public class HandlerUtil {
} else if (httpMethod instanceof HttpGet) { } else if (httpMethod instanceof HttpGet) {
HttpGet method = (HttpGet) httpMethod; HttpGet method = (HttpGet) httpMethod;
response = client.execute(method); 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(); 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.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; 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.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 java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
@ -269,6 +271,7 @@ public interface ApplicationManagementPublisherAPI {
); );
@POST @POST
@Path("/ent-app")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes("multipart/mixed") @Consumes("multipart/mixed")
@ApiOperation( @ApiOperation(
@ -299,7 +302,7 @@ public interface ApplicationManagementPublisherAPI {
message = "Internal Server Error. \n Error occurred while creating the application.", message = "Internal Server Error. \n Error occurred while creating the application.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response createApplication( Response createEntApp(
@ApiParam( @ApiParam(
name = "application", name = "application",
value = "The application that need to be created.", value = "The application that need to be created.",
@ -338,9 +341,137 @@ public interface ApplicationManagementPublisherAPI {
); );
@POST @POST
@Path("/web-app")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes("multipart/mixed") @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( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = 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.", message = "Internal Server Error. \n Error occurred while creating the application.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response createRelease( Response createEntAppRelease(
@ApiParam(
name = "appType",
value = "Application Type.",
required = true)
@PathParam("appType") String appType,
@ApiParam( @ApiParam(
name = "appId", name = "appId",
value = "Id of the application.", 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.ApplicationReleaseWrapper;
import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; 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.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.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
@ -167,7 +169,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@POST @POST
@Consumes("multipart/mixed") @Consumes("multipart/mixed")
public Response createApplication( @Path("/ent-app")
public Response createEntApp(
@Multipart("application") ApplicationWrapper applicationWrapper, @Multipart("application") ApplicationWrapper applicationWrapper,
@Multipart("binaryFile") Attachment binaryFile, @Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile, @Multipart("icon") Attachment iconFile,
@ -179,9 +182,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
applicationManager.validateAppCreatingRequest(applicationWrapper); applicationManager.validateAppCreatingRequest(applicationWrapper);
applicationManager.validateReleaseCreatingRequest(applicationWrapper.getApplicationReleaseWrappers().get(0), applicationManager.validateReleaseCreatingRequest(applicationWrapper.getApplicationReleaseWrappers().get(0));
applicationWrapper.getType()); applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateBinaryArtifact(binaryFile, applicationWrapper.getType());
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new application entry // Created new application entry
@ -207,9 +209,84 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@POST @POST
@Consumes("multipart/mixed") @Consumes("multipart/mixed")
@Path("/{appType}/{appId}") @Path("/web-app")
public Response createRelease( public Response createWebApp(
@PathParam("appType") String appType, @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, @PathParam("appId") int appId,
@Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper, @Multipart("applicationRelease") ApplicationReleaseWrapper applicationReleaseWrapper,
@Multipart("binaryFile") Attachment binaryFile, @Multipart("binaryFile") Attachment binaryFile,
@ -221,8 +298,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper, appType); applicationManager.validateReleaseCreatingRequest(applicationReleaseWrapper);
applicationManager.validateBinaryArtifact(binaryFile, appType); applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList);
// Created new application release // Created new application release
@ -301,7 +378,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} }
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
applicationManager.validateBinaryArtifact(binaryFile, appType); //todo check again
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.updateApplicationArtifact(deviceType, appType, applicationReleaseUuid, applicationManager.updateApplicationArtifact(deviceType, appType, applicationReleaseUuid,
constructApplicationArtifact(binaryFile, null, null, null)); constructApplicationArtifact(binaryFile, null, null, null));
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)
@ -364,7 +442,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
applicationManager.validateBinaryArtifact(binaryFile, appType); //todo check again
applicationManager.validateBinaryArtifact(binaryFile);
applicationManager.validateImageArtifacts(iconFile, bannerFile, screenshots); applicationManager.validateImageArtifacts(iconFile, bannerFile, screenshots);
if (!applicationManager.updateRelease(deviceType, appType, applicationUUID, applicationReleaseWrapper, if (!applicationManager.updateRelease(deviceType, appType, applicationUUID, applicationReleaseWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) { constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) {

Loading…
Cancel
Save