Sync with master

add_scope_mdm
Rajitha Kumara 7 months ago
commit d1661e3f6d

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>grafana-mgt</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>grafana-mgt</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>grafana-mgt</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>analytics-mgt</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -22,7 +22,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -21,7 +21,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>application-mgt</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -0,0 +1,52 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
import java.io.InputStream;
public class ChunkDescriptor {
private FileDescriptor associateFileDescriptor;
private long size;
private InputStream chunk;
public FileDescriptor getAssociateFileDescriptor() {
return associateFileDescriptor;
}
public void setAssociateFileDescriptor(FileDescriptor associateFileDescriptor) {
this.associateFileDescriptor = associateFileDescriptor;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
public InputStream getChunk() {
return chunk;
}
public void setChunk(InputStream chunk) {
this.chunk = chunk;
}
}

@ -0,0 +1,79 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
import java.io.InputStream;
public class FileDescriptor {
private String fileName;
private String extension;
private String fullQualifiedName;
private String absolutePath;
private long actualFileSize;
private InputStream file;
public InputStream getFile() {
return file;
}
public void setFile(InputStream file) {
this.file = file;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getExtension() {
return extension;
}
public void setExtension(String extension) {
this.extension = extension;
}
public String getAbsolutePath() {
return absolutePath;
}
public void setAbsolutePath(String absolutePath) {
this.absolutePath = absolutePath;
}
public long getActualFileSize() {
return actualFileSize;
}
public void setActualFileSize(long actualFileSize) {
this.actualFileSize = actualFileSize;
}
public String getFullQualifiedName() {
return fullQualifiedName;
}
public void setFullQualifiedName(String fullQualifiedName) {
this.fullQualifiedName = fullQualifiedName;
}
}

@ -0,0 +1,60 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
public class FileMetaEntry {
private String fileName;
private String extension;
private long size;
private String absolutePath;
public String getAbsolutePath() {
return absolutePath;
}
public void setAbsolutePath(String absolutePath) {
this.absolutePath = absolutePath;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getExtension() {
return extension;
}
public void setExtension(String extension) {
this.extension = extension;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
}

@ -0,0 +1,108 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
import java.util.Objects;
public class TransferLink {
private static final String SCHEMA_SEPARATOR = "://";
private static final String URL_SEPARATOR = "/";
private static final String COLON = ":";
private final String schema;
private final String host;
private final String port;
private final String endpoint;
private final String artifactHolderUUID;
private TransferLink(String schema, String host, String port, String endpoint, String artifactHolderUUID) {
this.schema = schema;
this.host = host;
this.port = port;
this.endpoint = endpoint;
this.artifactHolderUUID = artifactHolderUUID;
}
public String getDirectTransferLink() {
return schema + SCHEMA_SEPARATOR + host + COLON + port + URL_SEPARATOR + endpoint + URL_SEPARATOR + artifactHolderUUID;
}
public String getRelativeTransferLink() {
return endpoint + URL_SEPARATOR + artifactHolderUUID;
}
@Override
public String toString() {
return getDirectTransferLink();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TransferLink that = (TransferLink) o;
return Objects.equals(schema, that.schema) && Objects.equals(host, that.host) && Objects.equals(port, that.port)
&& Objects.equals(endpoint, that.endpoint) && Objects.equals(artifactHolderUUID, that.artifactHolderUUID);
}
@Override
public int hashCode() {
return Objects.hash(schema, host, port, endpoint, artifactHolderUUID);
}
public static class TransferLinkBuilder {
private static final String DEFAULT_SCHEMA = "https";
private static final String ENDPOINT = "application-mgt-publisher/v1.0/applications/uploads";
private static final String IOT_GW_HOST_ENV_VAR = "iot.gateway.host";
private static final String IOT_GW_HTTPS_PORT_ENV_VAR = "iot.gateway.https.port";
private static final String IOT_GW_HTTP_PORT_ENV_VAR = "iot.gateway.http.port";
private String schema;
private String endpoint;
private final String artifactHolderUUID;
public TransferLinkBuilder(String artifactHolderUUID) {
this.schema = DEFAULT_SCHEMA;
this.endpoint = ENDPOINT;
this.artifactHolderUUID = artifactHolderUUID;
}
public TransferLinkBuilder withSchema(String schema) {
this.schema = schema;
return this;
}
public TransferLinkBuilder withEndpoint(String endpoint) {
this.endpoint = endpoint;
return this;
}
public TransferLink build() {
return new TransferLink(this.schema, resolveHost(), resolvePort(), this.endpoint, this.artifactHolderUUID);
}
private String resolveHost() {
return System.getProperty(IOT_GW_HOST_ENV_VAR);
}
private String resolvePort() {
return Objects.equals(this.schema, DEFAULT_SCHEMA) ? System.getProperty(IOT_GW_HTTPS_PORT_ENV_VAR)
: System.getProperty(IOT_GW_HTTP_PORT_ENV_VAR);
}
}
}

@ -0,0 +1,30 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common.exception;
public class FileDownloaderServiceException extends Exception {
public FileDownloaderServiceException(String msg) {
super(msg);
}
public FileDownloaderServiceException(String msg, Throwable t) {
super(msg, t);
}
}

@ -0,0 +1,31 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common.exception;
public class FileTransferServiceException extends Exception {
public FileTransferServiceException(String msg) {
super(msg);
}
public FileTransferServiceException(String msg, Throwable throwable) {
super(msg, throwable);
}
}

@ -372,11 +372,9 @@ public interface ApplicationManager {
*
* @param releaseUuid UUID of the application release.
* @param entAppReleaseWrapper {@link ApplicationReleaseDTO}
* @param applicationArtifact {@link ApplicationArtifact}
* @return If the application release is updated correctly True returns, otherwise retuen False
*/
ApplicationRelease updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
ApplicationRelease updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper) throws ApplicationManagementException;
/**
@ -384,33 +382,27 @@ public interface ApplicationManager {
*
* @param releaseUuid UUID of the application release.
* @param publicAppReleaseWrapper {@link ApplicationReleaseDTO}
* @param applicationArtifact {@link ApplicationArtifact}
* @return If the application release is updated correctly True returns, otherwise retuen False
*/
ApplicationRelease updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
ApplicationRelease updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper) throws ApplicationManagementException;
/**
* Use to update existing web app release
*
* @param releaseUuid UUID of the application release.
* @param webAppReleaseWrapper {@link ApplicationReleaseDTO}
* @param applicationArtifact {@link ApplicationArtifact}
* @return If the application release is updated correctly True returns, otherwise retuen False
*/
ApplicationRelease updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
ApplicationRelease updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper) throws ApplicationManagementException;
/**
* Use to update existing custom app release
*
* @param releaseUuid UUID of the application release.
* @param customAppReleaseWrapper {@link ApplicationReleaseDTO}
* @param applicationArtifact {@link ApplicationArtifact}
* @return If the application release is updated correctly True returns, otherwise retuen False
*/
ApplicationRelease updateCustomAppRelease(String releaseUuid, CustomAppReleaseWrapper customAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
ApplicationRelease updateCustomAppRelease(String releaseUuid, CustomAppReleaseWrapper customAppReleaseWrapper) throws ApplicationManagementException;
/**
* To validate the application creating request
@ -547,4 +539,13 @@ public interface ApplicationManager {
*/
void updateAppIconInfo(ApplicationRelease applicationRelease, String oldPackageName)
throws ApplicationManagementException;
/**
* Delete all application related data of a tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementException thrown if an error occurs when deleting data
*/
void deleteApplicationDataOfTenant(int tenantId) throws ApplicationManagementException;
void deleteApplicationDataByTenantDomain(String tenantDomain) throws ApplicationManagementException;
}

@ -132,4 +132,12 @@ public interface ApplicationStorageManager {
* @throws StorageManagementException if errors while generating md5 string
*/
String getMD5(InputStream inputStream) throws StorageManagementException;
/**
* Delete the folder containing all the app releases of a tenant
*
* @param tenantId Tenant ID
* @throws ApplicationStorageManagementException thrown if
*/
void deleteAppFolderOfTenant(int tenantId) throws ApplicationStorageManagementException;
}

@ -0,0 +1,29 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common.services;
import io.entgra.device.mgt.core.application.mgt.common.FileDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.exception.FileDownloaderServiceException;
import java.net.URL;
public interface FileDownloaderService {
FileDescriptor download(URL downloadUrl) throws FileDownloaderServiceException;
}

@ -0,0 +1,73 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common.services;
import io.entgra.device.mgt.core.application.mgt.common.ChunkDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.FileDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.FileMetaEntry;
import io.entgra.device.mgt.core.application.mgt.common.TransferLink;
import io.entgra.device.mgt.core.application.mgt.common.exception.FileTransferServiceException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.NotFoundException;
import java.io.InputStream;
import java.net.URL;
public interface FileTransferService {
/**
* Create an upload link
* @param fileMetaEntry {@link FileMetaEntry}
* @return {@link TransferLink}
* @throws FileTransferServiceException Throws when error encountered while generating upload link
*/
TransferLink generateUploadLink(FileMetaEntry fileMetaEntry) throws FileTransferServiceException;
/**
* Resolve {@link ChunkDescriptor} using artifactHolder UUID and a given chunk
* @param artifactHolder Artifact holder's UUID string
* @param chunk Data chunk
* @return {@link ChunkDescriptor}
* @throws FileTransferServiceException Throws when error encountered while resolving chunk descriptor
* @throws NotFoundException Throws when artifact holder not exists in the file system
*/
ChunkDescriptor resolve(String artifactHolder, InputStream chunk) throws FileTransferServiceException, NotFoundException;
/**
* Write chunk of data
* @param chunkDescriptor {@link ChunkDescriptor}
* @throws FileTransferServiceException Throws when error encountered while writing chunk
*/
void writeChunk(ChunkDescriptor chunkDescriptor) throws FileTransferServiceException;
/**
* Check if the provided download url point to a file which exists on the local env or not
* @param downloadUrl Download URL
* @return Returns true if the download URL point to a file which resides in local
* @throws FileTransferServiceException Throws when error encountered while checking
*/
boolean isExistsOnLocal(URL downloadUrl) throws FileTransferServiceException;
/**
* Resolve {@link FileDescriptor} from a given download URL
* @param downloadUrl Download URL
* @return {@link java.io.FileDescriptor}
* @throws FileTransferServiceException Throws when error encountered while resolving file descriptor
*/
FileDescriptor resolve(URL downloadUrl) throws FileTransferServiceException;
}

@ -83,6 +83,44 @@ public class CustomAppReleaseWrapper {
@ApiModelProperty(name = "icon",
value = "banner of the application")
private Base64File banner;
private boolean remoteStatus;
public boolean isRemoteStatus() {
return remoteStatus;
}
public void setRemoteStatus(boolean remoteStatus) {
this.remoteStatus = remoteStatus;
}
private String artifactLink;
private List<String> screenshotLinks;
private String iconLink;
private String bannerLink;
public String getArtifactLink() {
return artifactLink;
}
public void setArtifactLink(String artifactLink) {
this.artifactLink = artifactLink;
}
public List<String> getScreenshotLinks() {
return screenshotLinks;
}
public void setScreenshotLinks(List<String> screenshotLinks) {
this.screenshotLinks = screenshotLinks;
}
public String getIconLink() {
return iconLink;
}
public void setIconLink(String iconLink) {
this.iconLink = iconLink;
}
public String getReleaseType() {
return releaseType;
@ -173,4 +211,12 @@ public class CustomAppReleaseWrapper {
public void setBanner(Base64File banner) {
this.banner = banner;
}
public String getBannerLink() {
return bannerLink;
}
public void setBannerLink(String bannerLink) {
this.bannerLink = bannerLink;
}
}

@ -86,6 +86,44 @@ public class EntAppReleaseWrapper {
@ApiModelProperty(name = "icon",
value = "banner of the application")
private Base64File banner;
private boolean remoteStatus;
public boolean isRemoteStatus() {
return remoteStatus;
}
public void setRemoteStatus(boolean remoteStatus) {
this.remoteStatus = remoteStatus;
}
private String artifactLink;
private List<String> screenshotLinks;
private String iconLink;
private String bannerLink;
public String getArtifactLink() {
return artifactLink;
}
public void setArtifactLink(String artifactLink) {
this.artifactLink = artifactLink;
}
public List<String> getScreenshotLinks() {
return screenshotLinks;
}
public void setScreenshotLinks(List<String> screenshotLinks) {
this.screenshotLinks = screenshotLinks;
}
public String getIconLink() {
return iconLink;
}
public void setIconLink(String iconLink) {
this.iconLink = iconLink;
}
public String getReleaseType() {
return releaseType;
@ -174,4 +212,12 @@ public class EntAppReleaseWrapper {
public void setBanner(Base64File banner) {
this.banner = banner;
}
public String getBannerLink() {
return bannerLink;
}
public void setBannerLink(String bannerLink) {
this.bannerLink = bannerLink;
}
}

@ -86,6 +86,18 @@ public class PublicAppReleaseWrapper {
@ApiModelProperty(name = "icon",
value = "banner of the application")
private Base64File banner;
private boolean remoteStatus;
public boolean isRemoteStatus() {
return remoteStatus;
}
public void setRemoteStatus(boolean remoteStatus) {
this.remoteStatus = remoteStatus;
}
private List<String> screenshotLinks;
private String iconLink;
private String bannerLink;
public String getReleaseType() {
return releaseType;
@ -162,4 +174,28 @@ public class PublicAppReleaseWrapper {
public void setBanner(Base64File banner) {
this.banner = banner;
}
public List<String> getScreenshotLinks() {
return screenshotLinks;
}
public void setScreenshotLinks(List<String> screenshotLinks) {
this.screenshotLinks = screenshotLinks;
}
public String getIconLink() {
return iconLink;
}
public void setIconLink(String iconLink) {
this.iconLink = iconLink;
}
public String getBannerLink() {
return bannerLink;
}
public void setBannerLink(String bannerLink) {
this.bannerLink = bannerLink;
}
}

@ -0,0 +1,41 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common.wrapper;
public class TransferLinkWrapper {
private String directTransferLink;
private String relativeTransferLink;
public String getDirectTransferLink() {
return directTransferLink;
}
public void setDirectTransferLink(String directTransferLink) {
this.directTransferLink = directTransferLink;
}
public String getRelativeTransferLink() {
return relativeTransferLink;
}
public void setRelativeTransferLink(String relativeTransferLink) {
this.relativeTransferLink = relativeTransferLink;
}
}

@ -77,6 +77,42 @@ public class WebAppReleaseWrapper {
@ApiModelProperty(name = "icon",
value = "banner of the application")
private Base64File banner;
private boolean remoteStatus;
public boolean isRemoteStatus() {
return remoteStatus;
}
public void setRemoteStatus(boolean remoteStatus) {
this.remoteStatus = remoteStatus;
}
private List<String> screenshotLinks;
private String iconLink;
private String bannerLink;
public List<String> getScreenshotLinks() {
return screenshotLinks;
}
public void setScreenshotLinks(List<String> screenshotLinks) {
this.screenshotLinks = screenshotLinks;
}
public String getIconLink() {
return iconLink;
}
public void setIconLink(String iconLink) {
this.iconLink = iconLink;
}
public String getBannerLink() {
return bannerLink;
}
public void setBannerLink(String bannerLink) {
this.bannerLink = bannerLink;
}
public String getReleaseType() {
return releaseType;

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>application-mgt</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
@ -163,6 +163,9 @@
<systemPropertyVariables>
<jacoco-agent.destfile>${basedir}/target/coverage-reports/jacoco-unit.exec</jacoco-agent.destfile>
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
<iot.gateway.http.port>8280</iot.gateway.http.port>
<iot.gateway.https.port>8280</iot.gateway.https.port>
<iot.gateway.host>test</iot.gateway.host>
</systemPropertyVariables>
<classpathDependencyExcludes>
<classpathDependencyExclude>org.ops4j.pax.logging</classpathDependencyExclude>
@ -419,6 +422,27 @@
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.notification.logger</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.multitenancy</groupId>
<artifactId>org.wso2.carbon.tenant.mgt</artifactId>
<scope>compile</scope>
>>>>>>> upstream/master
</dependency>
</dependencies>
</project>

@ -238,4 +238,52 @@ public interface ApplicationDAO {
int getApplicationCount(Filter filter, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException;
void deleteApplication(int appId, int tenantId) throws ApplicationManagementDAOException;
/**
* Delete favourite applications of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteAppFavouritesByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete Application category mapping of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteApplicationCategoryMappingByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete Application categories of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteApplicationCategoriesByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete Application tags mapping of Tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteApplicationTagsMappingByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete Application tags of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteApplicationTagsByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete Applications of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteApplicationsByTenant(int tenantId) throws ApplicationManagementDAOException;
}

@ -127,4 +127,12 @@ public interface ApplicationReleaseDAO {
*/
List<ApplicationReleaseDTO> getReleaseByPackages(List<String> packages, int tenantId)
throws ApplicationManagementDAOException;
/**
* Delete Application releases of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteReleasesByTenant(int tenantId) throws ApplicationManagementDAOException;
}

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.application.mgt.core.dao;
import io.entgra.device.mgt.core.application.mgt.common.LifecycleState;
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
import io.entgra.device.mgt.core.application.mgt.core.exception.LifeCycleManagementDAOException;
import java.util.List;
@ -75,4 +76,11 @@ public interface LifecycleStateDAO {
*/
String getAppReleaseCreatedUsername(int appId, String uuid, int tenantId) throws LifeCycleManagementDAOException;
}
/**
* Delete Application lifecycle states of tenant
*
* @param tenantId Tenant ID
* @throws LifeCycleManagementDAOException thrown if an error occurs while deleting data
*/
void deleteAppLifecycleStatesByTenant(int tenantId) throws LifeCycleManagementDAOException;
}

@ -119,4 +119,11 @@ import java.util.List;
void deleteAllChildCommentsOfReview(int rootParentId, int tenantId) throws ReviewManagementDAOException;
/**
* Delete reviews of a tenant
*
* @param tenantId Tenant ID
* @throws ReviewManagementDAOException thrown if an error occurs while deleting data
*/
void deleteReviewsByTenant(int tenantId) throws ReviewManagementDAOException;
}

@ -128,4 +128,20 @@ public interface SPApplicationDAO {
* @throws ApplicationManagementDAOException if any db error occurred
*/
void deleteIdentityServer(int id, int tenantId) throws ApplicationManagementDAOException;
/**
* Delete Identity servers of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteIdentityServerByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete Service provide mapping details of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteSPApplicationMappingByTenant(int tenantId) throws ApplicationManagementDAOException;
}

@ -264,4 +264,52 @@ public interface SubscriptionDAO {
* @throws ApplicationManagementDAOException if error occurred while retrieving the app details
*/
Activity getOperationAppDetails(int operationId, int tenantId) throws ApplicationManagementDAOException;
/**
* Delete Operation mapping details of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteOperationMappingByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete device subscriptions of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteDeviceSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete group subscriptions of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteGroupSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete role subscriptions of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteRoleSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete user subscriptions of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteUserSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete scheduled subscription details of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteScheduledSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException;
}

@ -17,6 +17,7 @@
*/
package io.entgra.device.mgt.core.application.mgt.core.dao;
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
import io.entgra.device.mgt.core.application.mgt.core.exception.VisibilityManagementDAOException;
import java.util.List;
@ -70,4 +71,11 @@ public interface VisibilityDAO {
*/
void deleteAppUnrestrictedRoles(int applicationId, int tenantId) throws VisibilityManagementDAOException;
/**
* Delete app unrestricted roles of tenant
*
* @param tenantId Tenant ID
* @throws VisibilityManagementDAOException thrown if an error occurs while deleting data
*/
void deleteAppUnrestrictedRolesByTenant(int tenantId) throws VisibilityManagementDAOException;
}

@ -43,4 +43,28 @@ public interface VppApplicationDAO {
int addAssociation(VppAssociationDTO vppAssociationDTO, int tenantId) throws ApplicationManagementDAOException;
VppAssociationDTO updateAssociation(VppAssociationDTO vppAssociationDTO, int tenantId) throws ApplicationManagementDAOException;
/**
* Delete associations of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteAssociationByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete Vpp users of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteVppUserByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* Delete assets of tenant
*
* @param tenantId Tenant ID
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteAssetsByTenant(int tenantId) throws ApplicationManagementDAOException;
}

@ -1880,4 +1880,165 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
}
@Override
public void deleteAppFavouritesByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete app of tenant of id " + tenantId + " from favourites");
}
String sql = "DELETE FROM AP_APP_FAVOURITES "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing app from favourites of tenant "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing app of tenant of id " + tenantId + " from favourites. " +
"Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteApplicationCategoryMappingByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete application category mapping of tenant of id " + tenantId);
}
String sql = "DELETE FROM AP_APP_CATEGORY_MAPPING "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing application category mapping of tenant"
+tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing application category mapping of tenant of id " + tenantId +
"Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteApplicationCategoriesByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete application category of tenant of id " + tenantId);
}
String sql = "DELETE FROM AP_APP_CATEGORY "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing application category of tenant "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing application category of tenant of id " + tenantId +
"Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteApplicationTagsMappingByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete application tags mapping of tenant of id " + tenantId);
}
String sql = "DELETE FROM AP_APP_TAG_MAPPING "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing application tags mapping of tenant"
+tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing application tags mapping of tenant of id " + tenantId +
"Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteApplicationTagsByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete application tags of tenant of id " + tenantId);
}
String sql = "DELETE FROM AP_APP_TAG "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing application tags of tenant"
+tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing application tags of tenant of id " + tenantId +
"Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteApplicationsByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete applications of tenant of id " + tenantId);
}
String sql = "DELETE FROM AP_APP "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing applications of tenant"
+tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing applications of tenant of id " + tenantId +
"Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -620,4 +620,30 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
throw new ApplicationManagementDAOException(msg, e);
}
}
}
@Override
public void deleteReleasesByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete application releases of tenant of id " + tenantId);
}
String sql = "DELETE FROM AP_APP_RELEASE "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing application release of tenant"
+tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing application release of tenant of id " + tenantId +
"Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -480,4 +480,57 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
}
}
@Override
public void deleteIdentityServerByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete identity server of the tenant of id: " + tenantId);
}
String sql = "DELETE FROM AP_IDENTITY_SERVER " +
"WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to delete an identity server of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to delete an identity server of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteSPApplicationMappingByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete applications of tenant of id " + tenantId
+ " from service providers");
}
String sql = "DELETE FROM AP_IS_SP_APP_MAPPING "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing applications of tenant"
+tenantId+ "from service providers";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing applications of tenant of id " + tenantId +
"from service providers. Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -482,4 +482,57 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp
}
}
@Override
public void deleteIdentityServerByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete identity server of the tenant of id: " + tenantId);
}
String sql = "DELETE FROM AP_IDENTITY_SERVER " +
"WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to delete an identity server of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to delete an identity server of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteSPApplicationMappingByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete applications of tenant of id " + tenantId
+ " from service providers");
}
String sql = "DELETE FROM AP_IS_SP_APP_MAPPING "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing applications of tenant"
+tenantId+ "from service providers";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing applications of tenant of id " + tenantId +
"from service providers. Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -482,4 +482,57 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S
}
}
@Override
public void deleteIdentityServerByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete identity server of the tenant of id: " + tenantId);
}
String sql = "DELETE FROM AP_IDENTITY_SERVER " +
"WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to delete an identity server of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to delete an identity server of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteSPApplicationMappingByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete applications of tenant of id " + tenantId
+ " from service providers");
}
String sql = "DELETE FROM AP_IS_SP_APP_MAPPING "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing applications of tenant"
+tenantId+ "from service providers";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing applications of tenant of id " + tenantId +
"from service providers. Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -482,4 +482,57 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S
}
}
@Override
public void deleteIdentityServerByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete identity server of the tenant of id: " + tenantId);
}
String sql = "DELETE FROM AP_IDENTITY_SERVER " +
"WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to delete an identity server of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to delete an identity server of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteSPApplicationMappingByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete applications of tenant of id " + tenantId
+ " from service providers");
}
String sql = "DELETE FROM AP_IS_SP_APP_MAPPING "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing applications of tenant"
+tenantId+ "from service providers";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing applications of tenant of id " + tenantId +
"from service providers. Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -110,6 +110,32 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
}
}
@Override
public void deleteAppLifecycleStatesByTenant(int tenantId) throws LifeCycleManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete app lifecycle states of tenant of id " + tenantId);
}
String sql = "DELETE FROM AP_APP_LIFECYCLE_STATE "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing app lifecycle states of tenant"
+tenantId;
log.error(msg, e);
throw new LifeCycleManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing app lifecycle states of tenant of id " + tenantId +
"Executed Query: " + sql;
log.error(msg, e);
throw new LifeCycleManagementDAOException(msg, e);
}
}
@Override
public List<LifecycleState> getLifecycleStates(int appReleaseId, int tenantId) throws LifeCycleManagementDAOException {
try {

@ -597,4 +597,30 @@ public class GenericReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
throw new ReviewManagementDAOException(msg, e);
}
}
@Override
public void deleteReviewsByTenant(int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete app reviews of tenant of id " + tenantId);
}
String sql = "DELETE FROM AP_APP_REVIEW "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing app reviews of tenant "
+ tenantId;
log.error(msg, e);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing app reviews of tenant of id " + tenantId +
"Executed Query: " + sql;
log.error(msg, e);
throw new ReviewManagementDAOException(msg, e);
}
}
}

@ -1466,4 +1466,163 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteOperationMappingByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete operation mapping of the tenant of id: " + tenantId);
}
String sql = "DELETE FROM AP_APP_SUB_OP_MAPPING " +
"WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to delete operation mapping of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to delete operation mapping of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteRoleSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete role subscription of the tenant of id: " + tenantId);
}
String sql = "DELETE FROM AP_ROLE_SUBSCRIPTION " +
"WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to delete role subscription of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to delete role subscription of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteUserSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete user subscription of the tenant of id: " + tenantId);
}
String sql = "DELETE FROM AP_USER_SUBSCRIPTION " +
"WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to delete user subscription of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to delete user subscription of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteGroupSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete user subscription of the tenant of id: " + tenantId);
}
String sql = "DELETE FROM AP_GROUP_SUBSCRIPTION " +
"WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to delete group subscription of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to delete group subscription of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteScheduledSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete scheduled subscription of the tenant of id: " + tenantId);
}
String sql = "DELETE FROM AP_SCHEDULED_SUBSCRIPTION " +
"WHERE APPLICATION_UUID IN " +
"(SELECT UUID FROM AP_APP_RELEASE WHERE TENANT_ID = ?)";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeBatch();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to delete scheduled subscription of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to delete scheduled subscription of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteDeviceSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete device subscription of the tenant of id: " + tenantId);
}
String sql = "DELETE FROM AP_DEVICE_SUBSCRIPTION " +
"WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to delete device subscription of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to delete device subscription of tenant of id "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -176,4 +176,32 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
throw new VisibilityManagementDAOException(msg, e);
}
}
@Override
public void deleteAppUnrestrictedRolesByTenant(int tenantId) throws VisibilityManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete Application unrestricted roles of tenant of ID "
+ tenantId);
}
String sql = "DELETE "
+ "FROM AP_UNRESTRICTED_ROLE "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to delete application unrestricted roles of tenant: "
+ tenantId;
log.error(msg, e);
throw new VisibilityManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing query to delete application unrestricted roles which of"
+ " tenant Id " + tenantId + ". executed query: " + sql;
log.error(msg, e);
throw new VisibilityManagementDAOException(msg, e);
}
}
}

@ -506,4 +506,84 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteAssetsByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete application releases of tenant of id " + tenantId);
}
String sql = "DELETE FROM AP_ASSETS "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing application release of tenant "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing application release of tenant of id " + tenantId +
" Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteVppUserByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete vpp user of tenant of id " + tenantId);
}
String sql = "DELETE FROM AP_VPP_USER "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing vpp user of tenant "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing vpp user of tenant of id " + tenantId +
"Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteAssociationByTenant(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete association of tenant of id " + tenantId);
}
String sql = "DELETE FROM AP_VPP_ASSOCIATION "
+ "WHERE TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
stmt.executeUpdate();
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection when removing association of tenant"
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while removing association of tenant of id " + tenantId +
" Executed Query: " + sql;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -0,0 +1,30 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.core.exception;
public class FileTransferServiceHelperUtilException extends Exception {
public FileTransferServiceHelperUtilException(String msg) {
super(msg);
}
public FileTransferServiceHelperUtilException(String msg, Throwable t) {
super(msg, t);
}
}

@ -18,11 +18,16 @@
package io.entgra.device.mgt.core.application.mgt.core.impl;
import io.entgra.device.mgt.core.application.mgt.common.exception.FileDownloaderServiceException;
import io.entgra.device.mgt.core.application.mgt.common.exception.FileTransferServiceException;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.core.dao.*;
import io.entgra.device.mgt.core.application.mgt.core.exception.*;
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
import io.entgra.device.mgt.core.application.mgt.core.dao.SPApplicationDAO;
import io.entgra.device.mgt.core.application.mgt.core.util.ApplicationManagementUtil;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
import org.apache.commons.codec.digest.DigestUtils;
@ -75,11 +80,6 @@ import io.entgra.device.mgt.core.application.mgt.common.wrapper.PublicAppWrapper
import io.entgra.device.mgt.core.application.mgt.common.wrapper.WebAppReleaseWrapper;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.WebAppWrapper;
import io.entgra.device.mgt.core.application.mgt.core.config.ConfigurationManager;
import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationDAO;
import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationReleaseDAO;
import io.entgra.device.mgt.core.application.mgt.core.dao.LifecycleStateDAO;
import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO;
import io.entgra.device.mgt.core.application.mgt.core.dao.VisibilityDAO;
import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
import io.entgra.device.mgt.core.application.mgt.core.exception.ForbiddenException;
@ -95,6 +95,8 @@ import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementEx
import io.entgra.device.mgt.core.device.mgt.core.common.exception.StorageManagementException;
import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceType;
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService;
import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
@ -102,6 +104,8 @@ import org.wso2.carbon.user.api.UserStoreException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -127,6 +131,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
private SubscriptionDAO subscriptionDAO;
private LifecycleStateManager lifecycleStateManager;
private SPApplicationDAO spApplicationDAO;
private VppApplicationDAO vppApplicationDAO;
private ReviewDAO reviewDAO;
public ApplicationManagerImpl() {
initDataAccessObjects();
@ -140,10 +146,61 @@ public class ApplicationManagerImpl implements ApplicationManager {
this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
this.subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO();
this.spApplicationDAO = ApplicationManagementDAOFactory.getSPApplicationDAO();
this.vppApplicationDAO = ApplicationManagementDAOFactory.getVppApplicationDAO();
this.reviewDAO = ApplicationManagementDAOFactory.getCommentDAO();
}
@Override
public <T> Application createApplication(T app, boolean isPublished) throws ApplicationManagementException {
return createApplicationBasedOnRemoteStatus(app, isPublished);
}
/**
* Create the application based on the release wrapper's remote status. If the remote status is true, then
* the application creation will take place asynchronously.
* @param app Application release wrapper
* @param isPublished Publish status
* @return {@link Application}
* @throws ApplicationManagementException Throws when error occurred while application creation
*/
@SuppressWarnings("unchecked")
private <T> Application createApplicationBasedOnRemoteStatus(T app, boolean isPublished) throws ApplicationManagementException {
if (ApplicationManagementUtil.getRemoteStatus(app)) {
List<?> releaseWrappers = ApplicationManagementUtil.deriveApplicationWithoutRelease(app);
Application createdApplication = triggerApplicationCreation(app, isPublished);
if (createdApplication == null) {
throw new ApplicationManagementException("Null retrieved for created application.");
}
try {
if (releaseWrappers != null && !releaseWrappers.isEmpty()) {
if (app instanceof ApplicationWrapper) {
((ApplicationWrapper) app).setEntAppReleaseWrappers((List<EntAppReleaseWrapper>) releaseWrappers);
createApplicationReleaseBasedOnRemoteStatus(createdApplication.getId(),
((ApplicationWrapper) app).getEntAppReleaseWrappers().get(0), isPublished);
} else if (app instanceof CustomAppWrapper) {
((CustomAppWrapper) app).setCustomAppReleaseWrappers((List<CustomAppReleaseWrapper>) releaseWrappers);
createApplicationReleaseBasedOnRemoteStatus(createdApplication.getId(),
((CustomAppWrapper) app).getCustomAppReleaseWrappers().get(0), isPublished);
} else {
throw new ApplicationManagementException("Unsupported release wrapper received");
}
}
return createdApplication;
} catch (ResourceManagementException e) {
throw new ApplicationManagementException("Error encountered while creating deploying artifact", e);
}
}
return triggerApplicationCreation(app, isPublished);
}
/**
* Trigger the application creation process
* @param app Application release wrapper
* @param isPublished Publish status
* @return {@link Application}
* @throws ApplicationManagementException Throws when error occurred while creating the application
*/
private <T> Application triggerApplicationCreation(T app, boolean isPublished) throws ApplicationManagementException {
ApplicationDTO applicationDTO = uploadReleaseArtifactIfExist(app);
try {
ConnectionManagerUtil.beginDBTransaction();
@ -171,22 +228,110 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
/**
* Create application release based on remote status. If the remote status is true, then the
* application release creation will take place asynchronously.
* @param appId Application id
* @param releaseWrapper Release wrapper
* @param isPublished Publish status
* @return {@link Application}
* @throws ApplicationManagementException Throws when error occurred while deploying the release
* @throws ResourceManagementException Throws when error occurred while deploying the release
*/
private <T> ApplicationRelease createApplicationReleaseBasedOnRemoteStatus(int appId, T releaseWrapper, boolean isPublished)
throws ApplicationManagementException, ResourceManagementException {
if (ApplicationManagementUtil.getRemoteStatusFromWrapper(releaseWrapper)) {
triggerReleaseAsynchronously(appId, releaseWrapper, isPublished);
} else {
if (releaseWrapper instanceof EntAppReleaseWrapper) {
return triggerEntAppRelease(appId, (EntAppReleaseWrapper) releaseWrapper, isPublished);
}
if (releaseWrapper instanceof CustomAppReleaseWrapper) {
return triggerCustomAppRelease(appId, (CustomAppReleaseWrapper) releaseWrapper, isPublished);
}
throw new ApplicationManagementException("Unsupported release wrapper received");
}
return new ApplicationRelease();
}
/**
* Trigger release creation asynchronously
* @param appId Application id
* @param releaseWrapper Release wrapper
* @param isPublished Publish status
*/
private <T> void triggerReleaseAsynchronously(int appId, T releaseWrapper, boolean isPublished) {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
new Thread(() -> {
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username);
if (releaseWrapper instanceof EntAppReleaseWrapper &&
((EntAppReleaseWrapper) releaseWrapper).isRemoteStatus()) {
triggerEntAppRelease(appId, (EntAppReleaseWrapper) releaseWrapper, isPublished);
}else if (releaseWrapper instanceof CustomAppReleaseWrapper &&
((CustomAppReleaseWrapper) releaseWrapper).isRemoteStatus()) {
triggerCustomAppRelease(appId, (CustomAppReleaseWrapper) releaseWrapper, isPublished);
} else {
throw new ApplicationManagementException("Unsupported release wrapper received");
}
} catch (ApplicationManagementException | ResourceManagementException e) {
log.error("Error encountered while deploying remote application release", e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}).start();
}
/**
* Trigger enterprise application creation
* @param appId Application id
* @param releaseWrapper Release wrapper
* @param isPublished Publish status
* @return {@link ApplicationRelease}
* @throws ApplicationManagementException Throws when error encountered while creating enterprise application
*/
private ApplicationRelease triggerEntAppRelease(int appId, EntAppReleaseWrapper releaseWrapper, boolean isPublished)
throws ApplicationManagementException{
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIconLink(), releaseWrapper.getScreenshotLinks(),
releaseWrapper.getArtifactLink(), releaseWrapper.getBannerLink());
ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
releaseDTO = uploadEntAppReleaseArtifacts(releaseDTO, artifact, deviceType.getName(), true);
try {
return createRelease(applicationDTO, releaseDTO, ApplicationType.ENTERPRISE, isPublished);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating ent app release for application with the name: " + applicationDTO.getName();
log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(releaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e);
}
} catch (MalformedURLException e) {
String msg = "Malformed URL link received as a downloadable link";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (FileDownloaderServiceException e) {
String msg = "Error encountered while downloading application release artifacts for app id " + appId;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
@Override
public ApplicationRelease createEntAppRelease(int appId, EntAppReleaseWrapper releaseWrapper, boolean isPublished)
throws ApplicationManagementException {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(), releaseWrapper.getScreenshots(),
releaseWrapper.getBinaryFile(), releaseWrapper.getBanner());
ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
releaseDTO = uploadEntAppReleaseArtifacts(releaseDTO, artifact, deviceType.getName(), true);
try {
return createRelease(applicationDTO, releaseDTO, ApplicationType.ENTERPRISE, isPublished);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating ent app release for application with the name: " + applicationDTO.getName();
return createApplicationReleaseBasedOnRemoteStatus(appId, releaseWrapper, isPublished);
} catch (ResourceManagementException e) {
String msg = "Error occurred while creating enterprise app release for the app id " + appId;
log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(releaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e);
}
}
@ -195,17 +340,27 @@ public class ApplicationManagerImpl implements ApplicationManager {
public ApplicationRelease createWebAppRelease(int appId, WebAppReleaseWrapper releaseWrapper, boolean isPublished)
throws ApplicationManagementException, ResourceManagementException {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), null, releaseWrapper.getBanner());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
releaseDTO = uploadWebAppReleaseArtifacts(releaseDTO, artifact);
try {
return createRelease(applicationDTO, releaseDTO, ApplicationType.WEB_CLIP, isPublished);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating web app release for application with the name: " + applicationDTO.getName();
ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIconLink(), releaseWrapper.getScreenshotLinks(),
null, releaseWrapper.getBannerLink());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
releaseDTO = uploadWebAppReleaseArtifacts(releaseDTO, artifact);
try {
return createRelease(applicationDTO, releaseDTO, ApplicationType.WEB_CLIP, isPublished);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating web app release for application with the name: " + applicationDTO.getName();
log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(releaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e);
}
} catch (MalformedURLException e) {
String msg = "Malformed URL link received as a downloadable link";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (FileDownloaderServiceException e) {
String msg = "Error encountered while downloading application release artifacts";
log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(releaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e);
}
}
@ -214,38 +369,69 @@ public class ApplicationManagerImpl implements ApplicationManager {
public ApplicationRelease createPubAppRelease(int appId, PublicAppReleaseWrapper releaseWrapper, boolean isPublished) throws
ResourceManagementException, ApplicationManagementException {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), null, releaseWrapper.getBanner());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
releaseDTO = uploadPubAppReleaseArtifacts(releaseDTO, artifact, deviceType.getName());
try {
return createRelease(applicationDTO, releaseDTO, ApplicationType.PUBLIC, isPublished);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating ent public release for application with the name: " + applicationDTO.getName();
ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIconLink(), releaseWrapper.getScreenshotLinks(),
null, releaseWrapper.getBannerLink());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
releaseDTO = uploadPubAppReleaseArtifacts(releaseDTO, artifact, deviceType.getName());
try {
return createRelease(applicationDTO, releaseDTO, ApplicationType.PUBLIC, isPublished);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating ent public release for application with the name: " + applicationDTO.getName();
log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(releaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e);
}
} catch (MalformedURLException e) {
String msg = "Malformed URL link received as a downloadable link";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (FileDownloaderServiceException e) {
String msg = "Error encountered while downloading application release artifacts";
log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(releaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e);
}
}
@Override
public ApplicationRelease createCustomAppRelease(int appId, CustomAppReleaseWrapper releaseWrapper, boolean isPublished)
throws ApplicationManagementException {
try {
return createApplicationReleaseBasedOnRemoteStatus(appId, releaseWrapper, isPublished);
} catch (ResourceManagementException e) {
String msg = "Error occurred while creating enterprise app release";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
private ApplicationRelease triggerCustomAppRelease(int appId, CustomAppReleaseWrapper releaseWrapper, boolean isPublished)
throws ResourceManagementException, ApplicationManagementException {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), releaseWrapper.getBinaryFile(), releaseWrapper.getBanner());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
releaseDTO = uploadCustomAppReleaseArtifacts(releaseDTO, artifact, deviceType.getName());
try {
return createRelease(applicationDTO, releaseDTO, ApplicationType.CUSTOM, isPublished);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating custom app release for application with the name: " + applicationDTO.getName();
ApplicationDTO applicationDTO = applicationManager.getApplication(appId);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIconLink(), releaseWrapper.getScreenshotLinks(),
releaseWrapper.getArtifactLink(), releaseWrapper.getBannerLink());
ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper);
releaseDTO = uploadCustomAppReleaseArtifacts(releaseDTO, artifact, deviceType.getName());
try {
return createRelease(applicationDTO, releaseDTO, ApplicationType.CUSTOM, isPublished);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating custom app release for application with the name: " + applicationDTO.getName();
log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(releaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e);
}
} catch (MalformedURLException e) {
String msg = "Malformed URL link received as a downloadable link";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (FileDownloaderServiceException e) {
String msg = "Error encountered while downloading application release artifacts";
log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(releaseDTO.getAppHashValue()));
throw new ApplicationManagementException(msg, e);
}
}
@ -278,27 +464,27 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (app instanceof ApplicationWrapper) {
ApplicationWrapper wrapper = (ApplicationWrapper) app;
EntAppReleaseWrapper releaseWrapper = wrapper.getEntAppReleaseWrappers().get(0);
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), releaseWrapper.getBinaryFile(), releaseWrapper.getBanner());
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIconLink(), releaseWrapper.getScreenshotLinks(),
releaseWrapper.getArtifactLink(), releaseWrapper.getBannerLink());
releaseDTO = uploadEntAppReleaseArtifacts(releaseDTO,
artifact, wrapper.getDeviceType(), false);
} else if (app instanceof PublicAppWrapper) {
PublicAppWrapper wrapper = (PublicAppWrapper) app;
PublicAppReleaseWrapper releaseWrapper = wrapper.getPublicAppReleaseWrappers().get(0);
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), null, releaseWrapper.getBanner());
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIconLink(), releaseWrapper.getScreenshotLinks(),
null, releaseWrapper.getBannerLink());
releaseDTO = uploadPubAppReleaseArtifacts(releaseDTO, artifact, wrapper.getDeviceType());
} else if (app instanceof WebAppWrapper) {
WebAppWrapper wrapper = (WebAppWrapper) app;
WebAppReleaseWrapper releaseWrapper = wrapper.getWebAppReleaseWrappers().get(0);
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), null, releaseWrapper.getBanner());
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIconLink(), releaseWrapper.getScreenshotLinks(),
null, releaseWrapper.getBannerLink());
releaseDTO = uploadWebAppReleaseArtifacts(releaseDTO, artifact);
} else if (app instanceof CustomAppWrapper) {
CustomAppWrapper wrapper = (CustomAppWrapper) app;
CustomAppReleaseWrapper releaseWrapper = wrapper.getCustomAppReleaseWrappers().get(0);
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(),
releaseWrapper.getScreenshots(), releaseWrapper.getBinaryFile(), releaseWrapper.getBanner());
artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIconLink(), releaseWrapper.getScreenshotLinks(),
releaseWrapper.getArtifactLink(), releaseWrapper.getBannerLink());
try {
releaseDTO = uploadCustomAppReleaseArtifacts(releaseDTO, artifact, wrapper.getDeviceType());
} catch (ResourceManagementException e) {
@ -315,7 +501,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
String msg = "Error Occurred when uploading artifacts of the web clip: " + applicationDTO.getName();
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (MalformedURLException e) {
String msg = "Malformed URL link received as a downloadable link";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (FileDownloaderServiceException e) {
String msg = "Error encountered while downloading application release artifacts";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
// TODO: artifact URLs are not working for Windows AppX installations https://roadmap.entgra.net/issues/11010
//ApplicationManagementUtil.addInstallerPathToMetadata(releaseDTO);
applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(releaseDTO);
return applicationDTO;
@ -2421,21 +2617,25 @@ public class ApplicationManagerImpl implements ApplicationManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
ApplicationDTO applicationDTO = getApplication(applicationId);
String sanitizedName = "";
if (!StringUtils.isEmpty(applicationUpdateWrapper.getName())) {
sanitizedName = ApplicationManagementUtil.sanitizeName(applicationUpdateWrapper.getName(),
Constants.ApplicationProperties.NAME );
}
try {
ConnectionManagerUtil.beginDBTransaction();
if (!StringUtils.isEmpty(applicationUpdateWrapper.getName()) && !applicationDTO.getName()
.equals(applicationUpdateWrapper.getName())) {
if (!StringUtils.isEmpty(sanitizedName) && !applicationDTO.getName()
.equals(sanitizedName)) {
if (applicationDAO
.isExistingAppName(applicationUpdateWrapper.getName().trim(), applicationDTO.getDeviceTypeId(),
.isExistingAppName(sanitizedName.trim(), applicationDTO.getDeviceTypeId(),
tenantId)) {
String msg = "Already an application registered with same name " + applicationUpdateWrapper.getName()
String msg = "Already an application registered with same name " + sanitizedName
+ ". Hence you can't update the application name from " + applicationDTO.getName() + " to "
+ applicationUpdateWrapper.getName();
+ sanitizedName;
log.error(msg);
throw new BadRequestException(msg);
}
applicationDTO.setName(ApplicationManagementUtil.sanitizeName(applicationUpdateWrapper.getName(),
Constants.ApplicationProperties.NAME));
applicationDTO.setName(sanitizedName);
}
if (!StringUtils.isEmpty(applicationUpdateWrapper.getSubMethod()) && !applicationDTO.getSubType()
.equals(applicationUpdateWrapper.getSubMethod())) {
@ -3131,11 +3331,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public ApplicationRelease updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
public ApplicationRelease updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ApplicationArtifact applicationArtifact = ApplicationManagementUtil.
constructApplicationArtifact(entAppReleaseWrapper.getIconLink(), entAppReleaseWrapper.getScreenshotLinks(),
entAppReleaseWrapper.getArtifactLink(), entAppReleaseWrapper.getBannerLink());
ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId);
DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
@ -3202,17 +3404,25 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ "UUID:" + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (MalformedURLException e) {
throw new ApplicationManagementException("Malformed downloadable URL received for the Public app " +
"release UUID: " + releaseUuid);
} catch (FileDownloaderServiceException e) {
throw new ApplicationManagementException("Error encountered while downloading artifact for the Public app " +
"release UUID: " + releaseUuid);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public ApplicationRelease updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
public ApplicationRelease updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ApplicationArtifact applicationArtifact = ApplicationManagementUtil.
constructApplicationArtifact(publicAppReleaseWrapper.getIconLink(), publicAppReleaseWrapper.getScreenshotLinks(),
null, publicAppReleaseWrapper.getBannerLink());
ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId);
validateAppReleaseUpdating(publicAppReleaseWrapper, applicationDTO, applicationArtifact,
@ -3271,17 +3481,25 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ "release UUID:" + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (MalformedURLException e) {
throw new ApplicationManagementException("Malformed downloadable URL received for the Public app " +
"release UUID: " + releaseUuid);
} catch (FileDownloaderServiceException e) {
throw new ApplicationManagementException("Error encountered while downloading artifact for the Public app " +
"release UUID: " + releaseUuid);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public ApplicationRelease updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
public ApplicationRelease updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ApplicationArtifact applicationArtifact = ApplicationManagementUtil.
constructApplicationArtifact(webAppReleaseWrapper.getIconLink(), webAppReleaseWrapper.getScreenshotLinks(),
null, webAppReleaseWrapper.getBannerLink());
ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId);
validateAppReleaseUpdating(webAppReleaseWrapper, applicationDTO, applicationArtifact,
@ -3336,18 +3554,27 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ "release UUID:" + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (MalformedURLException e) {
throw new ApplicationManagementException("Malformed downloadable URL received for the Public app " +
"release UUID: " + releaseUuid);
} catch (FileDownloaderServiceException e) {
throw new ApplicationManagementException("Error encountered while downloading artifact for the Public app " +
"release UUID: " + releaseUuid);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public ApplicationRelease updateCustomAppRelease(String releaseUuid,
CustomAppReleaseWrapper customAppReleaseWrapper, ApplicationArtifact applicationArtifact)
public ApplicationRelease updateCustomAppRelease(String releaseUuid, CustomAppReleaseWrapper customAppReleaseWrapper)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
ApplicationArtifact applicationArtifact = ApplicationManagementUtil.
constructApplicationArtifact(customAppReleaseWrapper.getIconLink(),
customAppReleaseWrapper.getScreenshotLinks(), customAppReleaseWrapper.getArtifactLink(),
customAppReleaseWrapper.getBannerLink());
ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId);
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
@ -3466,6 +3693,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ "UUID:" + releaseUuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (MalformedURLException e) {
throw new ApplicationManagementException("Malformed downloadable URL received for the Public app " +
"release UUID: " + releaseUuid);
} catch (FileDownloaderServiceException e) {
throw new ApplicationManagementException("Error encountered while downloading artifact for the Public app " +
"release UUID: " + releaseUuid);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -3901,30 +4134,24 @@ public class ApplicationManagerImpl implements ApplicationManager {
public void validateEntAppReleaseCreatingRequest(EntAppReleaseWrapper releaseWrapper, String deviceType)
throws RequestValidatingException, ApplicationManagementException {
validateReleaseCreatingRequest(releaseWrapper, deviceType);
validateBinaryArtifact(releaseWrapper.getBinaryFile());
validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
}
@Override
public void validateCustomAppReleaseCreatingRequest(CustomAppReleaseWrapper releaseWrapper, String deviceType)
throws RequestValidatingException, ApplicationManagementException {
validateReleaseCreatingRequest(releaseWrapper, deviceType);
validateBinaryArtifact(releaseWrapper.getBinaryFile());
validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
}
@Override
public void validateWebAppReleaseCreatingRequest(WebAppReleaseWrapper releaseWrapper)
throws RequestValidatingException, ApplicationManagementException {
validateReleaseCreatingRequest(releaseWrapper, Constants.ANY);
validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
}
@Override
public void validatePublicAppReleaseCreatingRequest(PublicAppReleaseWrapper releaseWrapper, String deviceType)
throws RequestValidatingException, ApplicationManagementException {
validateReleaseCreatingRequest(releaseWrapper, deviceType);
validateImageArtifacts(releaseWrapper.getIcon(), releaseWrapper.getScreenshots());
validatePublicAppReleasePackageName(releaseWrapper.getPackageName());
}
@ -4165,4 +4392,145 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e);
}
}
@Override
public void deleteApplicationDataOfTenant(int tenantId) throws ApplicationManagementException {
if (log.isDebugEnabled()) {
log.debug("Request is received to delete application related data of tenant with ID: " + tenantId);
}
try {
ConnectionManagerUtil.beginDBTransaction();
vppApplicationDAO.deleteAssociationByTenant(tenantId);
vppApplicationDAO.deleteVppUserByTenant(tenantId);
vppApplicationDAO.deleteAssetsByTenant(tenantId);
reviewDAO.deleteReviewsByTenant(tenantId);
subscriptionDAO.deleteOperationMappingByTenant(tenantId);
subscriptionDAO.deleteDeviceSubscriptionByTenant(tenantId);
subscriptionDAO.deleteGroupSubscriptionByTenant(tenantId);
subscriptionDAO.deleteRoleSubscriptionByTenant(tenantId);
subscriptionDAO.deleteUserSubscriptionByTenant(tenantId);
applicationDAO.deleteAppFavouritesByTenant(tenantId);
applicationDAO.deleteApplicationTagsMappingByTenant(tenantId);
applicationDAO.deleteApplicationTagsByTenant(tenantId);
applicationDAO.deleteApplicationCategoryMappingByTenant(tenantId);
applicationDAO.deleteApplicationCategoriesByTenant(tenantId);
subscriptionDAO.deleteScheduledSubscriptionByTenant(tenantId);
lifecycleStateDAO.deleteAppLifecycleStatesByTenant(tenantId);
applicationReleaseDAO.deleteReleasesByTenant(tenantId);
visibilityDAO.deleteAppUnrestrictedRolesByTenant(tenantId);
spApplicationDAO.deleteSPApplicationMappingByTenant(tenantId);
spApplicationDAO.deleteIdentityServerByTenant(tenantId);
applicationDAO.deleteApplicationsByTenant(tenantId);
APIUtil.getApplicationStorageManager().deleteAppFolderOfTenant(tenantId);
ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg = "Error occurred while observing the database connection to delete applications for tenant with ID: "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Database access error is occurred when getting applications for tenant with ID: " + tenantId;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (LifeCycleManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while deleting life-cycle state data of application releases of the tenant"
+ " of ID: " + tenantId ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ReviewManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while deleting reviews of application releases of the applications"
+ " of tenant ID: " + tenantId ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationStorageManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while deleting App folder of tenant"
+ " of tenant ID: " + tenantId ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public void deleteApplicationDataByTenantDomain(String tenantDomain) throws ApplicationManagementException {
int tenantId;
try{
TenantMgtAdminService tenantMgtAdminService = new TenantMgtAdminService();
TenantInfoBean tenantInfoBean = tenantMgtAdminService.getTenant(tenantDomain);
tenantId = tenantInfoBean.getTenantId();
} catch (Exception e) {
String msg = "Error getting tenant ID from domain: "
+ tenantDomain;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
try {
ConnectionManagerUtil.beginDBTransaction();
vppApplicationDAO.deleteAssociationByTenant(tenantId);
vppApplicationDAO.deleteVppUserByTenant(tenantId);
vppApplicationDAO.deleteAssetsByTenant(tenantId);
reviewDAO.deleteReviewsByTenant(tenantId);
subscriptionDAO.deleteOperationMappingByTenant(tenantId);
subscriptionDAO.deleteDeviceSubscriptionByTenant(tenantId);
subscriptionDAO.deleteGroupSubscriptionByTenant(tenantId);
subscriptionDAO.deleteRoleSubscriptionByTenant(tenantId);
subscriptionDAO.deleteUserSubscriptionByTenant(tenantId);
applicationDAO.deleteAppFavouritesByTenant(tenantId);
applicationDAO.deleteApplicationTagsMappingByTenant(tenantId);
applicationDAO.deleteApplicationTagsByTenant(tenantId);
applicationDAO.deleteApplicationCategoryMappingByTenant(tenantId);
applicationDAO.deleteApplicationCategoriesByTenant(tenantId);
subscriptionDAO.deleteScheduledSubscriptionByTenant(tenantId);
lifecycleStateDAO.deleteAppLifecycleStatesByTenant(tenantId);
applicationReleaseDAO.deleteReleasesByTenant(tenantId);
visibilityDAO.deleteAppUnrestrictedRolesByTenant(tenantId);
spApplicationDAO.deleteSPApplicationMappingByTenant(tenantId);
spApplicationDAO.deleteIdentityServerByTenant(tenantId);
applicationDAO.deleteApplicationsByTenant(tenantId);
APIUtil.getApplicationStorageManager().deleteAppFolderOfTenant(tenantId);
ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg = "Error occurred while observing the database connection to delete applications for tenant with ID: "
+ tenantId;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Database access error is occurred when getting applications for tenant with ID: " + tenantId;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (LifeCycleManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while deleting life-cycle state data of application releases of the tenant"
+ " of ID: " + tenantId ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ReviewManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while deleting reviews of application releases of the applications"
+ " of tenant ID: " + tenantId ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationStorageManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while deleting App folder of tenant"
+ " of tenant ID: " + tenantId ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
}

@ -313,4 +313,18 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
throw new StorageManagementException(msg, e);
}
}
@Override
public void deleteAppFolderOfTenant(int tenantId) throws ApplicationStorageManagementException{
String folderPath = storagePath + File.separator + tenantId;
File folder = new File(folderPath);
if (folder.exists()) {
try {
StorageManagementUtil.delete(folder);
} catch (IOException e) {
throw new ApplicationStorageManagementException(
"Error occurred while deleting App folder of tenant:" + tenantId, e);
}
}
}
}

@ -0,0 +1,211 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.core.impl;
import io.entgra.device.mgt.core.application.mgt.common.FileDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.FileMetaEntry;
import io.entgra.device.mgt.core.application.mgt.common.TransferLink;
import io.entgra.device.mgt.core.application.mgt.common.exception.FileDownloaderServiceException;
import io.entgra.device.mgt.core.application.mgt.common.exception.FileTransferServiceException;
import io.entgra.device.mgt.core.application.mgt.common.services.FileDownloaderService;
import io.entgra.device.mgt.core.application.mgt.common.services.FileTransferService;
import io.entgra.device.mgt.core.application.mgt.core.internal.DataHolder;
import io.entgra.device.mgt.core.application.mgt.core.util.Constants;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
public class FileDownloaderServiceProvider {
private static final Log log = LogFactory.getLog(FileDownloaderServiceProvider.class);
private static final FileTransferService fileTransferService = DataHolder.getInstance().getFileTransferService();
private static final LocalFileDownloaderService localFileDownloaderService = new LocalFileDownloaderService();
private static final RemoteFileDownloaderService remoteFileDownloaderService = new RemoteFileDownloaderService();
public static FileDownloaderService getFileDownloaderService(URL downloadUrl) throws FileDownloaderServiceException {
try {
if (fileTransferService.isExistsOnLocal(downloadUrl)) {
return localFileDownloaderService;
}
return remoteFileDownloaderService;
} catch (FileTransferServiceException e) {
String msg = "Error encountered while acquiring file downloader service";
log.error(msg, e);
throw new FileDownloaderServiceException(msg, e);
}
}
/**
* Class holing the implementation of the local file downloading service
*/
private static class LocalFileDownloaderService implements FileDownloaderService {
@Override
public FileDescriptor download(URL downloadUrl) throws FileDownloaderServiceException {
try {
return fileTransferService.resolve(downloadUrl);
} catch (FileTransferServiceException e) {
String msg = "Error encountered while downloading file pointing by " + downloadUrl;
log.error(msg, e);
throw new FileDownloaderServiceException(msg, e);
}
}
}
/**
* Class holing the implementation of the remote file downloading service
*/
private static class RemoteFileDownloaderService implements FileDownloaderService {
private static final OkHttpClient okhttpClient =
new OkHttpClient.Builder().connectTimeout(500, TimeUnit.MILLISECONDS).build();
@Override
public FileDescriptor download(URL downloadUrl) throws FileDownloaderServiceException {
FileMetaEntry fileMetaEntry = getFileMetaEntry(downloadUrl);
try {
TransferLink transferLink = fileTransferService.generateUploadLink(fileMetaEntry);
FileDescriptor fileDescriptor = fileTransferService.resolve(new URL(transferLink.getDirectTransferLink()
+ "/" + fileMetaEntry.getFileName() + "." + fileMetaEntry.getExtension()));
FileUtils.copyURLToFile(downloadUrl, new File(fileDescriptor.getAbsolutePath()),
15000, 3600000);
return fileDescriptor;
} catch (FileTransferServiceException | IOException e) {
String msg = "Error encountered while downloading file";
log.error(msg, e);
throw new FileDownloaderServiceException(msg, e);
}
}
/**
* Generate the {@link FileMetaEntry} from the remote file
* @param downloadUrl Remote file URL
* @return {@link FileMetaEntry}
* @throws FileDownloaderServiceException Throws when error encountered while generating {@link FileMetaEntry}
*/
private FileMetaEntry getFileMetaEntry(URL downloadUrl) throws FileDownloaderServiceException {
Request request = new Request.Builder().url(downloadUrl).head().build();
try (Response response = okhttpClient.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new FileDownloaderServiceException("Unexpected response code received for the remote url " + downloadUrl);
}
String contentDisposition = response.header("Content-Disposition");
String contentType = response.header("Content-Type");
String[] fileNameSegments = extractFileNameSegmentsFromUrl(downloadUrl);
// if the url parsing failed to resolve the file name segments
// falling to remote file name segment resolving
if (fileNameSegments == null) {
fileNameSegments = getFileNameSegments(contentDisposition, contentType);
}
FileMetaEntry fileMetaEntry = new FileMetaEntry();
fileMetaEntry.setSize(Long.parseLong(Objects.requireNonNull(response.header("Content-Length"))));
fileMetaEntry.setFileName(fileNameSegments[0]);
fileMetaEntry.setExtension(fileNameSegments[1]);
return fileMetaEntry;
} catch (IOException e) {
throw new FileDownloaderServiceException("IO error occurred while constructing file name for the remote url " + downloadUrl);
}
}
/**
* Extracting file name segments by parsing the URL
* @param url Remote URL to extract file name segments
* @return Array containing file name segments or null when failed to extract
*/
public static String[] extractFileNameSegmentsFromUrl(URL url) {
if (url == null) {
if (log.isDebugEnabled()) {
log.debug("Null received as the remote URL");
}
return null;
}
String []urlSegments = url.toString().split("/");
if (urlSegments.length < 1) {
if (log.isDebugEnabled()) {
log.debug("Cannot determine the file name for the remote file");
}
return null;
}
String fullQualifiedName = urlSegments[urlSegments.length - 1];
String []fileNameSegments = fullQualifiedName.split("\\.(?=[^.]+$)");
if (fileNameSegments.length != 2) {
if (log.isDebugEnabled()) {
log.debug("Error encountered when constructing file name");
}
return null;
}
return fileNameSegments;
}
/**
* Extract file name segments(filename & extensions) from content disposition header and content type header
* @param contentDisposition Content disposition header value
* @param contentType Content type header value
* @return Array of name segments
* @throws FileDownloaderServiceException Throws when error occurred while extracting name segments
*/
private static String[] getFileNameSegments(String contentDisposition, String contentType) throws FileDownloaderServiceException {
if (contentDisposition == null && contentType == null) {
throw new FileDownloaderServiceException("Cannot determine the file name for the remote file");
}
if (contentDisposition == null) {
String extension;
if (contentType.equals(Constants.MIME_TYPE_VND_ANDROID_PACKAGE_ARCHIVE)) {
extension = Constants.EXTENSION_APK;
} else if (contentType.equals(Constants.MIME_TYPE_OCTET_STREAM)) {
extension = Constants.EXTENSION_IPA;
} else if (contentType.equals(Constants.MIME_TYPE_VND_APPX)) {
extension = Constants.EXTENSION_APPX;
} else if (contentType.equals(Constants.MIME_TYPE_X_MS_INSTALLER)
|| contentType.equals(Constants.MIME_TYPE_VND_MS_WINDOWS_MSI)) {
extension = Constants.EXTENSION_MSI;
} else {
String []contentTypeSegments = contentType.split("/");
if (contentTypeSegments.length != 2) {
throw new FileDownloaderServiceException("Encountered wrong content type header value");
}
extension = contentTypeSegments[contentTypeSegments.length - 1];
}
return new String[]{ UUID.randomUUID().toString(), extension};
}
String []contentDispositionSegments = contentDisposition.split("=");
if (contentDispositionSegments.length != 2) {
throw new FileDownloaderServiceException("Error encountered when constructing file name");
}
String fullQualifiedName = contentDispositionSegments[contentDispositionSegments.length - 1].replace("\"", "");
String []fileNameSegments = fullQualifiedName.split("\\.(?=[^.]+$)");
if (fileNameSegments.length != 2) {
throw new FileDownloaderServiceException("Error encountered when constructing file name");
}
return fileNameSegments;
}
}
}

@ -0,0 +1,124 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.core.impl;
import io.entgra.device.mgt.core.application.mgt.common.ChunkDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.FileDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.FileMetaEntry;
import io.entgra.device.mgt.core.application.mgt.common.TransferLink;
import io.entgra.device.mgt.core.application.mgt.common.exception.FileTransferServiceException;
import io.entgra.device.mgt.core.application.mgt.common.services.FileTransferService;
import io.entgra.device.mgt.core.application.mgt.core.exception.FileTransferServiceHelperUtilException;
import io.entgra.device.mgt.core.application.mgt.core.util.FileTransferServiceHelperUtil;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.NotFoundException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.FileSystems;
import java.nio.file.Path;
public class FileTransferServiceImpl implements FileTransferService {
private final static Log log = LogFactory.getLog(FileTransferServiceImpl.class);
private static volatile FileTransferServiceImpl INSTANCE;
private FileTransferServiceImpl() throws FileTransferServiceException {
try {
FileTransferServiceHelperUtil.createDefaultRootStructure();
} catch (FileTransferServiceHelperUtilException e) {
String msg = "Error occurred while initializing file transfer service";
log.error(msg, e);
throw new FileTransferServiceException(msg, e);
}
}
public static FileTransferService getInstance() throws FileTransferServiceException{
if (INSTANCE == null) {
synchronized (FileTransferServiceImpl.class) {
if (INSTANCE == null) {
INSTANCE = new FileTransferServiceImpl();
}
}
}
return INSTANCE;
}
@Override
public TransferLink generateUploadLink(FileMetaEntry fileMetaEntry) throws FileTransferServiceException {
try {
Path artifactHolder = FileTransferServiceHelperUtil.createNewArtifactHolder(fileMetaEntry);
String []pathSegments = artifactHolder.toString().split(FileSystems.getDefault().getSeparator());
TransferLink.TransferLinkBuilder transferLinkBuilder =
new TransferLink.TransferLinkBuilder(pathSegments[pathSegments.length - 1]);
return transferLinkBuilder.build();
} catch (FileTransferServiceHelperUtilException e) {
String msg = "Error encountered while generating upload link";
log.error(msg, e);
throw new FileTransferServiceException(msg, e);
}
}
@Override
public ChunkDescriptor resolve(String artifactHolder, InputStream chunk) throws FileTransferServiceException, NotFoundException {
ChunkDescriptor chunkDescriptor = new ChunkDescriptor();
try {
FileTransferServiceHelperUtil.populateChunkDescriptor(artifactHolder, chunk, chunkDescriptor);
return chunkDescriptor;
} catch (FileTransferServiceHelperUtilException e) {
String msg = "Error occurred while resolving chuck descriptor for " + artifactHolder;
log.error(msg);
throw new FileTransferServiceException(msg, e);
}
}
@Override
public void writeChunk(ChunkDescriptor chunkDescriptor) throws FileTransferServiceException {
try {
FileTransferServiceHelperUtil.writeChunk(chunkDescriptor);
} catch (FileTransferServiceHelperUtilException e) {
String msg = "Failed to write data to artifact located in " + chunkDescriptor.getAssociateFileDescriptor().getAbsolutePath();
log.error(msg);
throw new FileTransferServiceException(msg, e);
}
}
@Override
public boolean isExistsOnLocal(URL downloadUrl) throws FileTransferServiceException {
try {
return FileTransferServiceHelperUtil.resolve(downloadUrl) != null;
} catch (FileTransferServiceHelperUtilException e) {
String msg = "Error occurred while checking the existence of artifact on the local environment";
log.error(msg, e);
throw new FileTransferServiceException(msg, e);
}
}
@Override
public FileDescriptor resolve(URL downloadUrl) throws FileTransferServiceException {
try {
return FileTransferServiceHelperUtil.resolve(downloadUrl);
} catch (FileTransferServiceHelperUtilException e) {
String msg = "Error occurred while resolving file descriptor pointing from " + downloadUrl;
log.error(msg, e);
throw new FileTransferServiceException(msg, e);
}
}
}

@ -21,6 +21,7 @@ import io.entgra.device.mgt.core.application.mgt.common.config.LifecycleState;
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationStorageManager;
import io.entgra.device.mgt.core.application.mgt.common.services.AppmDataHandler;
import io.entgra.device.mgt.core.application.mgt.common.services.FileTransferService;
import io.entgra.device.mgt.core.application.mgt.common.services.ReviewManager;
import io.entgra.device.mgt.core.application.mgt.common.services.SPApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager;
@ -29,6 +30,7 @@ import io.entgra.device.mgt.core.application.mgt.common.services.*;
import io.entgra.device.mgt.core.application.mgt.core.config.ConfigurationManager;
import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import io.entgra.device.mgt.core.application.mgt.core.impl.AppmDataHandlerImpl;
import io.entgra.device.mgt.core.application.mgt.core.impl.FileTransferServiceImpl;
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
import io.entgra.device.mgt.core.application.mgt.core.task.ScheduledAppSubscriptionTaskManager;
import io.entgra.device.mgt.core.application.mgt.core.util.ApplicationManagementUtil;
@ -102,6 +104,10 @@ public class ApplicationManagementServiceComponent {
DataHolder.getInstance().setVppApplicationManager(vppApplicationManager);
bundleContext.registerService(VPPApplicationManager.class.getName(), vppApplicationManager, null);
FileTransferService fileTransferService = FileTransferServiceImpl.getInstance();
DataHolder.getInstance().setFileTransferService(fileTransferService);
bundleContext.registerService(FileTransferService.class.getName(), fileTransferService, null);
ScheduledAppSubscriptionTaskManager taskManager = new ScheduledAppSubscriptionTaskManager();
// todo: taskManager.scheduleCleanupTask();

@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.application.mgt.core.internal;
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationStorageManager;
import io.entgra.device.mgt.core.application.mgt.common.services.AppmDataHandler;
import io.entgra.device.mgt.core.application.mgt.common.services.FileTransferService;
import io.entgra.device.mgt.core.application.mgt.common.services.SPApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.ReviewManager;
import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager;
@ -56,6 +57,7 @@ public class DataHolder {
private AppmDataHandler configManager;
private TaskService taskService;
private FileTransferService fileTransferService;
private static final DataHolder applicationMgtDataHolder = new DataHolder();
@ -154,4 +156,12 @@ public class DataHolder {
public void setVppApplicationManager(VPPApplicationManager vppApplicationManager) {
this.vppApplicationManager = vppApplicationManager;
}
public FileTransferService getFileTransferService() {
return fileTransferService;
}
public void setFileTransferService(FileTransferService fileTransferService) {
this.fileTransferService = fileTransferService;
}
}

@ -67,6 +67,7 @@ public class APIUtil {
private static volatile AppmDataHandler appmDataHandler;
private static volatile VPPApplicationManager vppApplicationManager;
private static volatile MetadataManagementService metadataManagementService;
private static volatile FileTransferService fileTransferService;
public static SPApplicationManager getSPApplicationManager() {
if (SPApplicationManager == null) {
@ -488,7 +489,6 @@ public class APIUtil {
List<String> screenshotPaths = new ArrayList<>();
ApplicationRelease applicationRelease = new ApplicationRelease();
UrlValidator urlValidator = new UrlValidator();
applicationRelease.setDescription(applicationReleaseDTO.getDescription());
applicationRelease.setVersion(applicationReleaseDTO.getVersion());
@ -511,13 +511,8 @@ public class APIUtil {
.getBannerName());
}
if (urlValidator.isValid(applicationReleaseDTO.getInstallerName())) {
applicationRelease.setInstallerPath(applicationReleaseDTO.getInstallerName());
} else {
applicationRelease.setInstallerPath(
basePath + Constants.APP_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO
.getInstallerName());
}
applicationRelease.setInstallerPath(constructInstallerPath(applicationReleaseDTO.getInstallerName(),
applicationReleaseDTO.getAppHashValue()));
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) {
screenshotPaths
@ -538,6 +533,21 @@ public class APIUtil {
return applicationRelease;
}
/**
* Construct installer path
* @param installerName Installer name
* @param appHash Application hash
* @return Constructed installer path value
* @throws ApplicationManagementException Throws when error encountered while constructing installer path
*/
public static String constructInstallerPath(String installerName, String appHash) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
UrlValidator urlValidator = new UrlValidator();
String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH + appHash + Constants.FORWARD_SLASH;
return urlValidator.isValid(installerName) ? installerName
: basePath + Constants.APP_ARTIFACT + Constants.FORWARD_SLASH + installerName;
}
public static String getArtifactDownloadBaseURL() throws ApplicationManagementException {
String host = System.getProperty(Constants.IOT_CORE_HOST);
MDMConfig mdmConfig = ConfigurationManager.getInstance().getConfiguration().getMdmConfig();
@ -584,4 +594,16 @@ public class APIUtil {
}
return metadataManagementService;
}
public static FileTransferService getFileTransferService() {
if (fileTransferService == null) {
synchronized (APIUtil.class) {
if (fileTransferService == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
fileTransferService = (FileTransferService) ctx.getOSGiService(FileTransferService.class, null);
}
}
}
return fileTransferService;
}
}

@ -17,18 +17,27 @@
*/
package io.entgra.device.mgt.core.application.mgt.core.util;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationArtifact;
import io.entgra.device.mgt.core.application.mgt.common.FileDataHolder;
import io.entgra.device.mgt.core.application.mgt.common.FileDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.LifecycleChanger;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ItuneAppDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.FileDownloaderServiceException;
import io.entgra.device.mgt.core.application.mgt.common.exception.FileTransferServiceException;
import io.entgra.device.mgt.core.application.mgt.common.exception.InvalidConfigurationException;
import io.entgra.device.mgt.core.application.mgt.common.exception.RequestValidatingException;
import io.entgra.device.mgt.core.application.mgt.common.response.Application;
import io.entgra.device.mgt.core.application.mgt.common.response.Category;
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationStorageManager;
import io.entgra.device.mgt.core.application.mgt.common.services.FileTransferService;
import io.entgra.device.mgt.core.application.mgt.common.services.ReviewManager;
import io.entgra.device.mgt.core.application.mgt.common.services.SPApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager;
@ -45,17 +54,17 @@ import io.entgra.device.mgt.core.application.mgt.common.wrapper.WebAppWrapper;
import io.entgra.device.mgt.core.application.mgt.core.config.ConfigurationManager;
import io.entgra.device.mgt.core.application.mgt.core.config.Extension;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.core.impl.FileDownloaderServiceProvider;
import io.entgra.device.mgt.core.application.mgt.core.impl.VppApplicationManagerImpl;
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
import io.entgra.device.mgt.core.device.mgt.core.common.util.FileUtil;
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.MetadataManagementServiceImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.application.mgt.common.services.*;
import io.entgra.device.mgt.core.application.mgt.common.wrapper.*;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -76,6 +85,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
/**
@ -161,6 +171,49 @@ public class ApplicationManagementUtil {
return applicationArtifact;
}
public static ApplicationArtifact constructApplicationArtifact(String iconLink, List<String> screenshotLinks, String artifactLink, String bannerLink)
throws MalformedURLException, FileDownloaderServiceException {
ApplicationArtifact applicationArtifact = new ApplicationArtifact();
FileDescriptor fileDescriptor;
if (artifactLink != null) {
URL artifactLinkUrl = new URL(artifactLink);
fileDescriptor = FileDownloaderServiceProvider.getFileDownloaderService(artifactLinkUrl).download(artifactLinkUrl);
applicationArtifact.setInstallerName(fileDescriptor.getFullQualifiedName());
applicationArtifact.setInstallerStream(fileDescriptor.getFile());
}
if (iconLink != null) {
URL iconLinkUrl = new URL(iconLink);
fileDescriptor = FileDownloaderServiceProvider.getFileDownloaderService(iconLinkUrl).download(iconLinkUrl);
applicationArtifact.setIconName(fileDescriptor.getFullQualifiedName());
applicationArtifact.setIconStream(fileDescriptor.getFile());
}
if (bannerLink != null) {
URL bannerLinkUrl = new URL(bannerLink);
fileDescriptor = FileDownloaderServiceProvider.getFileDownloaderService(bannerLinkUrl).download(bannerLinkUrl);
applicationArtifact.setBannerName(fileDescriptor.getFullQualifiedName());
applicationArtifact.setBannerStream(fileDescriptor.getFile());
}
if (screenshotLinks != null) {
Map<String, InputStream> screenshotData = new TreeMap<>();
// This is to handle cases in which multiple screenshots have the same name
Map<String, Integer> screenshotNameCount = new HashMap<>();
URL screenshotLinkUrl;
for (String screenshotLink : screenshotLinks) {
screenshotLinkUrl = new URL(screenshotLink);
fileDescriptor = FileDownloaderServiceProvider.getFileDownloaderService(screenshotLinkUrl).download(screenshotLinkUrl);
String screenshotName = fileDescriptor.getFullQualifiedName();
screenshotNameCount.put(screenshotName, screenshotNameCount.getOrDefault(screenshotName, 0) + 1);
screenshotName = FileUtil.generateDuplicateFileName(screenshotName, screenshotNameCount.get(screenshotName));
screenshotData.put(screenshotName, fileDescriptor.getFile());
}
applicationArtifact.setScreenshots(screenshotData);
}
return applicationArtifact;
}
/**
*
* @param base64File Base64File that should be converted to FileDataHolder bean
@ -253,6 +306,41 @@ public class ApplicationManagementUtil {
throw new IllegalArgumentException("Provided bean does not belong to an Application Wrapper");
}
public static <T> boolean getRemoteStatus(T appWrapper) {
if (!isReleaseAvailable(appWrapper)) {
return false;
}
if (appWrapper instanceof ApplicationWrapper) {
return getRemoteStatusFromWrapper(((ApplicationWrapper) appWrapper).getEntAppReleaseWrappers().get(0));
}
if (appWrapper instanceof PublicAppWrapper) {
return getRemoteStatusFromWrapper(((PublicAppWrapper) appWrapper).getPublicAppReleaseWrappers().get(0));
}
if (appWrapper instanceof WebAppWrapper) {
return getRemoteStatusFromWrapper(((WebAppWrapper) appWrapper).getWebAppReleaseWrappers().get(0));
}
if (appWrapper instanceof CustomAppWrapper) {
return getRemoteStatusFromWrapper(((CustomAppWrapper) appWrapper).getCustomAppReleaseWrappers().get(0));
}
throw new IllegalArgumentException("Provided bean does not belong to an Application Wrapper");
}
public static <T> boolean getRemoteStatusFromWrapper(T releaseWrapper) {
if (releaseWrapper instanceof EntAppReleaseWrapper) {
return ((EntAppReleaseWrapper) releaseWrapper).isRemoteStatus();
}
if (releaseWrapper instanceof PublicAppReleaseWrapper) {
return ((PublicAppReleaseWrapper) releaseWrapper).isRemoteStatus();
}
if (releaseWrapper instanceof WebAppReleaseWrapper) {
return ((WebAppReleaseWrapper) releaseWrapper).isRemoteStatus();
}
if (releaseWrapper instanceof CustomAppReleaseWrapper) {
return ((CustomAppReleaseWrapper) releaseWrapper).isRemoteStatus();
}
throw new IllegalArgumentException("Provided bean does not belong to an Release Wrapper");
}
public static <T> T getInstance(Extension extension, Class<T> cls) throws InvalidConfigurationException {
try {
Class theClass = Class.forName(extension.getClassName());
@ -281,13 +369,12 @@ public class ApplicationManagementUtil {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Category> categories = applicationManager.getRegisteredCategories();
if (product != null && product.getVersion() != null) {
// Generate artifacts
ApplicationArtifact applicationArtifact = generateArtifacts(product);
List<String> packageNamesOfApps = new ArrayList<>();
packageNamesOfApps.add(product.getPackageName());
List<Application> existingApps = applicationManager.getApplications(packageNamesOfApps);
PublicAppReleaseWrapper publicAppReleaseWrapper = generatePublicAppReleaseWrapper(product);
if (existingApps != null && existingApps.size() > 0) {
Application app = existingApps.get(0);
@ -295,7 +382,6 @@ public class ApplicationManagementUtil {
ApplicationUpdateWrapper applicationUpdateWrapper = generatePubAppUpdateWrapper(product, categories);
applicationManager.updateApplication(app.getId(), applicationUpdateWrapper);
PublicAppReleaseWrapper publicAppReleaseWrapper = new PublicAppReleaseWrapper();
if (app.getSubMethod()
.equalsIgnoreCase(Constants.ApplicationProperties.FREE_SUB_METHOD)) {
publicAppReleaseWrapper.setPrice(0.0);
@ -308,56 +394,48 @@ public class ApplicationManagementUtil {
publicAppReleaseWrapper.setVersion(product.getVersion());
publicAppReleaseWrapper.setSupportedOsVersions("4.0-12.3");
applicationManager.updatePubAppRelease(app.getApplicationReleases().get(0).getUuid(),
publicAppReleaseWrapper, applicationArtifact);
publicAppReleaseWrapper);
return;
}
} else {
// Generate App wrapper
PublicAppWrapper publicAppWrapper = generatePubAppWrapper(product, categories);
PublicAppReleaseWrapper appReleaseWrapper = new PublicAppReleaseWrapper();
if (publicAppWrapper.getSubMethod()
.equalsIgnoreCase(Constants.ApplicationProperties.FREE_SUB_METHOD)) {
appReleaseWrapper.setPrice(0.0);
} else {
appReleaseWrapper.setPrice(1.0);
}
appReleaseWrapper.setDescription(product.getDescription());
appReleaseWrapper.setReleaseType("ga");
appReleaseWrapper.setVersion(product.getVersion());
appReleaseWrapper.setPackageName(product.getPackageName());
appReleaseWrapper.setSupportedOsVersions("4.0-12.3");
publicAppWrapper.setPublicAppReleaseWrappers(
Arrays.asList(new PublicAppReleaseWrapper[]{appReleaseWrapper}));
try {
updateImages(appReleaseWrapper, applicationArtifact.getIconName(),
applicationArtifact.getIconStream(), applicationArtifact.getScreenshots());
Application application = applicationManager.createApplication(publicAppWrapper, false);
if (application != null && (application.getApplicationReleases().get(0).getCurrentStatus() == null
|| application.getApplicationReleases().get(0).getCurrentStatus().equals("CREATED"))) {
String uuid = application.getApplicationReleases().get(0).getUuid();
LifecycleChanger lifecycleChanger = new LifecycleChanger();
lifecycleChanger.setAction("IN-REVIEW");
applicationManager.changeLifecycleState(uuid, lifecycleChanger);
lifecycleChanger.setAction("APPROVED");
applicationManager.changeLifecycleState(uuid, lifecycleChanger);
lifecycleChanger.setAction("PUBLISHED");
applicationManager.changeLifecycleState(uuid, lifecycleChanger);
}
} catch (IOException e) {
String msg = "Error while downloading images of release.";
log.error(msg);
throw new ApplicationManagementException(msg, e);
Arrays.asList(new PublicAppReleaseWrapper[]{publicAppReleaseWrapper}));
Application application = applicationManager.createApplication(publicAppWrapper, false);
if (application != null && (application.getApplicationReleases().get(0).getCurrentStatus() == null
|| application.getApplicationReleases().get(0).getCurrentStatus().equals("CREATED"))) {
String uuid = application.getApplicationReleases().get(0).getUuid();
LifecycleChanger lifecycleChanger = new LifecycleChanger();
lifecycleChanger.setAction("IN-REVIEW");
applicationManager.changeLifecycleState(uuid, lifecycleChanger);
lifecycleChanger.setAction("APPROVED");
applicationManager.changeLifecycleState(uuid, lifecycleChanger);
lifecycleChanger.setAction("PUBLISHED");
applicationManager.changeLifecycleState(uuid, lifecycleChanger);
}
}
}
}
private static PublicAppReleaseWrapper generatePublicAppReleaseWrapper(ItuneAppDTO product) {
PublicAppReleaseWrapper publicAppReleaseWrapper = new PublicAppReleaseWrapper();
publicAppReleaseWrapper.setDescription(product.getDescription());
publicAppReleaseWrapper.setReleaseType("ga");
publicAppReleaseWrapper.setVersion(product.getVersion());
publicAppReleaseWrapper.setPackageName(product.getPackageName());
publicAppReleaseWrapper.setSupportedOsVersions("4.0-12.3");
publicAppReleaseWrapper.setIconLink(product.getIconURL());
publicAppReleaseWrapper.setRemoteStatus(false);
List<String> screenshotUrls = new ArrayList<>(Collections.nCopies(3, product.getIconURL()));
publicAppReleaseWrapper.setScreenshotLinks(screenshotUrls);
publicAppReleaseWrapper.setPrice(1.0);
return publicAppReleaseWrapper;
}
private static PublicAppWrapper generatePubAppWrapper(ItuneAppDTO product, List<Category> categories) {
PublicAppWrapper publicAppWrapper = new PublicAppWrapper();
publicAppWrapper.setName(product.getTitle());
@ -562,4 +640,77 @@ public class ApplicationManagementUtil {
return sanitizedName;
}
}
public static <T> List<?> deriveApplicationWithoutRelease(T app) {
List<?> releaseWrappers = null;
if (app instanceof ApplicationWrapper) {
ApplicationWrapper applicationWrapper = (ApplicationWrapper) app;
releaseWrappers = applicationWrapper.getEntAppReleaseWrappers();
applicationWrapper.setEntAppReleaseWrappers(Collections.emptyList());
}
if (app instanceof CustomAppWrapper) {
CustomAppWrapper applicationWrapper = (CustomAppWrapper) app;
releaseWrappers = applicationWrapper.getCustomAppReleaseWrappers();
applicationWrapper.setCustomAppReleaseWrappers(Collections.emptyList());
}
return releaseWrappers;
}
/**
* Add installer path metadata value to windows applications
* @param applicationReleaseDTO {@link ApplicationReleaseDTO}
* @throws ApplicationManagementException Throws when error encountered while updating the app metadata
*/
public static void addInstallerPathToMetadata(ApplicationReleaseDTO applicationReleaseDTO)
throws ApplicationManagementException {
if (applicationReleaseDTO.getMetaData() == null) return;
Gson gson = new Gson();
String installerPath = APIUtil.constructInstallerPath(applicationReleaseDTO.getInstallerName(), applicationReleaseDTO.getAppHashValue());
String[] fileNameSegments = extractNameSegments(applicationReleaseDTO, installerPath);
String extension = fileNameSegments[fileNameSegments.length - 1];
if (!Objects.equals(extension, "appx") && !Objects.equals(extension, "msi")) {
return;
}
String installerPaths = "[ {" +
"\"key\": \"Content_Uri\", " +
"\"value\" : \"" + installerPath + "\"" +
"}]";
if (Objects.equals(extension, "appx")) {
installerPaths = "[ {" +
"\"key\": \"Package_Url\", " +
"\"value\" : \"" + installerPath + "\"" +
"}]";
}
JsonArray parsedMetadataList = gson.fromJson(applicationReleaseDTO.getMetaData(), JsonArray.class);
JsonArray installerPathsArray = gson.fromJson(installerPaths, JsonArray.class);
parsedMetadataList.addAll(installerPathsArray);
applicationReleaseDTO.setMetaData(gson.toJson(parsedMetadataList));
}
/**
* Extract name segments from installer path
* @param applicationReleaseDTO {@link ApplicationReleaseDTO}
* @param installerPath Installer path
* @return Extracted file name segments
* @throws ApplicationManagementException Throws when error encountered while extracting name segments from installer path
*/
private static String[] extractNameSegments(ApplicationReleaseDTO applicationReleaseDTO, String installerPath)
throws ApplicationManagementException {
String []installerPathSegments = installerPath.split("/");
if (installerPathSegments.length == 0) {
throw new ApplicationManagementException("Received malformed url for installer path of the app : "
+ applicationReleaseDTO.getInstallerName());
}
String fullQualifiedName = installerPathSegments[installerPathSegments.length - 1];
String []fileNameSegments = fullQualifiedName.split("\\.(?=[^.]+$)");
if (fileNameSegments.length != 2) {
throw new ApplicationManagementException("Received malformed url for installer path of the app : "
+ applicationReleaseDTO.getInstallerName());
}
return fileNameSegments;
}
}

@ -223,4 +223,14 @@ public class Constants {
*/
public static final int MAX_APP_NAME_CHARACTERS = 350;
public static final String APP_NAME_REGEX = "[^a-zA-Z0-9.\\s-]";
public static final String EXTENSION_APK = ".apk";
public static final String EXTENSION_IPA = ".ipa";
public static final String EXTENSION_MSI = ".msi";
public static final String EXTENSION_APPX = ".appx";
public static final String MIME_TYPE_OCTET_STREAM = "application/octet-stream";
public static final String MIME_TYPE_VND_ANDROID_PACKAGE_ARCHIVE = "application/vnd.android.package-archive";
public static final String MIME_TYPE_VND_MS_WINDOWS_MSI = "application/vnd.ms-windows.msi";
public static final String MIME_TYPE_X_MS_INSTALLER = "application/x-ms-installer";
public static final String MIME_TYPE_VND_APPX = "application/vnd.appx";
}

@ -0,0 +1,237 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.core.util;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.application.mgt.common.ChunkDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.FileDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.FileMetaEntry;
import io.entgra.device.mgt.core.application.mgt.core.exception.FileTransferServiceHelperUtilException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.NotFoundException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Objects;
import java.util.UUID;
public class FileTransferServiceHelperUtil {
private static final Log log = LogFactory.getLog(FileTransferServiceHelperUtil.class);
private static final String ROOT = "iot-artifact-holder";
private static final String SYSTEM_PROPERTY_TEMP_DIR = "java.io.tmpdir";
private static final String META_ENTRY_FILE_NAME = ".meta.json";
private static final Gson gson = new Gson();
public static void createDefaultRootStructure() throws FileTransferServiceHelperUtilException {
try {
Path root = Paths.get(System.getProperty(SYSTEM_PROPERTY_TEMP_DIR), ROOT);
if (Files.notExists(root)) {
setMinimumPermissions(Files.createDirectory(root));
}
if (!Files.isDirectory(root)) {
throw new FileTransferServiceHelperUtilException(root.toAbsolutePath() + " is not a directory");
}
setMinimumPermissions(root);
} catch (IOException e) {
String msg = "Error encountered while creating default artifact root structure";
log.error(msg, e);
throw new FileTransferServiceHelperUtilException(msg, e);
}
}
public static Path createNewArtifactHolder(FileMetaEntry fileMetaEntry) throws FileTransferServiceHelperUtilException {
try {
Path artifactHolder = Paths.get(System.getProperty(SYSTEM_PROPERTY_TEMP_DIR), ROOT, UUID.randomUUID().toString());
if (Files.exists(artifactHolder)) {
throw new FileTransferServiceHelperUtilException("Artifact holder already exists in " + artifactHolder);
}
setMinimumPermissions(Files.createDirectory(artifactHolder));
createMetaEntry(fileMetaEntry, artifactHolder);
createArtifactFile(fileMetaEntry, artifactHolder);
return artifactHolder;
} catch (IOException e) {
String msg = "Error occurred while creating artifact holder";
log.error(msg, e);
throw new FileTransferServiceHelperUtilException(msg, e);
}
}
public static void populateChunkDescriptor(String artifactHolder, InputStream chunk, ChunkDescriptor chunkDescriptor)
throws FileTransferServiceHelperUtilException, NotFoundException {
Path holder = locateArtifactHolder(artifactHolder);
Path metaEntry = locateMetaEntry(holder);
chunkDescriptor.setChunk(chunk);
FileDescriptor fileDescriptor = new FileDescriptor();
populateFileDescriptor(metaEntry, holder, fileDescriptor);
chunkDescriptor.setAssociateFileDescriptor(fileDescriptor);
}
public static void populateFileDescriptor(String artifactHolder, FileDescriptor fileDescriptor)
throws FileTransferServiceHelperUtilException, NotFoundException {
Path holder = locateArtifactHolder(artifactHolder);
Path metaEntry = locateMetaEntry(holder);
populateFileDescriptor(metaEntry, holder, fileDescriptor);
}
public static void populateFileDescriptor(Path metaEntry, Path artifactHolder, FileDescriptor fileDescriptor) throws FileTransferServiceHelperUtilException {
try {
byte []metaEntryByteContent = Files.readAllBytes(metaEntry);
FileMetaEntry fileMetaEntry = gson.fromJson(new String(metaEntryByteContent, StandardCharsets.UTF_8), FileMetaEntry.class);
fileDescriptor.setFileName(fileMetaEntry.getFileName());
fileDescriptor.setActualFileSize(fileMetaEntry.getSize());
fileDescriptor.setFullQualifiedName(fileMetaEntry.getFileName() + "." + fileMetaEntry.getExtension());
Path artifact = artifactHolder.resolve(fileDescriptor.getFullQualifiedName());
fileDescriptor.setAbsolutePath(artifact.toAbsolutePath().toString());
fileDescriptor.setExtension(fileMetaEntry.getExtension());
fileDescriptor.setFile(Files.newInputStream(artifact));
} catch (IOException e) {
String msg = "Error encountered while populating chuck descriptor";
log.error(msg, e);
throw new FileTransferServiceHelperUtilException(msg, e);
}
}
private static Path locateArtifactHolder(String artifactHolder) throws FileTransferServiceHelperUtilException, NotFoundException {
Path holder = Paths.get(System.getProperty(SYSTEM_PROPERTY_TEMP_DIR), ROOT, artifactHolder);
if (Files.notExists(holder)) {
throw new NotFoundException(holder.toAbsolutePath() + " is not exists");
}
if (!Files.isDirectory(holder)) {
throw new FileTransferServiceHelperUtilException(holder.toFile().getAbsolutePath() + " is not a directory");
}
return holder;
}
private static Path locateMetaEntry(Path artifactHolder) throws FileTransferServiceHelperUtilException {
Path metaEntry = artifactHolder.resolve(META_ENTRY_FILE_NAME);
if (Files.notExists(metaEntry) || Files.isDirectory(metaEntry)) {
throw new FileTransferServiceHelperUtilException("Can't locate " + META_ENTRY_FILE_NAME);
}
if (!Files.isReadable(metaEntry)) {
throw new FileTransferServiceHelperUtilException("Unreadable " + META_ENTRY_FILE_NAME);
}
return metaEntry;
}
public static void writeChunk(ChunkDescriptor chunkDescriptor) throws FileTransferServiceHelperUtilException {
if (chunkDescriptor == null) {
throw new FileTransferServiceHelperUtilException("Received null for chuck descriptor");
}
FileDescriptor fileDescriptor = chunkDescriptor.getAssociateFileDescriptor();
if (fileDescriptor == null) {
throw new FileTransferServiceHelperUtilException("Target file descriptor is missing for retrieved chunk");
}
Path artifact = Paths.get(fileDescriptor.getAbsolutePath());
try {
InputStream chuckStream = chunkDescriptor.getChunk();
byte []chunk = new byte[chuckStream.available()];
chuckStream.read(chunk);
Files.write(artifact, chunk, StandardOpenOption.CREATE, StandardOpenOption.SYNC, StandardOpenOption.APPEND);
} catch (IOException e) {
String msg = "Error encountered while writing to the " + artifact;
log.error(msg, e);
throw new FileTransferServiceHelperUtilException(msg, e);
}
}
public static FileDescriptor resolve(URL downloadUrl) throws FileTransferServiceHelperUtilException {
if (downloadUrl == null) {
throw new FileTransferServiceHelperUtilException("Received null for download url");
}
if (!Objects.equals(System.getProperty("iot.gateway.host"), downloadUrl.getHost()) &&
!Objects.equals(System.getProperty("iot.core.host"), downloadUrl.getHost())) {
if (log.isDebugEnabled()) {
log.debug("Download URL " + downloadUrl + " contains not matching host");
}
return null;
}
String []urlPathSegments = downloadUrl.getPath().split("/");
if (urlPathSegments.length < 2) {
if (log.isDebugEnabled()) {
log.debug("URL patch segments contain less than 2 segments");
}
return null;
}
String file = urlPathSegments[urlPathSegments.length - 1];
String artifactHolder = urlPathSegments[urlPathSegments.length - 2];
try {
FileDescriptor fileDescriptor = new FileDescriptor();
populateFileDescriptor(artifactHolder, fileDescriptor);
if (!Objects.equals(file, fileDescriptor.getFullQualifiedName())) {
if (log.isDebugEnabled()) {
log.debug("File name not equal to the file exists in the local");
}
return null;
}
return fileDescriptor;
} catch (NotFoundException e) {
if (log.isDebugEnabled()) {
log.debug("Local URL not found in the system");
}
return null;
}
}
private static void setMinimumPermissions(Path path) throws FileTransferServiceHelperUtilException {
File file = path.toFile();
if (!file.setReadable(true, true)) {
throw new FileTransferServiceHelperUtilException("Failed to set read permission for " + file.getAbsolutePath());
}
if (!file.setWritable(true, true)) {
throw new FileTransferServiceHelperUtilException("Failed to set write permission for " + file.getAbsolutePath());
}
}
private static void createMetaEntry(FileMetaEntry fileMetaEntry, Path artifactHolder) throws FileTransferServiceHelperUtilException {
try {
Path metaEntry = artifactHolder.resolve(META_ENTRY_FILE_NAME);
String fileMetaJsonContent = gson.toJson(fileMetaEntry);
Files.write(metaEntry, fileMetaJsonContent.getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE, StandardOpenOption.SYNC);
} catch (IOException e) {
throw new FileTransferServiceHelperUtilException("Error encountered while creating meta entry", e);
}
}
private static void createArtifactFile(FileMetaEntry fileMetaEntry, Path artifactHolder) throws FileTransferServiceHelperUtilException {
try {
Path artifactFile = artifactHolder.resolve(fileMetaEntry.getFileName() + "." + fileMetaEntry.getExtension());
fileMetaEntry.setAbsolutePath(artifactFile.toAbsolutePath().toString());
Files.createFile(artifactFile);
setMinimumPermissions(artifactFile);
} catch (IOException e) {
throw new FileTransferServiceHelperUtilException("Error encountered while creating artifact file", e);
}
}
}

@ -19,8 +19,18 @@ package io.entgra.device.mgt.core.application.mgt.core.management;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationArtifact;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationList;
import io.entgra.device.mgt.core.application.mgt.common.ChunkDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.FileMetaEntry;
import io.entgra.device.mgt.core.application.mgt.common.Filter;
import io.entgra.device.mgt.core.application.mgt.common.LifecycleState;
import io.entgra.device.mgt.core.application.mgt.common.TransferLink;
import io.entgra.device.mgt.core.application.mgt.common.services.FileTransferService;
import io.entgra.device.mgt.core.application.mgt.core.impl.FileTransferServiceImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.RequestValidatingException;
@ -52,6 +62,10 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -98,32 +112,72 @@ public class ApplicationManagementTest extends BaseTestCase {
EntAppReleaseWrapper releaseWrapper = new EntAppReleaseWrapper();
releaseWrapper.setDescription("First release");
releaseWrapper.setIsSharedWithAllTenants(false);
releaseWrapper.setMetaData("Just meta data");
releaseWrapper.setMetaData("[{\"key\": \"Just a metadata\"}]");
releaseWrapper.setReleaseType("free");
releaseWrapper.setPrice(5.7);
releaseWrapper.setSupportedOsVersions("4.0-7.0");
File banner = new File("src/test/resources/samples/app1/banner1.jpg");
File icon = new File("src/test/resources/samples/app1/icon.png");
File ss1 = new File("src/test/resources/samples/app1/shot1.png");
File ss2 = new File("src/test/resources/samples/app1/shot2.png");
File ss3 = new File("src/test/resources/samples/app1/shot3.png");
Base64File bannerBase64 = new Base64File("banner", FileUtil.fileToBase64String(banner));
Base64File iconBase64 = new Base64File("icon", FileUtil.fileToBase64String(icon));
Base64File ss1Base64 = new Base64File("ss1", FileUtil.fileToBase64String(ss1));
Base64File ss2Base64 = new Base64File("ss2", FileUtil.fileToBase64String(ss2));
Base64File ss3Base64 = new Base64File("ss3", FileUtil.fileToBase64String(ss3));
File apk = new File("src/test/resources/samples/app1/sample.apk");
Base64File apkBase64 = new Base64File("apk", FileUtil.fileToBase64String(apk));
releaseWrapper.setBanner(bannerBase64);
releaseWrapper.setIcon(iconBase64);
releaseWrapper.setBinaryFile(apkBase64);
releaseWrapper.setScreenshots(Arrays.asList(ss1Base64, ss2Base64, ss3Base64));
FileTransferService fileTransferService = FileTransferServiceImpl.getInstance();
DataHolder.getInstance().setFileTransferService(fileTransferService);
FileMetaEntry metaEntry = new FileMetaEntry();
TransferLink transferLink;
String []segments;
ChunkDescriptor chunkDescriptor;
metaEntry.setFileName("banner1");
metaEntry.setExtension("jpg");
metaEntry.setSize(179761);
transferLink = fileTransferService.generateUploadLink(metaEntry);
segments = transferLink.getRelativeTransferLink().split("/");
chunkDescriptor = fileTransferService.
resolve(segments[segments.length-1], Files.newInputStream(
Paths.get("src/test/resources/samples/app1/banner1.jpg")));
fileTransferService.writeChunk(chunkDescriptor);
releaseWrapper.setBannerLink(transferLink.getDirectTransferLink() + "/banner1.jpg");
metaEntry.setFileName("icon");
metaEntry.setExtension("png");
metaEntry.setSize(41236);
transferLink = fileTransferService.generateUploadLink(metaEntry);
segments = transferLink.getRelativeTransferLink().split("/");
chunkDescriptor = fileTransferService.
resolve(segments[segments.length-1], Files.newInputStream(
Paths.get("src/test/resources/samples/app1/icon.png")));
fileTransferService.writeChunk(chunkDescriptor);
releaseWrapper.setIconLink(transferLink.getDirectTransferLink() + "/icon.png");
List<String> screenshotPaths = Arrays.asList("src/test/resources/samples/app1/shot1.png",
"src/test/resources/samples/app1/shot2.png", "src/test/resources/samples/app1/shot3.png");
List<String> screenshotLinks = new ArrayList<>();
String []pathSegments;
for (String path: screenshotPaths) {
pathSegments = path.split("/");
String fullQualifiedName = pathSegments[pathSegments.length - 1];
String []nameSegments = fullQualifiedName.split("\\.(?=[^.]+$)");
metaEntry.setFileName(nameSegments[0]);
metaEntry.setExtension(nameSegments[1]);
metaEntry.setSize(41236);
transferLink = fileTransferService.generateUploadLink(metaEntry);
segments = transferLink.getRelativeTransferLink().split("/");
chunkDescriptor = fileTransferService.
resolve(segments[segments.length-1], Files.newInputStream(Paths.get(path)));
fileTransferService.writeChunk(chunkDescriptor);
screenshotLinks.add(transferLink.getDirectTransferLink() + "/" + fullQualifiedName);
}
releaseWrapper.setScreenshotLinks(screenshotLinks);
metaEntry.setFileName("sample");
metaEntry.setExtension("apk");
metaEntry.setSize(6259412);
TransferLink apkTransferLink = fileTransferService.generateUploadLink(metaEntry);
segments = apkTransferLink.getRelativeTransferLink().split("/");
chunkDescriptor = fileTransferService.
resolve(segments[segments.length-1], Files.newInputStream(Paths.get("src/test/resources/samples/app1/sample.apk")));
fileTransferService.writeChunk(chunkDescriptor);
releaseWrapper.setArtifactLink(apkTransferLink.getDirectTransferLink() + "/sample.apk");
releaseWrapper.setRemoteStatus(false);
entAppReleaseWrappers.add(releaseWrapper);
applicationWrapper.setEntAppReleaseWrappers(entAppReleaseWrappers);

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>cea-mgt</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>cea-mgt</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>cea-mgt</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>cea-mgt</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>certificate-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>certificate-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>certificate-mgt</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -116,6 +116,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (ID)
);

@ -140,6 +140,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.41-SNAPSHOT</version>
<version>5.0.42-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -35,6 +35,8 @@ public class BasicUserInfo {
private String createdDate;
@ApiModelProperty(name = "modifiedDate", value = "User modifiedDate date." )
private String modifiedDate;
@ApiModelProperty(name = "isRemovable", value = "User's removable status." )
private boolean isRemovable;
public String getUsername() {
return username;
@ -84,4 +86,11 @@ public class BasicUserInfo {
this.modifiedDate = modifiedDate;
}
public boolean isRemovable() {
return isRemovable;
}
public void setRemovable(boolean removable) {
isRemovable = removable;
}
}

@ -0,0 +1,181 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAuthorizationRequest;
import io.entgra.device.mgt.core.device.mgt.common.authorization.GroupAuthorizationRequest;
import io.entgra.device.mgt.core.device.mgt.common.authorization.GroupAuthorizationResult;
import io.swagger.annotations.*;
import org.apache.axis2.transport.http.HTTPConstants;
import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "AccessAuthorizationService"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/access"),
})
}
),
tags = {
@Tag(name = "device_management", description = "")
}
)
@Path("/access")
@Api(value = "AccessAuthorizationService", description = "This API carries all device group management related " +
"access authorization")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface AccessAuthorizationService {
@POST
@Path("/device")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_GET,
value = "check device access authorization",
notes = "Returns device access acutorization info",
tags = "device_management"
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "Created. \n Device group has successfully been created",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The URL of the added group."),
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time" +
".\n" + "Used by caches, or in conditional requests.")
}
),
@ApiResponse(
code = 303,
message = "See Other. \n Source can be retrieved from the URL specified at the Location " +
"header.",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The Source URL of the document.")}),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 401,
message = "Unauthorized. \n Current logged in user is not authorized for this request",
response = ErrorResponse.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported " +
"format."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while checking access",
response = ErrorResponse.class)
})
Response checkDeviceAccess(
@ApiParam(
name = "deviceAccessRequest",
value = "Define the device access request object with data.",
required = true)
@Valid DeviceAuthorizationRequest deviceAuthorizationRequest);
@POST
@Path("/group")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_GET,
value = "check device access authorization",
notes = "Returns device access acutorization info",
tags = "device_management"
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "Created. \n Device group has successfully been created",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The URL of the added group."),
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time" +
".\n" + "Used by caches, or in conditional requests.")
}
),
@ApiResponse(
code = 303,
message = "See Other. \n Source can be retrieved from the URL specified at the Location " +
"header.",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The Source URL of the document.")}),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 401,
message = "Unauthorized. \n Current logged in user is not authorized for this request",
response = ErrorResponse.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported " +
"format."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while checking access",
response = ErrorResponse.class)
})
Response checkGroupAccess(
@ApiParam(
name = "groupAccessRequest",
value = "Define the group access request object with data.",
required = true)
@Valid GroupAuthorizationRequest request);
}

@ -473,7 +473,7 @@ public interface ActivityInfoProviderService {
name = "status",
value = "Operation response status to filter"
)
@QueryParam("status") String status,
@QueryParam("status") List<String> statuses,
@ApiParam(
name = "If-Modified-Since",
value = "Checks if the requested variant was modified, since the specified date-time\n." +
@ -597,7 +597,7 @@ public interface ActivityInfoProviderService {
name = "status",
value = "Operation response status to filter"
)
@QueryParam("status") String status,
@QueryParam("status") List<String> statuses,
@ApiParam(
name = "If-Modified-Since",
value = "Checks if the requested variant was modified, since the specified date-time\n." +

@ -61,6 +61,13 @@ import javax.ws.rs.core.Response;
key = "um:admin:users:remove",
roles = {"Internal/devicemgt-admin"},
permissions = {"/device-mgt/admin/users/delete"}
),
@Scope(
name = "Delete Tenant Information",
description = "Delete tenant details",
key = "um:admin:tenants:remove",
roles = {"Internal/devicemgt-admin"},
permissions = {"/device-mgt/admin/tenants/delete"}
)
}
)
@ -258,5 +265,41 @@ public interface UserManagementAdminService {
@Size(max = 45)
String deviceId);
@DELETE
@Path("/domain/{tenantDomain}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "DELETE",
value = "Delete a tenant by tenant domain.",
notes = "This API allows the deletion of a tenant by providing the tenant domain.",
tags = "Tenant details remove",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "um:admin:tenants:remove")
})
}
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Tenant has been deleted successfully."),
@ApiResponse(
code = 404,
message = "Not Found. \n The tenant with the provided domain does not exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while removing the tenant.",
response = ErrorResponse.class)
})
Response deleteTenantByDomain(
@ApiParam(
name = "tenantDomain",
value = "The domain of the tenant to be deleted.",
required = true)
@PathParam("tenantDomain")
String tenantDomain);
}

@ -0,0 +1,95 @@
/*
* Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.AccessAuthorizationService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.authorization.*;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
public class AccessAuthorizationServiceImpl implements AccessAuthorizationService {
private static final Log log = LogFactory.getLog(AccessAuthorizationServiceImpl.class);
@Override
public Response checkDeviceAccess(DeviceAuthorizationRequest deviceAuthorizationRequest) {
if (StringUtils.isEmpty(deviceAuthorizationRequest.getType())) {
String msg = "device type not specified";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
if (deviceAuthorizationRequest.getDeviceIds().isEmpty()) {
String msg = "device ids not specified";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
if (deviceAuthorizationRequest.getPermissions().isEmpty()) {
String msg = "permissions not specified";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
for(String id : deviceAuthorizationRequest.getDeviceIds()) {
DeviceIdentifier identifier = new DeviceIdentifier(id, deviceAuthorizationRequest.getType());
deviceIdentifiers.add(identifier);
}
try {
DeviceAuthorizationResult result = DeviceMgtAPIUtils.getDeviceAccessAuthorizationService()
.isUserAuthorized(deviceIdentifiers, deviceAuthorizationRequest.getUsername(),
deviceAuthorizationRequest.getPermissions().toArray(new String[0]));
return Response.status(Response.Status.OK).entity(result).build();
} catch (DeviceAccessAuthorizationException e) {
String msg = "Error occurred while checking access info";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
public Response checkGroupAccess(GroupAuthorizationRequest request) {
if (request.getGroupIds().isEmpty()) {
String msg = "group ids not specified";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
if (request.getPermissions().isEmpty()) {
String msg = "permissions not specified";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
try {
GroupAuthorizationResult result = DeviceMgtAPIUtils.getGroupAccessAuthorizationService()
.isUserAuthorized(request.getGroupIds(), request.getUsername(),
request.getPermissions().toArray(new String[0]));
return Response.status(Response.Status.OK).entity(result).build();
} catch (GroupAccessAuthorizationException e) {
String msg = "Error occurred while checking access info";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -43,6 +43,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -252,7 +253,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
@QueryParam("deviceType") String deviceType,
@QueryParam("deviceId") List<String> deviceIds,
@QueryParam("type") String type,
@QueryParam("status") String status,
@QueryParam("status") List<String> statuses,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("startTimestamp") long startTimestamp,
@QueryParam("endTimestamp") long endTimestamp) {
@ -329,8 +330,12 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
if (type != null && !type.isEmpty()) {
activityPaginationRequest.setType(Operation.Type.valueOf(type.toUpperCase()));
}
if (status != null && !status.isEmpty()) {
activityPaginationRequest.setStatus(Operation.Status.valueOf(status.toUpperCase()));
if (statuses != null && !statuses.isEmpty()) {
List<Operation.Status> statusEnums = new ArrayList<>();
for (String status : statuses) {
statusEnums.add(Operation.Status.valueOf(status.toUpperCase()));
}
activityPaginationRequest.setStatuses(statusEnums);
}
if (timestamp > 0) {
activityPaginationRequest.setSince(timestamp);
@ -375,7 +380,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
@QueryParam("deviceType") String deviceType,
@QueryParam("deviceId") List<String> deviceIds,
@QueryParam("type") String type,
@QueryParam("status") String status,
@QueryParam("status") List<String> statuses,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("startTimestamp") long startTimestamp,
@QueryParam("endTimestamp") long endTimestamp) {
@ -450,8 +455,12 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
if (type != null && !type.isEmpty()) {
activityPaginationRequest.setType(Operation.Type.valueOf(type.toUpperCase()));
}
if (status != null && !status.isEmpty()) {
activityPaginationRequest.setStatus(Operation.Status.valueOf(status.toUpperCase()));
if (statuses != null && !statuses.isEmpty()) {
List<Operation.Status> statusEnums = new ArrayList<>();
for (String status : statuses) {
statusEnums.add(Operation.Status.valueOf(status.toUpperCase()));
}
activityPaginationRequest.setStatuses(statusEnums);
}
if (timestamp > 0) {
activityPaginationRequest.setSince(timestamp);

@ -28,6 +28,11 @@ import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.analytics.EventAttri
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.DeviceAgentService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import io.entgra.device.mgt.core.device.mgt.core.permission.mgt.PermissionManagerServiceImpl;
import org.apache.axis2.AxisFault;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
@ -161,7 +166,9 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
DeviceMgtAPIUtils.getDeviceAccessAuthorizationService();
boolean status;
try {
status = deviceAccessAuthorizationService.isUserAuthorized(new DeviceIdentifier(id, type));
String requiredPermission = PermissionManagerServiceImpl.getInstance().getRequiredPermission();
String[] requiredPermissions = new String[] {requiredPermission};
status = deviceAccessAuthorizationService.isUserAuthorized(new DeviceIdentifier(id, type), requiredPermissions);
} catch (DeviceAccessAuthorizationException e) {
String msg = "Error occurred while modifying enrollment of the Android device that carries the id '" +
id + "'";
@ -223,8 +230,10 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
String msg = "invalid payload structure";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} else {
String requiredPermission = PermissionManagerServiceImpl.getInstance().getRequiredPermission();
String[] requiredPermissions = new String[] {requiredPermission};
boolean authorized = DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized
(new DeviceIdentifier(type, deviceId));
(new DeviceIdentifier(type, deviceId), requiredPermissions);
if (!authorized) {
String msg = "Does not have permission to access the device.";
return Response.status(Response.Status.UNAUTHORIZED).entity(msg).build();
@ -323,8 +332,10 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
String msg = "Invalid payload structure";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} else {
String requiredPermission = PermissionManagerServiceImpl.getInstance().getRequiredPermission();
String[] requiredPermissions = new String[] {requiredPermission};
boolean authorized = DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized
(new DeviceIdentifier(type, deviceId));
(new DeviceIdentifier(type, deviceId), requiredPermissions);
if (!authorized) {
String msg = "Does not have permission to access the device.";
return Response.status(Response.Status.UNAUTHORIZED).entity(msg).build();

@ -43,6 +43,7 @@ import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionMan
import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.DisenrollRequest;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtUtil;
import io.entgra.device.mgt.core.device.mgt.core.permission.mgt.PermissionManagerServiceImpl;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
@ -589,7 +590,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, type);
// check whether the user is authorized
if (!deviceAccessAuthorizationService.isUserAuthorized(deviceIdentifier, authorizedUser)) {
String requiredPermission = PermissionManagerServiceImpl.getInstance().getRequiredPermission();
String[] requiredPermissions = new String[] {requiredPermission};
if (!deviceAccessAuthorizationService.isUserAuthorized(deviceIdentifier, authorizedUser, requiredPermissions)) {
String msg = "User '" + authorizedUser + "' is not authorized to retrieve the given device id '" + id + "'";
log.error(msg);
return Response.status(Response.Status.UNAUTHORIZED).entity(
@ -725,7 +728,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
}
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, device.getType());
// check whether the user is authorized
if (!deviceAccessAuthorizationService.isUserAuthorized(deviceIdentifier, authorizedUser)) {
String requiredPermission = PermissionManagerServiceImpl.getInstance().getRequiredPermission();
String[] requiredPermissions = new String[] {requiredPermission};
if (!deviceAccessAuthorizationService.isUserAuthorized(deviceIdentifier, authorizedUser, requiredPermissions)) {
String message = "User '" + authorizedUser + "' is not authorized to retrieve the given " +
"device id '" + id + "'";
log.error(message);

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.core.permission.mgt.PermissionManagerServiceImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -96,7 +97,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
String username = threadLocalCarbonContext.getUsername();
try {
if (!deviceAccessAuthorizationService.isUserAuthorized(deviceIdentifier, username)) {
String requiredPermission = PermissionManagerServiceImpl.getInstance().getRequiredPermission();
String[] requiredPermissions = new String[] {requiredPermission};
if (!deviceAccessAuthorizationService.isUserAuthorized(deviceIdentifier, username, requiredPermissions)) {
return Response.status(Response.Status.UNAUTHORIZED).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage
("Current logged in user is not authorized to add policies").build()).build();

@ -243,7 +243,7 @@ public class UserManagementServiceImpl implements UserManagementService {
BasicUserInfo user = this.getBasicUserInfo(username);
return Response.status(Response.Status.OK).entity(user).build();
} catch (UserStoreException e) {
} catch (UserStoreException | DeviceManagementException e) {
String msg = "Error occurred while retrieving information of the user '" + username + "'";
log.error(msg, e);
return Response.serverError().entity(
@ -325,7 +325,7 @@ public class UserManagementServiceImpl implements UserManagementService {
BasicUserInfo updatedUserInfo = this.getBasicUserInfo(username);
return Response.ok().entity(updatedUserInfo).build();
} catch (UserStoreException e) {
} catch (UserStoreException | DeviceManagementException e) {
String msg = "Error occurred while trying to update user '" + username + "'";
log.error(msg, e);
return Response.serverError().entity(
@ -486,7 +486,7 @@ public class UserManagementServiceImpl implements UserManagementService {
result.setCount(userList.size());
return Response.status(Response.Status.OK).entity(result).build();
} catch (UserStoreException e) {
} catch (UserStoreException | DeviceManagementException e) {
String msg = "Error occurred while retrieving the list of users.";
log.error(msg, e);
return Response.serverError().entity(
@ -565,6 +565,7 @@ public class UserManagementServiceImpl implements UserManagementService {
basicUserInfo.setEmailAddress(getClaimValue(user, Constants.USER_CLAIM_EMAIL_ADDRESS));
basicUserInfo.setFirstname(getClaimValue(user, Constants.USER_CLAIM_FIRST_NAME));
basicUserInfo.setLastname(getClaimValue(user, Constants.USER_CLAIM_LAST_NAME));
basicUserInfo.setRemovable(isUserRemovable(user));
filteredUserList.add(basicUserInfo);
}
}
@ -589,7 +590,7 @@ public class UserManagementServiceImpl implements UserManagementService {
result.setCount(commonUsers != null ? commonUsers.size() : 0);
return Response.status(Response.Status.OK).entity(result).build();
} catch (UserStoreException e) {
} catch (UserStoreException | DeviceManagementException e) {
String msg = "Error occurred while retrieving the list of users.";
log.error(msg, e);
return Response.serverError().entity(
@ -1240,7 +1241,7 @@ public class UserManagementServiceImpl implements UserManagementService {
return initialUserPassword.toString();
}
private BasicUserInfo getBasicUserInfo(String username) throws UserStoreException {
private BasicUserInfo getBasicUserInfo(String username) throws UserStoreException, DeviceManagementException {
BasicUserInfo userInfo = new BasicUserInfo();
userInfo.setUsername(username);
userInfo.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
@ -1248,9 +1249,21 @@ public class UserManagementServiceImpl implements UserManagementService {
userInfo.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
userInfo.setCreatedDate(getClaimValue(username, Constants.USER_CLAIM_CREATED));
userInfo.setModifiedDate(getClaimValue(username, Constants.USER_CLAIM_MODIFIED));
userInfo.setRemovable(isUserRemovable(username));
return userInfo;
}
/**
* Check if the user can be removed or not
* @param username Username of the user
* @return True when user can be removed, otherwise false
* @throws DeviceManagementException Throws when error occurred while getting device count
*/
private boolean isUserRemovable(String username) throws DeviceManagementException {
DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService();
return deviceManagementProviderService.getDeviceCount(username.contains("/") ? username.split("/")[1] : username) == 0;
}
private String getClaimValue(String username, String claimUri) throws UserStoreException {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
return userStoreManager.getUserClaimValue(username, claimUri, null);

@ -172,6 +172,9 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ
if (group == null) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
if (StringUtils.isEmpty(group.getOwner())) {
group.setOwner(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
}
group.setStatus(DeviceGroupConstants.GroupStatus.ACTIVE);
try {
DeviceMgtAPIUtils.getGroupManagementProviderService().createGroup(group, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);

@ -17,14 +17,21 @@
*/
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.admin;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.PrivacyComplianceException;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.PasswordResetWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.admin.UserManagementAdminService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.CredentialManagementResponseBuilder;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.PrivacyComplianceException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.stratos.common.exception.StratosException;
import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService;
import org.wso2.carbon.user.api.UserStoreException;
import javax.validation.constraints.Size;
import javax.ws.rs.*;
@ -81,4 +88,38 @@ public class UserManagementAdminServiceImpl implements UserManagementAdminServic
}
}
@DELETE
@Path("/domain/{tenantDomain}")
@Override
public Response deleteTenantByDomain(@PathParam("tenantDomain") String tenantDomain) {
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
if (tenantId != MultitenantConstants.SUPER_TENANT_ID){
String msg = "Only super tenants are allowed to delete tenants";
log.error(msg);
return Response.status(Response.Status.UNAUTHORIZED).entity(msg).build();
} else {
DeviceMgtAPIUtils.getApplicationManager().deleteApplicationDataByTenantDomain(tenantDomain);
DeviceMgtAPIUtils.getDeviceManagementService().deleteDeviceDataByTenantDomain(tenantDomain);
TenantMgtAdminService tenantMgtAdminService = new TenantMgtAdminService();
tenantMgtAdminService.deleteTenant(tenantDomain);
String msg = "Tenant Deletion process has been initiated for tenant:" + tenantDomain;
return Response.status(Response.Status.OK).entity(msg).build();
}
} catch (StratosException | UserStoreException e) {
String msg = "Error deleting tenant: " + tenantDomain;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error deleting application data of tenant: " + tenantDomain;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (DeviceManagementException e) {
String msg = "Error deleting device data of tenant: " + tenantDomain;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save