diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DefaultOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DefaultOperation.java new file mode 100644 index 0000000000..f947e7f45f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DefaultOperation.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.mgt.common; + +public class DefaultOperation implements Operation { + + @Override + public void init() { + + } + + @Override + public void execute() { + + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementServiceException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementServiceException.java new file mode 100644 index 0000000000..941d04db53 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementServiceException.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2014, 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.mgt.common; + +/** + * Created by manoj on 12/22/14. + */ +public class DeviceManagementServiceException extends Exception { + + private static final long serialVersionUID = -8933146283800122640L; + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public DeviceManagementServiceException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public DeviceManagementServiceException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public DeviceManagementServiceException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public DeviceManagementServiceException() { + super(); + } + + public DeviceManagementServiceException(Throwable cause) { + super(cause); + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java new file mode 100644 index 0000000000..8424142f7d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.mgt.common; + +/** + * This class needs to be implemented by all + */ +public interface Operation { + + /** + * Initializes any start-up resources required to execute a particular operation + */ + void init(); + + /** + * Executes the functionality configured within the method implementation + */ + void execute(); + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationData.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationData.java new file mode 100644 index 0000000000..9cb0ad63d5 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationData.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.mgt.common; + +import java.util.Properties; + +public class OperationData { + + public enum Type { + CONFIG, MESSAGE, STATE + } + + private String name; + private boolean state; + private Properties properties; + private String text; + private Type type; + + public OperationData(String name, Type type) { + this.type = type; + this.name = name; + } + + public OperationData(String name, boolean state) { + this.name = name; + this.type = Type.STATE; + this.state = state; + } + + public OperationData(String name, Properties properties) { + this.name = name; + this.type = Type.CONFIG; + this.properties = properties; + } + + public OperationData(String name, String text) { + this.name = name; + this.type = Type.MESSAGE; + this.text = text; + } + + public Type getType() { + return type; + } + + public boolean getState() { + return state; + } + + public String getText() { + return text; + } + + public Properties getProperties() { + return properties; + } + + public String getName() { + return name; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationFactory.java new file mode 100644 index 0000000000..ae8d0bb688 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationFactory.java @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.mgt.common; + +public class OperationFactory { + + public static Operation getOperation(String type) { + return new DefaultOperation(); + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java index 7be4549289..3f3340c1f3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java @@ -15,13 +15,18 @@ */ package org.wso2.carbon.device.mgt.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; +import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import java.util.HashMap; import java.util.Map; public class DeviceManagementRepository { + private static final Log log = LogFactory.getLog(DeviceManagerUtil.class); private Map providers; public DeviceManagementRepository() { @@ -29,7 +34,13 @@ public class DeviceManagementRepository { } public void addDeviceManagementProvider(DeviceManagerService provider) { - providers.put(provider.getProviderType(), provider); + String deviceType = provider.getProviderType(); + providers.put(deviceType, provider); + try { + DeviceManagerUtil.registerDeviceType(deviceType); + } catch (DeviceManagementException e) { + log.error("Exception occured while registering the device type.",e); + } } public DeviceManagerService getDeviceManagementProvider(String type) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java index f7b79a9d2f..124939f8bd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java @@ -1,17 +1,19 @@ -/** - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * Licensed 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 + * 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 + * 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. + * 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.mgt.core; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java index 19df597820..a2b6496747 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java @@ -1,17 +1,19 @@ -/** - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * Licensed 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 + * 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 + * 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. + * 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.mgt.core; @@ -29,13 +31,13 @@ import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import java.util.List; -public class DeviceManagerImpl implements DeviceManager{ - +public class DeviceManagerImpl implements DeviceManager { + private DeviceDAO deviceDAO; private DeviceTypeDAO deviceTypeDAO; private DeviceManagementConfig config; private DeviceManagementRepository pluginRepository; - + public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) { this.config = config; this.pluginRepository = pluginRepository; @@ -45,61 +47,57 @@ public class DeviceManagerImpl implements DeviceManager{ @Override public boolean enrollDevice(Device device) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(device.getType()); + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); boolean status = dms.enrollDevice(device); + try { this.getDeviceTypeDAO().getDeviceType(); - org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice( - device); + org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device); + Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType()); + deviceDto.setDeviceType(deviceTypeId); + this.getDeviceDAO().addDevice(deviceDto); - Integer deviceTypeId = this.getDeviceDAO().getDeviceTypeIdByDeviceTypeName(device.getType()); - deviceDto.setDeviceType(deviceTypeId); - this.getDeviceDAO().addDevice(deviceDto); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while enrolling the device '" + - device.getId() + "'", e); + throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'", + e); } return status; } @Override public boolean modifyEnrollment(Device device) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(device.getType()); + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); boolean status = dms.modifyEnrollment(device); try { this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device)); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while modifying the device '" + - device.getId() + "'", e); + throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + "'", + e); } return status; } @Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); return dms.disenrollDevice(deviceId); } @Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); return dms.isEnrolled(deviceId); } @Override public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); return dms.isActive(deviceId); } @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); return dms.setActive(deviceId, status); @@ -114,28 +112,24 @@ public class DeviceManagerImpl implements DeviceManager{ @Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); return dms.getDevice(deviceId); } @Override public boolean updateDeviceInfo(Device device) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(device.getType()); + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); return dms.updateDeviceInfo(device); } @Override public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); return dms.setOwnership(deviceId, ownershipType); } public OperationManager getOperationManager(String type) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(type); + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); return dms.getOperationManager(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java index e7e5dbe5bb..3c5a6073a2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java @@ -1,14 +1,17 @@ /* * Copyright (c) 2014, 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. + * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -27,14 +30,14 @@ import javax.xml.bind.Unmarshaller; import java.io.File; /** - * Class responsible for the rss manager configuration initialization + * Class responsible for the cdm manager configuration initialization */ public class DeviceConfigurationManager { private DeviceManagementConfig currentDeviceConfig; private static DeviceConfigurationManager deviceConfigManager; - private final String deviceMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + + private static final String deviceMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME; public static DeviceConfigurationManager getInstance() { @@ -49,6 +52,8 @@ public class DeviceConfigurationManager { } public synchronized void initConfig() throws DeviceManagementException { + + //catch generic exception.if any exception occurs wrap and throw DeviceManagementException try { File deviceMgtConfig = new File(deviceMgtConfigXMLPath); Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java index bfe8216981..8735df0fe5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java @@ -1,14 +1,17 @@ /* * Copyright (c) 2014, 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. + * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementRepository.java index 39fc6b4bd7..b84ef0388f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementRepository.java @@ -1,21 +1,23 @@ /* * Copyright (c) 2014, 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. + * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.wso2.carbon.device.mgt.core.config; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; - import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/datasource/DataSourceConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/datasource/DataSourceConfig.java index 07f5aab98d..f8b07312a1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/datasource/DataSourceConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/datasource/DataSourceConfig.java @@ -1,25 +1,27 @@ /* * Copyright (c) 2014, 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. + * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ - package org.wso2.carbon.device.mgt.core.config.datasource; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** - * Class for holding data source configuration in rss-config.xml at parsing with JAXB + * Class for holding data source configuration in cdm-config.xml at parsing with JAXB */ @XmlRootElement(name = "DataSourceConfiguration") public class DataSourceConfig { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index ea9c148c81..60ab53fd01 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -1,14 +1,17 @@ /* * Copyright (c) 2014, 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. + * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -36,6 +39,4 @@ public interface DeviceDAO { Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException; List getDevices() throws DeviceManagementDAOException; - - Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java index bc1ab0255e..ae12417d62 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java @@ -1,18 +1,21 @@ -/** - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * Licensed 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 + * 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 + * 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. + * 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.mgt.core.dao; import org.apache.commons.logging.Log; @@ -22,7 +25,6 @@ import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.dao.impl.DeviceDAOImpl; import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; - import javax.sql.DataSource; import java.util.Hashtable; import java.util.List; @@ -57,8 +59,8 @@ public class DeviceManagementDAOFactory { private static DataSource resolveDataSource(DataSourceConfig config) { DataSource dataSource = null; if (config == null) { - throw new RuntimeException("Device Management Repository data source configuration " + - "is null and thus, is not initialized"); + throw new RuntimeException("Device Management Repository data source configuration " + "is null and " + + "thus, is not initialized"); } JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion(); if (jndiConfig != null) { @@ -66,15 +68,13 @@ public class DeviceManagementDAOFactory { log.debug("Initializing Device Management Repository data source using the JNDI " + "Lookup Definition"); } - List jndiPropertyList = - jndiConfig.getJndiProperties(); + List jndiPropertyList = jndiConfig.getJndiProperties(); if (jndiPropertyList != null) { Hashtable jndiProperties = new Hashtable(); for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { jndiProperties.put(prop.getName(), prop.getValue()); } - dataSource = - DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); } else { dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java index 1947922f56..29c08d9ca2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java @@ -11,11 +11,10 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ - package org.wso2.carbon.device.mgt.core.dao; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; @@ -36,4 +35,6 @@ public interface DeviceTypeDAO { DeviceIdentifier getDeviceType() throws DeviceManagementDAOException; + Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index dd85092825..87ce6ab397 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -11,7 +11,7 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -102,38 +102,6 @@ public class DeviceDAOImpl implements DeviceDAO { return null; } - @Override - public Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException { - - Connection conn = null; - PreparedStatement stmt = null; - ResultSet resultSet = null; - Integer deviceTypeId = null; - - try { - conn = this.getConnection(); - String createDBQuery = - "SELECT * From DM_DEVICE_TYPE DT WHERE DT.NAME=?"; - - stmt = conn.prepareStatement(createDBQuery); - stmt.setString(1, type); - resultSet = stmt.executeQuery(); - - while(resultSet.next()){ - deviceTypeId = resultSet.getInt(1); - } - - } catch (SQLException e) { - String msg = "Error occurred while fetch device type id for device type '" + type + "'"; - log.error(msg, e); - throw new DeviceManagementDAOException(msg, e); - } finally { - DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - - return deviceTypeId; - } - private Connection getConnection() throws DeviceManagementDAOException { try { return dataSource.getConnection(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java index aa1386c86b..049ed04244 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java @@ -1,35 +1,42 @@ -/** - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * Licensed 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 + * 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 + * 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. + * 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.mgt.core.dao.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; +import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import javax.sql.DataSource; import java.sql.Connection; import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; public class DeviceTypeDAOImpl implements DeviceTypeDAO { private DataSource dataSource; + private static final Log log = LogFactory.getLog(DeviceTypeDAOImpl.class); public DeviceTypeDAOImpl(DataSource dataSource) { this.dataSource = dataSource; @@ -44,8 +51,9 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { stmt.setString(1, deviceType.getName()); stmt.execute(); } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while registering the device type '" + - deviceType.getName() + "'", e); + String msg = "Error occurred while registering the device type '" + deviceType.getName() + "'"; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); } finally { DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); } @@ -58,21 +66,72 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { @Override public List getDeviceTypes() throws DeviceManagementDAOException { - return null; + Connection conn = this.getConnection(); + PreparedStatement stmt = null; + List deviceTypes = new ArrayList(); + try { + stmt = conn.prepareStatement("SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE"); + ResultSet results = stmt.executeQuery(); + + while (results.next()) { + DeviceType deviceType = new DeviceType(); + deviceType.setId(results.getLong("DEVICE_TYPE_ID")); + deviceType.setName(results.getString("DEVICE_TYPE")); + deviceTypes.add(deviceType); + } + } catch (SQLException e) { + String msg = "Error occurred while fetching the registered device types"; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } finally { + DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return deviceTypes; } @Override public DeviceIdentifier getDeviceType() throws DeviceManagementDAOException { - return new DeviceIdentifier(); + //TODO: + return null; + } + + @Override + public Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException { + + Connection conn = this.getConnection(); + PreparedStatement stmt = null; + ResultSet resultSet = null; + Integer deviceTypeId = null; + + try { + String createDBQuery = "SELECT * From DM_DEVICE_TYPE DT WHERE DT.NAME=?"; + stmt = conn.prepareStatement(createDBQuery); + stmt.setString(1, type); + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + deviceTypeId = resultSet.getInt(1); + } + + } catch (SQLException e) { + String msg = "Error occurred while fetch device type id for device type '" + type + "'"; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } finally { + DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + + return deviceTypeId; } private Connection getConnection() throws DeviceManagementDAOException { try { return dataSource.getConnection(); } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while obtaining a connection from the device " + - "management metadata repository datasource", e); + String msg = "Error occurred while obtaining a connection from the device " + + "management metadata repository datasource"; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); } } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java index 60ec9785f2..dc38a96d41 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java @@ -61,6 +61,9 @@ public final class DeviceManagementDAOUtil { log.warn("Error occurred while closing database connection", e); } } + rs = null; + stmt = null; + conn = null; } /** @@ -83,8 +86,7 @@ public final class DeviceManagementDAOUtil { try { tenantId = tenantManager.getTenantId(tenantDomain); } catch (UserStoreException e) { - String msg = "Error occurred while retrieving id from the domain of tenant " + - tenantDomain; + String msg = "Error occurred while retrieving id from the domain of tenant " + tenantDomain; throw new DeviceManagementDAOException(msg); } return tenantId; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 92b2386333..daa67845bb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -1,17 +1,19 @@ -/** - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * Licensed 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 + * 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 + * 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. + * 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.mgt.core.internal; @@ -56,7 +58,6 @@ public class DeviceManagementServiceComponent { try { /* Initializing Device Management Configuration */ DeviceConfigurationManager.getInstance().initConfig(); - DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig(); @@ -88,6 +89,8 @@ public class DeviceManagementServiceComponent { private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException { DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config); log.info("Initializing device management repository database schema"); + + // catch generic exception. If any error occurs wrap and throw DeviceManagementException try { initializer.createRegistryDatabase(); } catch (Exception e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index f008423a4e..ab71bdc5ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -21,7 +21,11 @@ import org.w3c.dom.Document; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; import javax.sql.DataSource; import javax.xml.parsers.DocumentBuilder; @@ -47,7 +51,7 @@ public final class DeviceManagerUtil { } /** - * Resolve data source from the data source definition + * Resolve data source from the data source definition. * * @param config data source configuration * @return data source resolved from the data source definition @@ -80,4 +84,27 @@ public final class DeviceManagerUtil { return dataSource; } + /** + * Adds a new device type to the database if it does not exists. + * + * @param deviceTypeName device type + * @return status of the operation + */ + public static boolean registerDeviceType(String deviceTypeName) throws DeviceManagementException{ + boolean status = false; + try { + DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); + Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceTypeName); + if(deviceTypeId == null){ + DeviceType deviceType = new DeviceType(); + deviceType.setName(deviceTypeName); + deviceTypeDAO.addDeviceType(deviceType); + } + status = true; + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while registering the device type " + deviceTypeName; + throw new DeviceManagementException(msg, e); + } + return status; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementTestCase.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementTestCase.java index e72afb3c20..0162f11a0e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementTestCase.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementTestCase.java @@ -1,20 +1,20 @@ /* -* Copyright (c) 2014, 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. -*/ + * Copyright (c) 2014, 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.mgt.core; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/DBTypes.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/DBTypes.java index 203d580cea..89c5683ff6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/DBTypes.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/DBTypes.java @@ -1,14 +1,17 @@ /* * Copyright (c) 2014, 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. + * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDBConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDBConfiguration.java index 9689cd2621..d33bfeba94 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDBConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDBConfiguration.java @@ -1,14 +1,17 @@ /* * Copyright (c) 2014, 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. + * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDBConfigurations.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDBConfigurations.java index 7c7fdfb731..d1551cca0e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDBConfigurations.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDBConfigurations.java @@ -1,14 +1,17 @@ /* * Copyright (c) 2014, 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. + * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceMgtDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceMgtDAOTestSuite.java index 116a24907f..98bb0d4372 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceMgtDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceMgtDAOTestSuite.java @@ -1,14 +1,17 @@ /* * Copyright (c) 2014, 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. + * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -66,8 +69,8 @@ public class DeviceMgtDAOTestSuite { } } - private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) - throws DeviceManagementDAOException, DeviceManagementException { + private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws DeviceManagementDAOException, + DeviceManagementException { File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml"); Document doc = null; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml index ed184b1943..aabc554c47 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml @@ -1,4 +1,21 @@ + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java index 604b3278be..551aa1ddad 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java @@ -27,7 +27,7 @@ import javax.xml.bind.Unmarshaller; import java.io.File; /** - * Class responsible for the mobile device manager configuration initialization + * Class responsible for the mobile device manager configuration initialization. */ public class MobileDeviceConfigurationManager { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java index ee16af2179..5a595be13c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java @@ -21,7 +21,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** - * Class for holding management repository data + * Class for holding management repository data. */ @XmlRootElement(name = "ManagementRepository") public class MobileDeviceManagementRepository { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/JNDILookupDefinition.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/JNDILookupDefinition.java index 40f88a4202..f868b914ab 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/JNDILookupDefinition.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/JNDILookupDefinition.java @@ -20,7 +20,7 @@ import javax.xml.bind.annotation.*; import java.util.List; /** - * Class for hold JndiLookupDefinition of mobile-config.xml at parsing with JAXB + * Class for hold JndiLookupDefinition of mobile-config.xml at parsing with JAXB. */ @XmlRootElement(name = "JndiLookupDefinition") public class JNDILookupDefinition { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java index 98e06c1507..2b9c570c9f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java @@ -20,7 +20,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** - * Class for holding data source configuration in mobile-config.xml at parsing with JAXB + * Class for holding data source configuration in mobile-config.xml at parsing with JAXB. */ @XmlRootElement(name = "DataSourceConfiguration") public class MobileDataSourceConfig { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOException.java index 2bf9b21cf8..22f02a9498 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOException.java @@ -49,7 +49,7 @@ public class MobileDeviceManagementDAOException extends Exception { } /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message + * Constructs a new MobileDeviceManagementDAOException with the specified detail message. * * @param message the detail message. */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java index 600fcf52f9..e8ab4660d2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java @@ -40,7 +40,7 @@ public class MobileDeviceManagementDAOUtil { private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOUtil.class); /** - * Resolve data source from the data source definition + * Resolve data source from the data source definition. * * @param config Mobile data source configuration * @return data source resolved from the data source definition @@ -128,7 +128,7 @@ public class MobileDeviceManagementDAOUtil { } /** - * Initializes the creation of mobile device management schema if -Dsetup has provided + * Initializes the creation of mobile device management schema if -Dsetup has provided. * * @param dataSource Mobile data source */ @@ -151,7 +151,7 @@ public class MobileDeviceManagementDAOUtil { } /** - * Creates the mobile device management schema + * Creates the mobile device management schema. * * @param dataSource Mobile data source */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java index 798c922cc7..ebb6038b9d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java @@ -22,7 +22,7 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; import java.util.List; /** - * This represents the iOS implementation of DeviceManagerService. * + * This represents the iOS implementation of DeviceManagerService. */ public class IOSDeviceManagerService implements DeviceManagerService { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/DeviceManagementUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/DeviceManagementUtil.java deleted file mode 100644 index 4c7bc8bb31..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/DeviceManagementUtil.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * Licensed 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.mgt.mobile.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.w3c.dom.Document; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import java.io.File; - -public class DeviceManagementUtil { - - private static final Log log = LogFactory.getLog(DeviceManagementUtil.class); - - public static Document convertToDocument(File file) throws DeviceManagementException { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - try { - DocumentBuilder docBuilder = factory.newDocumentBuilder(); - return docBuilder.parse(file); - } catch (Exception e) { - throw new DeviceManagementException( - "Error occurred while parsing file, while converting " + - "to a org.w3c.dom.Document : " + e.getMessage(), e); - } - } - -} diff --git a/product/modules/agents/android/jax-rs/pom.xml b/product/modules/agents/android/jax-rs/pom.xml index ff4e139e64..6ee8f104b6 100644 --- a/product/modules/agents/android/jax-rs/pom.xml +++ b/product/modules/agents/android/jax-rs/pom.xml @@ -1,18 +1,20 @@ + ~ 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. +--> 2.6.1 4.8.2 - diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Device.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Device.java index cc75b3a89e..f1cdfc64f4 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Device.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Device.java @@ -1,33 +1,33 @@ /* * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * Licensed 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 + * 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 + * 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. + * 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 cdm.api.android; +import cdm.api.android.common.AndroidAgentException; import cdm.api.android.util.AndroidAPIUtils; -import cdm.api.android.util.AndroidConstants; import cdm.api.android.util.Message; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.DeviceManagementServiceException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; - import javax.ws.rs.*; import javax.ws.rs.core.Response; import java.util.List; @@ -39,107 +39,112 @@ import java.util.List; @Consumes({ "application/json", "application/xml" }) public class Device { - private static Log log = LogFactory.getLog(Device.class); - - @GET - public List getAllDevices() { - List devices = null; - String msg = ""; - DeviceManagementService dmService; - - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - try { - if (dmService != null) { - devices = dmService.getAllDevices( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - Response.status(HttpStatus.SC_OK); - } else { - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - } - } catch (DeviceManagementException e) { - msg = "Error occurred while fetching the device list."; - log.error(msg, e); - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - } - return devices; - } - - @GET - @Path("{id}") - public org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id) { - String msg = ""; - DeviceManagementService dmService; - org.wso2.carbon.device.mgt.common.Device device = - new org.wso2.carbon.device.mgt.common.Device(); - - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - try { - if (dmService != null) { - device = dmService.getDevice(deviceIdentifier); - if (device == null) { - Response.status(HttpStatus.SC_NOT_FOUND); - } - - } else { - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - } - - } catch (DeviceManagementException e) { - msg = "Error occurred while fetching the device information."; - log.error(msg, e); - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - } - return device; - } - - @PUT - @Path("{id}") - public Message updateDevice(@PathParam("id") String id, - org.wso2.carbon.device.mgt.common.Device device) { - boolean result = false; - String msg = ""; - DeviceManagementService dmService; - Message responseMessage = new Message(); - - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - try { - if (dmService != null) { - device.setType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - result = dmService.updateDeviceInfo(device); - if (result) { - Response.status(HttpStatus.SC_OK); - responseMessage.setResponseMessage("Device information has modified successfully."); - } else { - Response.status(HttpStatus.SC_NOT_MODIFIED); - responseMessage.setResponseMessage("Update device has failed."); - } - } else { - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; - responseMessage.setResponseMessage(msg); - } - - } catch (DeviceManagementException e) { - msg = "Error occurred while modifying the device information."; - log.error(msg, e); - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - responseMessage.setResponseMessage(msg); - - } - return responseMessage; - } + private static Log LOG = LogFactory.getLog(Device.class); + + @GET + public List getAllDevices() throws AndroidAgentException { + + List devices; + String msg; + DeviceManagementService dmService; + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + + } catch (DeviceManagementServiceException deviceMgtServiceEx) { + String errorMsg = "Device management service error"; + LOG.error(errorMsg, deviceMgtServiceEx); + throw new AndroidAgentException(errorMsg, deviceMgtServiceEx); + } + + try { + devices = dmService.getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + Response.status(HttpStatus.SC_OK); + return devices; + + } catch (DeviceManagementException e) { + msg = "Error occurred while fetching the device list."; + LOG.error(msg, e); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + throw new AndroidAgentException(msg, e); + } + } + + @GET + @Path("{id}") + public org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id) throws AndroidAgentException { + + String msg; + DeviceManagementService dmService; + org.wso2.carbon.device.mgt.common.Device device; + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + + } catch (DeviceManagementServiceException deviceMgtServiceEx) { + String errorMsg = "Device management service error"; + LOG.error(errorMsg, deviceMgtServiceEx); + throw new AndroidAgentException(errorMsg, deviceMgtServiceEx); + } + + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + try { + device = dmService.getDevice(deviceIdentifier); + if (device == null) { + Response.status(HttpStatus.SC_NOT_FOUND); + } + return device; + + } catch (DeviceManagementException deviceMgtEx) { + msg = "Error occurred while fetching the device information."; + LOG.error(msg, deviceMgtEx); + throw new AndroidAgentException(msg, deviceMgtEx); + } + } + + @PUT + @Path("{id}") + public Message updateDevice(@PathParam("id") String id, org.wso2.carbon.device.mgt.common.Device device) throws + AndroidAgentException { + + DeviceManagementService dmService = null; + Message responseMessage = new Message(); + + boolean result; + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + + } catch (DeviceManagementServiceException deviceManagementServiceException) { + String errorMsg = "Device management service error"; + LOG.error(errorMsg, deviceManagementServiceException); + } + + try { + device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + result = dmService.updateDeviceInfo(device); + + if (result) { + Response.status(HttpStatus.SC_OK); + responseMessage.setResponseMessage("Device information has modified successfully."); + } else { + Response.status(HttpStatus.SC_NOT_MODIFIED); + responseMessage.setResponseMessage("Device not found for the update."); + } + return responseMessage; + + } catch (DeviceManagementException deviceMgtEx) { + String msg = "Error occurred while modifying the device information."; + LOG.error(msg, deviceMgtEx); + throw new AndroidAgentException(msg, deviceMgtEx); + } + } + + @POST + @Path("/device/license") + @Produces ("text/plain") + public String getLicense() { + //TODO: need to implement fetch license from core + return "License Agreement"; + } } diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java index f2eb449d75..5c93765f52 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java @@ -1,32 +1,33 @@ /* * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * Licensed 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 + * 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 + * 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. + * 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 cdm.api.android; +import cdm.api.android.common.AndroidAgentException; import cdm.api.android.util.AndroidAPIUtils; -import cdm.api.android.util.AndroidConstants; import cdm.api.android.util.Message; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.DeviceManagementServiceException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import javax.ws.rs.*; @@ -39,186 +40,147 @@ import javax.ws.rs.core.Response; @Consumes({ "application/json", "application/xml" }) public class Enrollment { - private static Log log = LogFactory.getLog(Enrollment.class); - - /* - * Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD", - * "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"}, - * {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"}, - * {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"}, - * {"name":"osVersion","value":"5.0.0"}]} - * - **/ - @POST - public Message enrollDevice(Device device) { - - boolean result = false; - int status = 0; - String msg = ""; - DeviceManagementService dmService; - Message responseMsg = new Message(); - - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - - try { - if (dmService != null) { - device.setType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - result = dmService.enrollDevice(device); - Response.status(HttpStatus.SC_CREATED); - responseMsg.setResponseMessage("Device enrollment has succeeded"); - return responseMsg; - - } else { - responseMsg.setResponseMessage( - AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE); - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - return responseMsg; - } - } catch (DeviceManagementException e) { - log.error(msg, e); - responseMsg.setResponseMessage("Error occurred while enrolling the device"); - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - return responseMsg; - } - - } - - @GET - @Path("{id}") - public Message isEnrolled(@PathParam("id") String id) { - - boolean result = false; - String msg = ""; - DeviceManagementService dmService; - Message responseMsg = new Message(); - - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - try { - if (dmService != null) { - result = dmService.isEnrolled(deviceIdentifier); - if (result) { - Response.status(HttpStatus.SC_OK); - responseMsg.setResponseMessage("Device has already enrolled"); - } else { - Response.status(HttpStatus.SC_NOT_FOUND); - responseMsg.setResponseMessage("Device has not enrolled"); - } - return responseMsg; - } else { - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - responseMsg.setResponseMessage( - AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE); - return responseMsg; - } - } catch (DeviceManagementException e) { - msg = "Error occurred while checking the enrollment of the device."; - log.error(msg, e); - responseMsg.setResponseMessage(msg); - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - return responseMsg; - } - - } - - /* - * Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD", - * "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"}, - * {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"}, - * {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"}, - * {"name":"osVersion","value":"5.0.0"}]} - * - **/ - @PUT - @Path("{id}") - public Message modifyEnrollment(@PathParam("id") String id, Device device) { - boolean result = false; - String msg = ""; - DeviceManagementService dmService; - Message responseMsg = new Message(); - - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - - try { - if (dmService != null) { - device.setType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - result = dmService.modifyEnrollment(device); - - if (result) { - responseMsg.setResponseMessage("Device enrollment has updated successfully"); - Response.status(HttpStatus.SC_OK); - } else { - responseMsg.setResponseMessage("Update enrollment has failed"); - Response.status(HttpStatus.SC_NOT_MODIFIED); - } - } else { - msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; - responseMsg.setResponseMessage(msg); - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - } - return responseMsg; - } catch (DeviceManagementException e) { - msg = "Error occurred while modifying enrollment of the device"; - log.error(msg, e); - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - responseMsg.setResponseMessage(msg); - return responseMsg; - } - - } - - @DELETE - @Path("{id}") - public Message disenrollDevice(@PathParam("id") String id) { - - boolean result = false; - String msg = ""; - DeviceManagementService dmService; - Message responseMsg = new Message(); - - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - try { - if (dmService != null) { - result = dmService.disenrollDevice(deviceIdentifier); - if (result) { - responseMsg.setResponseMessage("Device has disenrolled successfully"); - Response.status(HttpStatus.SC_OK); - } else { - responseMsg.setResponseMessage("Device not found"); - Response.status(HttpStatus.SC_NOT_FOUND); - } - } else { - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; - responseMsg.setResponseMessage(msg); - } - - return responseMsg; - } catch (DeviceManagementException e) { - msg = "Error occurred while disenrolling the device"; - log.error(msg, e); - Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); - responseMsg.setResponseMessage(msg); - return responseMsg; - } - } + private static Log log = LogFactory.getLog(Enrollment.class); + + @POST + public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException { + + DeviceManagementService dmService; + Message responseMsg = new Message(); + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + + } catch (DeviceManagementServiceException deviceServiceMgtEx) { + String errorMsg = "Device management service error"; + log.error(errorMsg, deviceServiceMgtEx); + throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); + } + + try { + device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + dmService.enrollDevice(device); + Response.status(HttpStatus.SC_CREATED); + responseMsg.setResponseMessage("Device enrollment succeeded"); + return responseMsg; + + } catch (DeviceManagementException deviceMgtEx) { + String errorMsg = "Error occurred while enrolling the device"; + log.error(errorMsg, deviceMgtEx); + throw new AndroidAgentException(errorMsg, deviceMgtEx); + } + } + + @GET + @Path("{id}") + public Message isEnrolled(@PathParam("id") String id) throws AndroidAgentException { + + boolean result; + DeviceManagementService dmService; + Message responseMsg = new Message(); + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + + } catch (DeviceManagementServiceException deviceServiceMgtEx) { + String errorMsg = "Device management service error"; + log.error(errorMsg, deviceServiceMgtEx); + throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); + } + + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + + try { + result = dmService.isEnrolled(deviceIdentifier); + if (result) { + Response.status(HttpStatus.SC_OK); + responseMsg.setResponseMessage("Device has already enrolled"); + } else { + Response.status(HttpStatus.SC_NOT_FOUND); + responseMsg.setResponseMessage("Device not found"); + } + return responseMsg; + } catch (DeviceManagementException deviceMgtEx) { + String errormsg = "Error occurred while enrollment of the device."; + log.error(errormsg, deviceMgtEx); + throw new AndroidAgentException(errormsg, deviceMgtEx); + } + } + + @PUT + @Path("{id}") + public Message modifyEnrollment(@PathParam("id") String id, org.wso2.carbon.device.mgt.common.Device device) + throws AndroidAgentException { + + boolean result; + DeviceManagementService dmService; + Message responseMsg = new Message(); + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + + } catch (DeviceManagementServiceException deviceServiceMgtEx) { + String errorMsg = "Device management service error"; + log.error(errorMsg, deviceServiceMgtEx); + throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); + } + + try { + device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + result = dmService.modifyEnrollment(device); + + if (result) { + responseMsg.setResponseMessage("Device enrollment has updated successfully"); + Response.status(HttpStatus.SC_OK); + } else { + responseMsg.setResponseMessage("device not found for enrollment"); + Response.status(HttpStatus.SC_NOT_MODIFIED); + } + + return responseMsg; + + } catch (DeviceManagementException deviceMgtEx) { + String errorMsg = "Error occurred while modifying enrollment of the device"; + log.error(errorMsg, deviceMgtEx); + throw new AndroidAgentException(errorMsg, deviceMgtEx); + } + + } + + @DELETE + @Path("{id}") + public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException { + + DeviceManagementService dmService; + Message responseMsg = new Message(); + + boolean result; + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + + } catch (DeviceManagementServiceException deviceServiceMgtEx) { + String errorMsg = "Device management service error"; + log.error(errorMsg, deviceServiceMgtEx); + throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); + } + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + + try { + result = dmService.disenrollDevice(deviceIdentifier); + if (result) { + responseMsg.setResponseMessage("Device has disenrolled successfully"); + Response.status(HttpStatus.SC_OK); + } else { + responseMsg.setResponseMessage("Device not found"); + Response.status(HttpStatus.SC_NOT_FOUND); + } + return responseMsg; + + } catch (DeviceManagementException deviceMgtEx) { + String errorMsg = "Error occurred while dis enrolling the device"; + log.error(errorMsg, deviceMgtEx); + throw new AndroidAgentException(errorMsg, deviceMgtEx); + } + } } diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java new file mode 100644 index 0000000000..caf7cf5382 --- /dev/null +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java @@ -0,0 +1,36 @@ +package cdm.api.android; + +import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.Device; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +/** + * This is a Test class + */ +@Produces({"application/json", "application/xml"}) +@Consumes({"application/json", "application/xml"}) +public class Test { + + @GET + public List getAllDevices() throws DeviceManagementException{ + + Device dev = new Device(); + dev.setName("test1"); + dev.setDateOfEnrolment(11111111L); + dev.setDateOfLastUpdate(992093209L); + dev.setDescription("sassasaas"); + + ArrayList listdevices = new ArrayList(); + listdevices.add(dev); + throw new DeviceManagementException("test ex"); + + } + +} diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/AndroidAgentException.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/AndroidAgentException.java new file mode 100644 index 0000000000..138a3fa952 --- /dev/null +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/AndroidAgentException.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014, 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 cdm.api.android.common; + +public class AndroidAgentException extends Exception{ + + private static final long serialVersionUID = 7950151650447893900L; + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public AndroidAgentException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public AndroidAgentException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public AndroidAgentException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public AndroidAgentException() { + super(); + } + + public AndroidAgentException(Throwable cause) { + super(cause); + } + + + +} diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/ErrorHandler.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/ErrorHandler.java index 6fa07dba1f..de3d0c523f 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/ErrorHandler.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/ErrorHandler.java @@ -1,32 +1,35 @@ /* * Copyright (c) 2014, 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 + * 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 + * 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. + * 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 cdm.api.android.common; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; + +import javax.ws.rs.Produces; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; -public class ErrorHandler implements ExceptionMapper { - public Response toResponse(Throwable throwable) { - Response.Status status; - status = Response.Status.INTERNAL_SERVER_ERROR; - // return Response.status(status).header("exception", exception.getMessage()).build(); - return null; +@Produces({ "application/json", "application/xml" }) +public class ErrorHandler implements ExceptionMapper { + + public Response toResponse(AndroidAgentException exception) { + ErrorMessage errorMessage = new ErrorMessage(); + errorMessage.setErrorMessage(exception.getErrorMessage()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); } } diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/ErrorMessage.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/ErrorMessage.java new file mode 100644 index 0000000000..d166f105d4 --- /dev/null +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/ErrorMessage.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014, 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 cdm.api.android.common; + + +public class ErrorMessage { + + private String errorMessage; + private String errorCode; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } +} diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtils.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtils.java index 5d24d6eb14..e0e418b8a2 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtils.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtils.java @@ -1,34 +1,38 @@ /* * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * Licensed 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 + * 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 + * 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. - */ - + * 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 cdm.api.android.util; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; -import java.util.*; - /** * AndroidAPIUtil class provides utility function used by Android REST-API classes. */ public class AndroidAPIUtils { + private static Log log = LogFactory.getLog(AndroidAPIUtils.class); + public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) { + DeviceIdentifier identifier = new DeviceIdentifier(); identifier.setId(deviceId); identifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); @@ -36,14 +40,21 @@ public class AndroidAPIUtils { } - public static DeviceManagementService getDeviceManagementService() { + public static DeviceManagementService getDeviceManagementService() throws DeviceManagementServiceException{ + + // until complete login this is use to load super tenant context DeviceManagementService dmService; PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); - dmService = (DeviceManagementService) ctx - .getOSGiService(DeviceManagementService.class, null); + dmService = (DeviceManagementService) ctx.getOSGiService(DeviceManagementService.class, null); + + if (dmService == null){ + log.error("device management service not initialized"); + throw new DeviceManagementServiceException("device management service not initialized"); + } + PrivilegedCarbonContext.endTenantFlow(); return dmService; } } diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidConstants.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidConstants.java index 0dcb9e59de..f3880536c2 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidConstants.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidConstants.java @@ -1,19 +1,20 @@ /* * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * 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 + * 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. - */ - + * 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 cdm.api.android.util; /** diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/Message.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/Message.java index f5e34cf7ec..5361ff0d4c 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/Message.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/Message.java @@ -1,21 +1,20 @@ /* * Copyright (c) 2014, 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 + * 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 + * 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. - */ - + * 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 cdm.api.android.util; import javax.xml.bind.annotation.XmlElement; diff --git a/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml b/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml index 3f42f416b0..7f7e753d17 100644 --- a/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -1,21 +1,21 @@ - - + ~ 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. +--> - + + @@ -37,6 +38,7 @@ + @@ -45,12 +47,22 @@ + - + + + + + + + + + + diff --git a/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/web.xml b/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/web.xml index b12b2cf4e8..1a5ca4fedd 100644 --- a/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/web.xml +++ b/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/web.xml @@ -1,19 +1,21 @@ + ~ 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. +--> CDM-Android-API diff --git a/product/modules/distribution/src/repository/dbscripts/cdm/h2.sql b/product/modules/distribution/src/repository/dbscripts/cdm/h2.sql index dadcbd080c..d1c40af642 100644 --- a/product/modules/distribution/src/repository/dbscripts/cdm/h2.sql +++ b/product/modules/distribution/src/repository/dbscripts/cdm/h2.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( - ID INT(11) NOT NULL, + ID INT(11) auto_increment NOT NULL, NAME VARCHAR(300) NULL DEFAULT NULL, PRIMARY KEY (ID) ); @@ -21,6 +21,4 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE PRIMARY KEY (ID), CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID ) REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION -); --- TO:DO - Remove this INSERT sql statement. -Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android'); +); \ No newline at end of file