forked from community/device-mgt-core
Merge pull request #903 from Megala21/appm_new
Adding Application Release Management related changes.feature/appm-store/pbac
commit
98ff1179da
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.application.mgt.api;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.StreamingOutput;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileStreamingOutput to allow the user to send the files as Stream.
|
||||||
|
*/
|
||||||
|
public class FileStreamingOutput implements StreamingOutput {
|
||||||
|
private InputStream inputStream;
|
||||||
|
|
||||||
|
public FileStreamingOutput(InputStream inputStream) {
|
||||||
|
this.inputStream = inputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
|
||||||
|
try {
|
||||||
|
byte[] buffer = new byte[inputStream.available()];
|
||||||
|
inputStream.read(buffer);
|
||||||
|
outputStream.write(buffer);
|
||||||
|
outputStream.flush();
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
if (outputStream != null) {
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.application.mgt.api;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.jaxrs.AnnotationExclusionStrategy;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
import javax.ws.rs.ext.MessageBodyReader;
|
||||||
|
import javax.ws.rs.ext.Provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider for the text/plain type of input. Particularly use-ful for the complex objects sent along with Multipart
|
||||||
|
* request.
|
||||||
|
*/
|
||||||
|
@Provider
|
||||||
|
@Consumes(MediaType.TEXT_PLAIN)
|
||||||
|
public class MultipartCustomProvider implements MessageBodyReader<Object> {
|
||||||
|
private Gson gson;
|
||||||
|
|
||||||
|
public MultipartCustomProvider() {
|
||||||
|
final GsonBuilder gsonBuilder = new GsonBuilder().setDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz")
|
||||||
|
.setExclusionStrategies(new AnnotationExclusionStrategy());
|
||||||
|
gson = gsonBuilder.create();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
|
||||||
|
return !aClass.equals(Attachment.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object readFrom(Class<Object> objectClass, Type type, Annotation[] annotations, MediaType mediaType,
|
||||||
|
MultivaluedMap<String, String> headers, InputStream inputStream) throws IOException,
|
||||||
|
WebApplicationException {
|
||||||
|
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int length;
|
||||||
|
while ((length = inputStream.read(buffer)) != -1) {
|
||||||
|
result.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
String jsonString = result.toString();
|
||||||
|
JsonObject obj = new JsonParser().parse(jsonString).getAsJsonObject();
|
||||||
|
return gson.fromJson(obj, type);
|
||||||
|
}
|
||||||
|
}
|
13
components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationUploadManager.java → components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationStorageManagementException.java
13
components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationUploadManager.java → components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationStorageManagementException.java
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.application.mgt.common.services;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This manages all the storage related requirements of Application.
|
||||||
|
*/
|
||||||
|
public interface ApplicationStorageManager {
|
||||||
|
/**
|
||||||
|
* To upload image artifacts related with an Application.
|
||||||
|
*
|
||||||
|
* @param applicationUUID UUID of the application
|
||||||
|
* @param iconFile Icon File input stream
|
||||||
|
* @param bannerFile Banner File input stream
|
||||||
|
* @throws ApplicationStorageManagementException Application Storage Management Exception.
|
||||||
|
*/
|
||||||
|
public void uploadImageArtifacts(String applicationUUID, InputStream iconFile, InputStream bannerFile,
|
||||||
|
List<InputStream> screenshots) throws ApplicationStorageManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To upload release artifacts for an Application.
|
||||||
|
* @param applicationUUID UUID of the application related with the release.
|
||||||
|
* @param versionName Name of version of the Applcation Release.
|
||||||
|
* @param binaryFile Binary File for the release.
|
||||||
|
* @throws ApplicationStorageManagementException Application Storage Management Exception.
|
||||||
|
*/
|
||||||
|
public void uploadReleaseArtifacts(String applicationUUID, String versionName, InputStream binaryFile) throws
|
||||||
|
ApplicationStorageManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To get released artifacts for the particular version of the application.
|
||||||
|
* @param applicationUUID UUID of the Application
|
||||||
|
* @param versionName Version of the release to be retrieved
|
||||||
|
* @return the artifact related with the Application Release.
|
||||||
|
* @throws ApplicationStorageManagementException Application Storage Management Exception.
|
||||||
|
*/
|
||||||
|
public InputStream getReleasedArtifacts(String applicationUUID, String versionName) throws
|
||||||
|
ApplicationStorageManagementException;
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.application.mgt.core.config;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This represents Artifacts element in application-mgt configuration file.
|
||||||
|
*/
|
||||||
|
@XmlRootElement(name = "Artifacts")
|
||||||
|
public class Artifacts {
|
||||||
|
private String imageLocation;
|
||||||
|
private String binaryLocation;
|
||||||
|
|
||||||
|
@XmlElement(name = "ImageLocation", required = true)
|
||||||
|
public String getImageLocation() {
|
||||||
|
return imageLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageLocation(String imageLocation) {
|
||||||
|
this.imageLocation = imageLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "BinaryLocation", required = true)
|
||||||
|
public String getBinaryLocation() {
|
||||||
|
return binaryLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBinaryLocation(String binaryLocation) {
|
||||||
|
this.binaryLocation = binaryLocation;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,208 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.application.mgt.core.dao.impl.application.release;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GenericApplicationReleaseDAOImpl holds the implementation of ApplicationRelease related DAO operations.
|
||||||
|
*/
|
||||||
|
public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements ApplicationReleaseDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApplicationRelease createRelease(ApplicationRelease applicationRelease) throws
|
||||||
|
ApplicationManagementDAOException {
|
||||||
|
Connection connection;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
String sql = "insert into APPM_APPLICATION_RELEASE(VERSION_NAME, RESOURCE, RELEASE_CHANNEL ,"
|
||||||
|
+ "RELEASE_DETAILS, CREATED_AT, APPM_APPLICATION_ID, IS_DEFAULT) values (?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
int index = 0;
|
||||||
|
boolean isBatchExecutionSupported = ConnectionManagerUtil.isBatchQuerySupported();
|
||||||
|
|
||||||
|
try {
|
||||||
|
connection = this.getDBConnection();
|
||||||
|
statement = connection.prepareStatement(sql);
|
||||||
|
statement.setString(++index, applicationRelease.getVersionName());
|
||||||
|
statement.setString(++index, applicationRelease.getResource());
|
||||||
|
statement.setString(++index, String.valueOf(applicationRelease.getReleaseChannel()));
|
||||||
|
statement.setString(++index, applicationRelease.getReleaseDetails());
|
||||||
|
statement.setDate(++index, new Date(applicationRelease.getCreatedAt().getTime()));
|
||||||
|
statement.setInt(++index, applicationRelease.getApplication().getId());
|
||||||
|
statement.setBoolean(++index, applicationRelease.isDefault());
|
||||||
|
statement.executeUpdate();
|
||||||
|
resultSet = statement.getGeneratedKeys();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
applicationRelease.setId(resultSet.getInt(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (applicationRelease.getProperties() != null && applicationRelease.getProperties().size() != 0) {
|
||||||
|
sql = "INSERT INTO APPM_RELEASE_PROPERTY (PROP_KEY, PROP_VALUE, APPLICATION_RELEASE_ID) VALUES (?,?,?)";
|
||||||
|
statement = connection.prepareStatement(sql);
|
||||||
|
for (Object entry : applicationRelease.getProperties().entrySet()) {
|
||||||
|
Map.Entry<String, String> property = (Map.Entry) entry;
|
||||||
|
statement.setString(1, property.getKey());
|
||||||
|
statement.setString(2, property.getValue());
|
||||||
|
statement.setInt(3, applicationRelease.getId());
|
||||||
|
if (isBatchExecutionSupported) {
|
||||||
|
statement.addBatch();
|
||||||
|
} else {
|
||||||
|
statement.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isBatchExecutionSupported) {
|
||||||
|
statement.executeBatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return applicationRelease;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new ApplicationManagementDAOException(
|
||||||
|
"SQL Exception while trying to release an application (UUID : " + applicationRelease
|
||||||
|
.getApplication().getUuid() + "), by executing the query " + sql, e);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
throw new ApplicationManagementDAOException(
|
||||||
|
"Database Connection Exception while trying to release the " + "applcation with UUID "
|
||||||
|
+ applicationRelease.getApplication().getUuid(), e);
|
||||||
|
} finally {
|
||||||
|
Util.cleanupResources(statement, resultSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApplicationRelease getRelease(String applicationUuid, String versionName)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
Connection connection;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
String sql = "SELECT * FROM APPM_APPLICATION_RELEASE WHERE VERSION_NAME = ? AND APPM_APPLICATION_ID = "
|
||||||
|
+ "(SELECT ID FROM APPM_APPLICATION WHERE UUID = ?)";
|
||||||
|
ApplicationRelease applicationRelease = null;
|
||||||
|
ResultSet rsProperties = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
connection = this.getDBConnection();
|
||||||
|
statement = connection.prepareStatement(sql);
|
||||||
|
statement.setString(1, versionName);
|
||||||
|
statement.setString(2, applicationUuid);
|
||||||
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
|
if (resultSet.next()) {
|
||||||
|
applicationRelease = new ApplicationRelease();
|
||||||
|
applicationRelease.setVersionName(versionName);
|
||||||
|
applicationRelease.setDefault(resultSet.getBoolean("IS_DEFAULT"));
|
||||||
|
applicationRelease.setCreatedAt(resultSet.getDate("CREATED_AT"));
|
||||||
|
applicationRelease.setReleaseChannel(resultSet.getString("RELEASE_CHANNEL"));
|
||||||
|
applicationRelease.setReleaseDetails(resultSet.getString("RELEASE_DETAILS"));
|
||||||
|
applicationRelease.setResource(resultSet.getString("RESOURCE"));
|
||||||
|
|
||||||
|
sql = "SELECT * FROM APPM_RELEASE_PROPERTY WHERE APPLICATION_RELEASE_ID=?";
|
||||||
|
statement = connection.prepareStatement(sql);
|
||||||
|
statement.setInt(1, resultSet.getInt("ID"));
|
||||||
|
rsProperties = statement.executeQuery();
|
||||||
|
|
||||||
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
while (rsProperties.next()) {
|
||||||
|
properties.put(rsProperties.getString("PROP_KEY"),
|
||||||
|
rsProperties.getString("PROP_VAL"));
|
||||||
|
}
|
||||||
|
applicationRelease.setProperties(properties);
|
||||||
|
}
|
||||||
|
return applicationRelease;
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
throw new ApplicationManagementDAOException("Database connection exception while trying to gett the "
|
||||||
|
+ "release details of the application with UUID " + applicationUuid + " and version " +
|
||||||
|
versionName, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new ApplicationManagementDAOException("Error while getting release details of the application " +
|
||||||
|
applicationUuid + " and version " + versionName + " , while executing the query " + sql, e);
|
||||||
|
} finally {
|
||||||
|
Util.cleanupResources(statement, resultSet);
|
||||||
|
Util.cleanupResources(null, rsProperties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ApplicationRelease> getApplicationReleases(String applicationUUID)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
Connection connection;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
String sql = "SELECT * FROM APPM_APPLICATION_RELEASE WHERE APPM_APPLICATION_ID = (SELECT ID FROM "
|
||||||
|
+ "APPM_APPLICATION WHERE UUID = ?)";
|
||||||
|
List<ApplicationRelease> applicationReleases = new ArrayList<>();
|
||||||
|
ResultSet rsProperties = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
connection = this.getDBConnection();
|
||||||
|
statement = connection.prepareStatement(sql);
|
||||||
|
statement.setString(1, applicationUUID);
|
||||||
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
ApplicationRelease applicationRelease = new ApplicationRelease();
|
||||||
|
applicationRelease.setVersionName(resultSet.getString("VERSION_NAME"));
|
||||||
|
applicationRelease.setDefault(resultSet.getBoolean("IS_DEFAULT"));
|
||||||
|
applicationRelease.setCreatedAt(resultSet.getDate("CREATED_AT"));
|
||||||
|
applicationRelease.setReleaseChannel(resultSet.getString("RELEASE_CHANNEL"));
|
||||||
|
applicationRelease.setReleaseDetails(resultSet.getString("RELEASE_DETAILS"));
|
||||||
|
applicationRelease.setResource(resultSet.getString("RESOURCE"));
|
||||||
|
|
||||||
|
sql = "SELECT * FROM APPM_RELEASE_PROPERTY WHERE APPLICATION_RELEASE_ID= ?";
|
||||||
|
statement = connection.prepareStatement(sql);
|
||||||
|
statement.setInt(1, resultSet.getInt("ID"));
|
||||||
|
rsProperties = statement.executeQuery();
|
||||||
|
|
||||||
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
while (rsProperties.next()) {
|
||||||
|
properties.put(rsProperties.getString("PROP_KEY"), rsProperties.getString("PROP_VAL"));
|
||||||
|
}
|
||||||
|
applicationRelease.setProperties(properties);
|
||||||
|
applicationReleases.add(applicationRelease);
|
||||||
|
}
|
||||||
|
return applicationReleases;
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
throw new ApplicationManagementDAOException("Database connection exception while trying to get the "
|
||||||
|
+ "release details of the application with UUID " + applicationUUID, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new ApplicationManagementDAOException(
|
||||||
|
"Error while getting all the release details of the " + "application " + applicationUUID
|
||||||
|
+ ", while executing the query " + sql, e);
|
||||||
|
} finally {
|
||||||
|
Util.cleanupResources(statement, resultSet);
|
||||||
|
Util.cleanupResources(null, rsProperties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,219 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.application.mgt.core.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.Application;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.util.Constants;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class contains the default concrete implementation of ApplicationStorage Management.
|
||||||
|
*/
|
||||||
|
public class ApplicationStorageManagerImpl implements ApplicationStorageManager {
|
||||||
|
private static final Log log = LogFactory.getLog(ApplicationStorageManagerImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void uploadImageArtifacts(String applicationUUID, InputStream iconFileStream, InputStream bannerFileStream,
|
||||||
|
List<InputStream> screenShotStreams) throws ApplicationStorageManagementException {
|
||||||
|
Application application;
|
||||||
|
try {
|
||||||
|
application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID);
|
||||||
|
} catch (ApplicationManagementException e) {
|
||||||
|
throw new ApplicationStorageManagementException(
|
||||||
|
"Exception while retrieving the application details for " + "the application with UUID "
|
||||||
|
+ applicationUUID);
|
||||||
|
}
|
||||||
|
if (application == null) {
|
||||||
|
throw new ApplicationStorageManagementException("Application with UUID " + applicationUUID + " does not "
|
||||||
|
+ "exist. Cannot upload the artifacts to non-existing application.");
|
||||||
|
}
|
||||||
|
String artifactDirectoryPath = Constants.artifactPath + application.getId();
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Artifact Directory Path for saving the artifacts related with application " + applicationUUID
|
||||||
|
+ " is " + artifactDirectoryPath);
|
||||||
|
}
|
||||||
|
createArtifactDirectory(artifactDirectoryPath);
|
||||||
|
if (iconFileStream != null) {
|
||||||
|
String iconName = application.getIconName();
|
||||||
|
iconName = (iconName == null) ? "icon" : iconName;
|
||||||
|
try {
|
||||||
|
saveFile(iconFileStream, artifactDirectoryPath + File.separator + iconName);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ApplicationStorageManagementException(
|
||||||
|
"IO Exception while saving the icon file in the server for " + "the application "
|
||||||
|
+ applicationUUID, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bannerFileStream != null) {
|
||||||
|
String bannerName = application.getBannerName();
|
||||||
|
bannerName = (bannerName == null) ? "banner" : bannerName;
|
||||||
|
try {
|
||||||
|
saveFile(bannerFileStream, artifactDirectoryPath + File.separator + bannerName);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ApplicationStorageManagementException(
|
||||||
|
"IO Exception while saving the banner file in the server for" + " the application "
|
||||||
|
+ applicationUUID, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (screenShotStreams != null) {
|
||||||
|
int count = 1;
|
||||||
|
String screenshotName;
|
||||||
|
List<String> screenShotNames = application.getScreenshots();
|
||||||
|
boolean isScreenShotNameExist = (screenShotNames == null || screenShotNames.isEmpty());
|
||||||
|
int screenShotNameLength = isScreenShotNameExist ? screenShotNames.size() : 0;
|
||||||
|
for (InputStream screenshotStream : screenShotStreams) {
|
||||||
|
try {
|
||||||
|
if (isScreenShotNameExist && count <= screenShotNameLength) {
|
||||||
|
screenshotName = screenShotNames.get(count);
|
||||||
|
} else {
|
||||||
|
screenshotName = "screenshot_" + count;
|
||||||
|
}
|
||||||
|
saveFile(screenshotStream, artifactDirectoryPath + File.separator + screenshotName);
|
||||||
|
count++;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ApplicationStorageManagementException(
|
||||||
|
"IO Exception while saving the screens hots for the " + "application " + applicationUUID,
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void uploadReleaseArtifacts(String applicationUUID, String versionName, InputStream binaryFile)
|
||||||
|
throws ApplicationStorageManagementException {
|
||||||
|
Application application;
|
||||||
|
try {
|
||||||
|
application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID);
|
||||||
|
} catch (ApplicationManagementException e) {
|
||||||
|
throw new ApplicationStorageManagementException("Exception while retrieving the application details for "
|
||||||
|
+ "the application with UUID " + applicationUUID);
|
||||||
|
}
|
||||||
|
if (application == null) {
|
||||||
|
throw new ApplicationStorageManagementException("Application with UUID " + applicationUUID + " does not "
|
||||||
|
+ "exist. Cannot upload release artifacts for not existing application.");
|
||||||
|
}
|
||||||
|
String artifactDirectoryPath = Constants.artifactPath + application.getId();
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Artifact Directory Path for saving the application release related artifacts related with "
|
||||||
|
+ "application " + applicationUUID + " is " + artifactDirectoryPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
createArtifactDirectory(artifactDirectoryPath);
|
||||||
|
if (binaryFile != null) {
|
||||||
|
try {
|
||||||
|
saveFile(binaryFile, artifactDirectoryPath + File.separator + versionName);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ApplicationStorageManagementException(
|
||||||
|
"IO Exception while saving the release artifacts in the server for the application "
|
||||||
|
+ applicationUUID, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getReleasedArtifacts(String applicationUUID, String versionName)
|
||||||
|
throws ApplicationStorageManagementException {
|
||||||
|
Application application;
|
||||||
|
try {
|
||||||
|
application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID);
|
||||||
|
} catch (ApplicationManagementException e) {
|
||||||
|
throw new ApplicationStorageManagementException("Exception while retrieving the application details for "
|
||||||
|
+ "the application with UUID " + applicationUUID);
|
||||||
|
}
|
||||||
|
if (application == null) {
|
||||||
|
throw new ApplicationStorageManagementException("Application with UUID " + applicationUUID + " does not "
|
||||||
|
+ "exist. Cannot retrieve release artifacts for not existing application.");
|
||||||
|
}
|
||||||
|
String artifactPath = Constants.artifactPath + application.getId() + File.separator + versionName;
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("ApplicationRelease artifacts are searched in the location " + artifactPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
File binaryFile = new File(artifactPath);
|
||||||
|
|
||||||
|
if (!binaryFile.exists()) {
|
||||||
|
throw new ApplicationStorageManagementException("Binary file does not exist for this release");
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
return new FileInputStream(artifactPath);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new ApplicationStorageManagementException("Binary file does not exist for the version " +
|
||||||
|
versionName + " for the application ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To save a file in a given location.
|
||||||
|
*
|
||||||
|
* @param inputStream Stream of the file.
|
||||||
|
* @param path Path the file need to be saved in.
|
||||||
|
*/
|
||||||
|
private void saveFile(InputStream inputStream, String path) throws IOException {
|
||||||
|
OutputStream outStream = null;
|
||||||
|
try {
|
||||||
|
byte[] buffer = new byte[inputStream.available()];
|
||||||
|
inputStream.read(buffer);
|
||||||
|
outStream = new FileOutputStream(new File(path));
|
||||||
|
outStream.write(buffer);
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
if (outStream != null) {
|
||||||
|
outStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is responsible for creating artifact parent directories in the given path.
|
||||||
|
*
|
||||||
|
* @param artifactDirectoryPath Path for the artifact directory.
|
||||||
|
* @throws ApplicationStorageManagementException Application Storage Management Exception.
|
||||||
|
*/
|
||||||
|
private void createArtifactDirectory(String artifactDirectoryPath) throws ApplicationStorageManagementException {
|
||||||
|
File artifactDirectory = new File(artifactDirectoryPath);
|
||||||
|
|
||||||
|
if (!artifactDirectory.exists()) {
|
||||||
|
if (!artifactDirectory.mkdirs()) {
|
||||||
|
throw new ApplicationStorageManagementException(
|
||||||
|
"Cannot create directories in the path to save the application related artifacts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.application.mgt.core.impl;
|
|
||||||
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationUploadManager;
|
|
||||||
|
|
||||||
public class ApplicationUploadManagerImpl implements ApplicationUploadManager {
|
|
||||||
|
|
||||||
public ApplicationUploadManagerImpl(String uploadPath){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue