Fixed build issues.

feature/appm-store/pbac
Harshan Liyanage 8 years ago
parent 04d1082b4e
commit 84c6443971

@ -20,10 +20,10 @@ package org.wso2.carbon.device.application.mgt.api.services.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.core.components.ApplicationManager;
import org.wso2.carbon.device.application.mgt.core.dto.ApplicationList;
import org.wso2.carbon.device.application.mgt.core.dto.Filter;
import org.wso2.carbon.device.application.mgt.core.dto.lists.ApplicationList;
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil;
import org.wso2.carbon.device.application.mgt.core.services.ApplicationManager;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
@ -42,7 +42,7 @@ public class ApplicationManagementServiceImpl {
@Path("applications")
public Response getApplications(@QueryParam("offset") int offset, @QueryParam("limit") int limit,
@QueryParam("q") String searchQuery) {
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManager();
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagementService();
try {
if(limit == 0){

@ -1,34 +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.components;
import org.wso2.carbon.device.application.mgt.core.dto.Application;
import org.wso2.carbon.device.application.mgt.core.dto.ApplicationList;
import org.wso2.carbon.device.application.mgt.core.dto.Filter;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagerException;
import java.util.List;
public interface ApplicationManager {
public void createApplication(Application application) throws ApplicationManagerException;
public ApplicationList getApplications(Filter filter) throws ApplicationManagerException;
}

@ -1,63 +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.components.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.core.components.ApplicationManager;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationManagementDAO;
import org.wso2.carbon.device.application.mgt.core.dto.Application;
import org.wso2.carbon.device.application.mgt.core.dto.ApplicationList;
import org.wso2.carbon.device.application.mgt.core.dto.Filter;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagerException;
import org.wso2.carbon.device.application.mgt.core.internal.ApplicationManagementDataHolder;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.util.List;
public class ApplicationManagerImpl implements ApplicationManager {
private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class);
private static ApplicationManagerImpl applicationManager = new ApplicationManagerImpl();
private ApplicationManagerImpl() {
}
public static ApplicationManagerImpl getInstance() {
return applicationManager;
}
@Override
public void createApplication(Application application) {
}
@Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagerException {
ConnectionManagerUtil.openConnection();
ApplicationManagementDAO applicationManagementDAO = ApplicationManagementDataHolder.getInstance().getApplicationManagementDAO();
ApplicationList applications = applicationManagementDAO.getApplications(filter);
ConnectionManagerUtil.closeConnection();
return applications;
}
}

@ -1,65 +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.dao;
import org.wso2.carbon.device.application.mgt.core.dto.Application;
import org.wso2.carbon.device.application.mgt.core.dto.ApplicationList;
import org.wso2.carbon.device.application.mgt.core.dto.Filter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface ApplicationManagementDAO {
public enum DatabaseType {
H2("H2"),
MYSQL("MySQL"),
ORACLE("Oracle"),
POSTGRESQL("PostgreSQL"),
MSSQL("Microsoft SQL Server");
private final String value;
private static final Map<String, DatabaseType> lookup = new HashMap<String, DatabaseType>();
static {
for (DatabaseType databaseType : DatabaseType.values()) {
lookup.put(databaseType.getValue(), databaseType);
}
}
DatabaseType(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public static DatabaseType lookup(String value) {
return lookup.get(value);
}
}
public void createApplication(Application application) throws ApplicationManagementDAOException;
public ApplicationList getApplications(Filter filter) throws ApplicationManagementDAOException;
}

@ -1,32 +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.dao;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagerException;
public class ApplicationManagementDAOException extends ApplicationManagerException {
public ApplicationManagementDAOException(String message, Throwable throwable) {
super(message, throwable);
}
public ApplicationManagementDAOException(String message) {
super(message, new Exception());
}
}

@ -1,58 +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.dao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.application.mgt.core.dao.impl.GenericAppManagementDAO;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class ApplicationManagementDAOFactory {
public static final String H2 = "H2";
private ApplicationManagementDAO.DatabaseType databaseType;
private static DataSource dataSource;
private static final Log log = LogFactory.getLog(ApplicationManagementDAOFactory.class);
public ApplicationManagementDAOFactory(DataSourceConfig dataSourceConfig) {
dataSource = ConnectionManagerUtil.resolveDataSource(dataSourceConfig);
ConnectionManagerUtil.setDataSource(dataSource);
String databaseEngine = H2;
try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException e) {
log.error("Error occurred while retrieving config.datasource connection", e);
}
this.databaseType = ApplicationManagementDAO.DatabaseType.lookup(databaseEngine);
}
public ApplicationManagementDAO getApplicationManagementDAO(){
switch (databaseType) {
default:
return new GenericAppManagementDAO();
}
}
}

@ -1,100 +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.dao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.core.dto.Application;
import org.wso2.carbon.device.application.mgt.core.dto.ApplicationType;
import org.wso2.carbon.device.application.mgt.core.dto.Category;
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;
public class ApplicationManagementDAOUtil {
private static final Log log = LogFactory.getLog(ApplicationManagementDAOUtil.class);
public static Application loadApplication(ResultSet rs , ResultSet rsProperties) throws SQLException, JSONException {
Application application = new Application();
application.setId(rs.getInt("ID"));
application.setName(rs.getString("NAME"));
application.setUuid(rs.getString("UUID"));
application.setDescription(rs.getString("DESCRIPTION"));
application.setIconName(rs.getString("ICON_NAME"));
application.setBannerName(rs.getString("BANNER_NAME"));
application.setVideoName(rs.getString("VIDEO_NAME"));
application.setScreenshots(jsonArrayStringToList(rs.getString("SCREENSHOTS")));
application.setTags(jsonArrayStringToList(rs.getString("TAGS")));
application.setCreatedAt(rs.getDate("CREATED_AT"));
application.setModifiedAt(rs.getDate("MODIFIED_AT"));
ApplicationType applicationType = new ApplicationType();
applicationType.setName(rs.getString("AT_NAME"));
applicationType.setCode(rs.getString("AT_CODE"));
application.setApplicationType(applicationType);
Map<String, String> properties = new HashMap<>();
while (rsProperties.next()){
properties.put(rsProperties.getString("PROP_KEY"), rsProperties.getString("PROP_VAL"));
}
application.setProperties(properties);
Category category = new Category();
category.setName(rs.getString("CT_NAME"));
application.setCategory(category);
return application;
}
public static void cleanupResources(PreparedStatement stmt, ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
log.warn("Error occurred while closing result set", e);
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
log.warn("Error occurred while closing prepared statement", e);
}
}
}
public static List<String> jsonArrayStringToList(String value) throws JSONException {
JSONArray jsonArray = new JSONArray(value);
List<String> list = new ArrayList<>();
if (jsonArray != null) {
int len = jsonArray.length();
for (int i = 0; i < len; i++) {
list.add(jsonArray.get(i).toString());
}
}
return list;
}
}
Loading…
Cancel
Save