forked from community/device-mgt-plugins
Merge branch 'master' of https://github.com/geethkokila/product-cdm
commit
1f489c8d62
@ -0,0 +1,53 @@
|
||||
/*
|
||||
*
|
||||
* * 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;
|
||||
|
||||
public class License {
|
||||
|
||||
private String licenseName;
|
||||
private String licenseText;
|
||||
private String licenseVersion;
|
||||
|
||||
public String getLicenseName() {
|
||||
return licenseName;
|
||||
}
|
||||
|
||||
public void setLicenseName(String licenseName) {
|
||||
this.licenseName = licenseName;
|
||||
}
|
||||
|
||||
public String getLicenseText() {
|
||||
return licenseText;
|
||||
}
|
||||
|
||||
public void setLicenseText(String licenseText) {
|
||||
this.licenseText = licenseText;
|
||||
}
|
||||
|
||||
public String getLicenseVersion() {
|
||||
return licenseVersion;
|
||||
}
|
||||
|
||||
public void setLicenseVersion(String licenseVersion) {
|
||||
this.licenseVersion = licenseVersion;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2015, 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.core;
|
||||
|
||||
public final class DeviceManagementConstants {
|
||||
|
||||
public static final class Common {
|
||||
private Common() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
public static final String PROPERTY_SETUP = "setup";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Copyright (c) 2015, 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.core;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import java.io.File;
|
||||
|
||||
public class DeviceManagementConfigTests {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceManagementConfigTests.class);
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY =
|
||||
"./src/test/resources/config/malformed-cdm-config-no-mgt-repo.xml";
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG =
|
||||
"./src/test/resources/config/malformed-cdm-config-no-ds-config.xml";
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG =
|
||||
"./src/test/resources/config/malformed-cdm-config-no-jndi-config.xml";
|
||||
private static final String TEST_CONFIG_SCHEMA_LOCATION =
|
||||
"./src/test/resources/config/schema/DeviceManagementConfigSchema.xsd";
|
||||
|
||||
private Schema schema;
|
||||
|
||||
@BeforeClass
|
||||
private void initSchema() {
|
||||
File deviceManagementSchemaConfig = new File(DeviceManagementConfigTests.TEST_CONFIG_SCHEMA_LOCATION);
|
||||
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
try {
|
||||
schema = factory.newSchema(deviceManagementSchemaConfig);
|
||||
} catch (SAXException e) {
|
||||
Assert.fail("Invalid schema found", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testMandateManagementRepositoryElement() {
|
||||
File malformedConfig =
|
||||
new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMandateDataSourceConfigurationElement() {
|
||||
File malformedConfig = new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMandateJndiLookupDefinitionElement() {
|
||||
File malformedConfig = new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
private void validateMalformedConfig(File malformedConfig) {
|
||||
try {
|
||||
JAXBContext ctx = JAXBContext.newInstance(DeviceManagementConfig.class);
|
||||
Unmarshaller um = ctx.createUnmarshaller();
|
||||
um.setSchema(this.getSchema());
|
||||
um.unmarshal(malformedConfig);
|
||||
Assert.assertTrue(false);
|
||||
} catch (JAXBException e) {
|
||||
log.error("Error occurred while unmarsharlling device management config", e);
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
private Schema getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright (c) 2015, 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.core;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||
|
||||
public class DeviceManagementRepositoryTests {
|
||||
|
||||
private DeviceManagementRepository repository;
|
||||
|
||||
@BeforeClass
|
||||
public void initRepository() {
|
||||
this.repository = new DeviceManagementRepository();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddDeviceManagementService() {
|
||||
DeviceManagerService sourceProvider = new TestDeviceManagerService();
|
||||
this.getRepository().addDeviceManagementProvider(sourceProvider);
|
||||
|
||||
DeviceManagerService targetProvider =
|
||||
this.getRepository().getDeviceManagementProvider(TestDeviceManagerService.DEVICE_TYPE_TEST);
|
||||
|
||||
Assert.assertEquals(targetProvider.getProviderType(), sourceProvider.getProviderType());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testAddDeviceManagementService")
|
||||
public void testRemoveDeviceManagementService() {
|
||||
DeviceManagerService sourceProvider = new TestDeviceManagerService();
|
||||
this.getRepository().removeDeviceManagementProvider(sourceProvider);
|
||||
|
||||
DeviceManagerService targetProvider =
|
||||
this.getRepository().getDeviceManagementProvider(TestDeviceManagerService.DEVICE_TYPE_TEST);
|
||||
|
||||
Assert.assertNull(targetProvider);
|
||||
}
|
||||
|
||||
private DeviceManagementRepository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* 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.core;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.OperationManager;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TestDeviceManagerService implements DeviceManagerService {
|
||||
|
||||
public static final String DEVICE_TYPE_TEST = "Test";
|
||||
|
||||
@Override
|
||||
public String getProviderType() {
|
||||
return TestDeviceManagerService.DEVICE_TYPE_TEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperationManager getOperationManager() throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 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.core;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(TestUtils.class);
|
||||
|
||||
public static void cleanupResources(Connection conn, Statement stmt, ResultSet rs) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing result set", e);
|
||||
}
|
||||
}
|
||||
if (stmt != null) {
|
||||
try {
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing prepared statement", e);
|
||||
}
|
||||
}
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing database connection", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ 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.
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<DeviceMgtConfiguration>
|
||||
<ManagementRepository>
|
||||
<MalformedDataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/DEVICE_MGT_DS</Name>
|
||||
</JndiLookupDefinition>
|
||||
</MalformedDataSourceConfiguration>
|
||||
</ManagementRepository>
|
||||
</DeviceMgtConfiguration>
|
||||
|
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ 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.
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<DeviceMgtConfiguration>
|
||||
<ManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<MalformedJndiLookupDefinition>
|
||||
<Name>jdbc/DEVICE_MGT_DS</Name>
|
||||
</MalformedJndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
</ManagementRepository>
|
||||
</DeviceMgtConfiguration>
|
||||
|
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ 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.
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<DeviceMgtConfiguration>
|
||||
<MalformedManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/DEVICE_MGT_DS</Name>
|
||||
</JndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
</MalformedManagementRepository>
|
||||
</DeviceMgtConfiguration>
|
||||
|
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2015, 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.
|
||||
~ 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.
|
||||
-->
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
<xs:element name="DeviceMgtConfiguration">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="ManagementRepository" minOccurs="1" maxOccurs="1" type="DataSourceConfigurationType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:complexType name="JndiLookupDefinitionType">
|
||||
<xs:sequence>
|
||||
<xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="DataSourceConfigurationType">
|
||||
<xs:sequence>
|
||||
<xs:element name="JndiLookupDefinition" minOccurs="1" maxOccurs="1"
|
||||
type="JndiLookupDefinitionType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="ManagementRepositoryType">
|
||||
<xs:sequence>
|
||||
<xs:element name="DataSourceConfiguration" minOccurs="1" maxOccurs="1"
|
||||
type="DataSourceConfigurationType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
|
||||
|
||||
/**
|
||||
* This class represents the key operations associated with persisting operation related
|
||||
* information.
|
||||
*/
|
||||
public interface MobileOperationDAO {
|
||||
|
||||
/**
|
||||
* Add a new Mobile operation to plugin operation table.
|
||||
* @param operation Operation object that holds data related to the operation to be inserted.
|
||||
* @return The last inserted Id is returned, if the insertion was unsuccessful -1 is returned.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
int addMobileOperation(MobileOperation operation) throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update a Mobile operation in the operation table.
|
||||
* @param operation Operation object that holds data has to be updated.
|
||||
* @return The status of the operation. If the update was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateMobileOperation(MobileOperation operation) throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete a given Mobile operation from plugin database.
|
||||
* @param operationId Operation code of the operation to be deleted.
|
||||
* @return The status of the operation. If the operationId was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean deleteMobileOperation(int operationId) throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve a given Mobile operation from plugin database.
|
||||
* @param operationId Operation id of the operation to be retrieved.
|
||||
* @return Operation object that holds data of the feature represented by operationId.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
MobileOperation getMobileOperation(int operationId) throws MobileDeviceManagementDAOException;
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the key operations associated with persisting operation property related
|
||||
* information.
|
||||
*/
|
||||
public interface MobileOperationPropertyDAO {
|
||||
/**
|
||||
* Add a new mapping to plugin operation property table.
|
||||
*
|
||||
* @param operationProperty OperationProperty object that holds data related to the operation
|
||||
* property to be inserted.
|
||||
* @return The status of the operation. If the insert was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean addMobileOperationProperty(MobileOperationProperty operationProperty)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update a feature in the feature table.
|
||||
*
|
||||
* @param operationProperty DeviceOperation object that holds data has to be updated.
|
||||
* @return The status of the operation. If the update was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateMobileOperationProperty(MobileOperationProperty operationProperty)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Deletes mobile operation properties of a given operation id from the plugin database.
|
||||
*
|
||||
* @param operationId Operation id of the mapping to be deleted.
|
||||
* @return The status of the operation. If the deletion was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean deleteMobileOperationProperties(int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve a given mobile operation property from plugin database.
|
||||
*
|
||||
* @param operationId Operation id of the mapping to be retrieved.
|
||||
* @param property Property of the mapping to be retrieved.
|
||||
* @return DeviceOperation object that holds data of the device operation mapping represented by
|
||||
* deviceId and operationId.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
MobileOperationProperty getMobileOperationProperty(int operationId, String property)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve all the mobile operation properties related to the a operation id.
|
||||
*
|
||||
* @param operationId Operation id of the mapping to be retrieved.
|
||||
* @return Device operation mapping object list.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
List<MobileOperationProperty> getAllMobileOperationPropertiesOfOperation(int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.Operation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the key operations associated with persisting operation related
|
||||
* information.
|
||||
*/
|
||||
public interface OperationDAO {
|
||||
|
||||
/**
|
||||
* Add a new operation to plugin operation table.
|
||||
* @param operation Operation object that holds data related to the operation to be inserted.
|
||||
* @return The last inserted Id is returned, if the insertion was unsuccessful -1 is returned.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
int addOperation(Operation operation) throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update a operation in the operation table.
|
||||
* @param operation Operation object that holds data has to be updated.
|
||||
* @return The status of the operation. If the update was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateOperation(Operation operation) throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete a given operation from plugin database.
|
||||
* @param operationId Operation code of the operation to be deleted.
|
||||
* @return The status of the operation. If the operationId was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean deleteOperation(int operationId) throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve a given operation from plugin database.
|
||||
* @param operationId Operation id of the operation to be retrieved.
|
||||
* @return Operation object that holds data of the feature represented by operationId.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
Operation getOperation(int operationId) throws MobileDeviceManagementDAOException;
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.OperationProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the key operations associated with persisting operation property related
|
||||
* information.
|
||||
*/
|
||||
public interface OperationPropertyDAO {
|
||||
/**
|
||||
* Add a new mapping to plugin operation property table.
|
||||
*
|
||||
* @param operationProperty OperationProperty object that holds data related to the operation property to be inserted.
|
||||
* @return The status of the operation. If the insert was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean addOperationProperty(OperationProperty operationProperty)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update a feature in the feature table.
|
||||
*
|
||||
* @param operationProperty DeviceOperation object that holds data has to be updated.
|
||||
* @return The status of the operation. If the update was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateOperationProperty(OperationProperty operationProperty)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete a given device operation from plugin database.
|
||||
*
|
||||
* @param operationPropertyId Device id of the mapping to be deleted.
|
||||
* @return The status of the operation. If the deletion was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean deleteOperationProperty(int operationPropertyId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve a given device operation from plugin database.
|
||||
*
|
||||
* @param deviceId Device id of the mapping to be retrieved.
|
||||
* @param operationId Operation id of the mapping to be retrieved.
|
||||
* @return DeviceOperation object that holds data of the device operation mapping represented by deviceId and operationId.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
OperationProperty getOperationProperty(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve all the device operation mapping from plugin database.
|
||||
*
|
||||
* @return Device operation mapping object list.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
List<OperationProperty> getAllDeviceOperationOfDevice(String deviceId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
}
|
76
components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/DeviceOperationDAOImpl.java → components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationDAOImpl.java
76
components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/DeviceOperationDAOImpl.java → components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationDAOImpl.java
@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileOperationPropertyDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Implementation of MobileOperationPropertyDAO.
|
||||
*/
|
||||
public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(MobileOperationPropertyDAOImpl.class);
|
||||
|
||||
public MobileOperationPropertyDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addMobileOperationProperty(MobileOperationProperty operationProperty)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO MBL_OPERATION_PROPERTY(OPERATION_ID, PROPERTY, VALUE) VALUES ( ?, ?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setInt(1, operationProperty.getOperationId());
|
||||
stmt.setString(2, operationProperty.getProperty());
|
||||
stmt.setString(3, operationProperty.getValue());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while adding mobile operation property to MBL_OPERATION_PROPERTY table";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMobileOperationProperty(
|
||||
MobileOperationProperty operationProperty)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"UPDATE MBL_OPERATION_PROPERTY SET VALUE = ? WHERE OPERATION_ID = ? AND PROPERTY = ?";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, operationProperty.getValue());
|
||||
stmt.setInt(2, operationProperty.getOperationId());
|
||||
stmt.setString(3, operationProperty.getProperty());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while updating the mobile operation property in MBL_OPERATION_PROPERTY table.";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteMobileOperationProperties(int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setInt(1, operationId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while deleting MBL_OPERATION_PROPERTY entry with operation Id - ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileOperationProperty getMobileOperationProperty(int operationId,
|
||||
String property)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileOperationProperty mobileOperationProperty = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ? AND PROPERTY = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setInt(1, operationId);
|
||||
stmt.setString(2, property);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
mobileOperationProperty = new MobileOperationProperty();
|
||||
mobileOperationProperty.setOperationId(resultSet.getInt(1));
|
||||
mobileOperationProperty.setProperty(resultSet.getString(2));
|
||||
mobileOperationProperty.setValue(resultSet.getString(3));
|
||||
break;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while fetching the mobile operation property of Operation_id : " +
|
||||
operationId + " and Property : " + property;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return mobileOperationProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileOperationProperty> getAllMobileOperationPropertiesOfOperation(
|
||||
int operationId) throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileOperationProperty mobileOperationProperty = null;
|
||||
List<MobileOperationProperty> properties = new ArrayList<MobileOperationProperty>();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setInt(1, operationId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
mobileOperationProperty = new MobileOperationProperty();
|
||||
mobileOperationProperty.setOperationId(resultSet.getInt(1));
|
||||
mobileOperationProperty.setProperty(resultSet.getString(2));
|
||||
mobileOperationProperty.setValue(resultSet.getString(3));
|
||||
properties.add(mobileOperationProperty);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while fetching the mobile operation properties of Operation_id " +
|
||||
operationId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while obtaining a connection from the mobile device " +
|
||||
"management metadata repository datasource.";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.OperationPropertyDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.OperationProperty;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of OperationPropertyDAO
|
||||
*/
|
||||
public class OperationPropertyDAOImpl implements OperationPropertyDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(OperationPropertyDAOImpl.class);
|
||||
|
||||
public OperationPropertyDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addOperationProperty(OperationProperty operationProperty)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO MBL_OPERATION_PROPERTY(OPERATION_ID, PROPERTY_ID, VALUE) VALUES ( ?, ?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setInt(1, operationProperty.getOperationId());
|
||||
stmt.setInt(2, operationProperty.getPropertyId());
|
||||
stmt.setString(3, operationProperty.getValue());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding feature property to operation property table";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override public boolean updateOperationProperty(OperationProperty operationProperty)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean deleteOperationProperty(int operationPropertyId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public OperationProperty getOperationProperty(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public List<OperationProperty> getAllDeviceOperationOfDevice(String deviceId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while obtaining a connection from the mobile device " +
|
||||
"management metadata repository datasource.";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dto;
|
||||
|
||||
/**
|
||||
* DTO of Operations.
|
||||
*/
|
||||
public class DeviceOperation {
|
||||
String deviceId;
|
||||
int operationId;
|
||||
int sentDate;
|
||||
int receivedDate;
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public int getOperationId() {
|
||||
return operationId;
|
||||
}
|
||||
|
||||
public void setOperationId(int operationId) {
|
||||
this.operationId = operationId;
|
||||
}
|
||||
|
||||
public int getSentDate() {
|
||||
return sentDate;
|
||||
}
|
||||
|
||||
public void setSentDate(int sentDate) {
|
||||
this.sentDate = sentDate;
|
||||
}
|
||||
|
||||
public int getReceivedDate() {
|
||||
return receivedDate;
|
||||
}
|
||||
|
||||
public void setReceivedDate(int receivedDate) {
|
||||
this.receivedDate = receivedDate;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.dto;
|
||||
|
||||
/**
|
||||
* DTO of Mobile Device Operations.
|
||||
*/
|
||||
public class MobileDeviceOperation {
|
||||
|
||||
private String deviceId;
|
||||
private int operationId;
|
||||
private long sentDate;
|
||||
private long receivedDate;
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public int getOperationId() {
|
||||
return operationId;
|
||||
}
|
||||
|
||||
public void setOperationId(int operationId) {
|
||||
this.operationId = operationId;
|
||||
}
|
||||
|
||||
public long getSentDate() {
|
||||
return sentDate;
|
||||
}
|
||||
|
||||
public void setSentDate(long sentDate) {
|
||||
this.sentDate = sentDate;
|
||||
}
|
||||
|
||||
public long getReceivedDate() {
|
||||
return receivedDate;
|
||||
}
|
||||
|
||||
public void setReceivedDate(long receivedDate) {
|
||||
this.receivedDate = receivedDate;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2015, 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.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DTO of MobileOperation.
|
||||
*/
|
||||
public class MobileOperation {
|
||||
|
||||
private int operationId;
|
||||
private String featureCode;
|
||||
private long createdDate;
|
||||
private List<MobileOperationProperty> properties;
|
||||
|
||||
public int getOperationId() {
|
||||
return operationId;
|
||||
}
|
||||
|
||||
public void setOperationId(int operationId) {
|
||||
this.operationId = operationId;
|
||||
}
|
||||
|
||||
public List<MobileOperationProperty> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(List<MobileOperationProperty> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public String getFeatureCode() {
|
||||
return featureCode;
|
||||
}
|
||||
|
||||
public void setFeatureCode(String featureCode) {
|
||||
this.featureCode = featureCode;
|
||||
}
|
||||
|
||||
public long getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(long createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2015, 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.dto;
|
||||
|
||||
/**
|
||||
* DTO of Mobile Operation property.
|
||||
*/
|
||||
public class MobileOperationProperty {
|
||||
|
||||
private int operationId;
|
||||
private String property;
|
||||
private String value;
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getOperationId() {
|
||||
return operationId;
|
||||
}
|
||||
|
||||
public void setOperationId(int operationId) {
|
||||
this.operationId = operationId;
|
||||
}
|
||||
|
||||
public String getProperty() {
|
||||
return property;
|
||||
}
|
||||
|
||||
public void setProperty(String property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dto;
|
||||
|
||||
/**
|
||||
* DTO of operation.
|
||||
*/
|
||||
public class Operation {
|
||||
int operationId;
|
||||
String featureCode;
|
||||
int createdDate;
|
||||
|
||||
public int getOperationId() {
|
||||
return operationId;
|
||||
}
|
||||
|
||||
public void setOperationId(int operationId) {
|
||||
this.operationId = operationId;
|
||||
}
|
||||
|
||||
public String getFeatureCode() {
|
||||
return featureCode;
|
||||
}
|
||||
|
||||
public void setFeatureCode(String featureCode) {
|
||||
this.featureCode = featureCode;
|
||||
}
|
||||
|
||||
public int getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(int createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dto;
|
||||
|
||||
/**
|
||||
* DTO of operation property.
|
||||
*/
|
||||
public class OperationProperty {
|
||||
int operationPropertyId;
|
||||
int getOperationId;
|
||||
int propertyId;
|
||||
String value;
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getOperationPropertyId() {
|
||||
return operationPropertyId;
|
||||
}
|
||||
|
||||
public void setOperationPropertyId(int operationPropertyId) {
|
||||
this.operationPropertyId = operationPropertyId;
|
||||
}
|
||||
|
||||
public int getOperationId() {
|
||||
return getOperationId;
|
||||
}
|
||||
|
||||
public void setOperationId(int getOperationId) {
|
||||
this.getOperationId = getOperationId;
|
||||
}
|
||||
|
||||
public int getPropertyId() {
|
||||
return propertyId;
|
||||
}
|
||||
|
||||
public void setPropertyId(int propertyId) {
|
||||
this.propertyId = propertyId;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
/**
|
||||
* Copyright (c) 2015, 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.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.apimgt.api.APIManagementException;
|
||||
import org.wso2.carbon.apimgt.api.APIProvider;
|
||||
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
|
||||
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||
import org.wso2.carbon.device.mgt.mobile.config.APIConfig;
|
||||
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig;
|
||||
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerService;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService;
|
||||
import org.wso2.carbon.device.mgt.mobile.util.DeviceManagementAPIPublisherUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.device.mgt.mobile.impl.internal.MobileDeviceManagementServiceComponent"
|
||||
* immediate="true"
|
||||
* @scr.reference name="api.manager.config.service"
|
||||
* interface="org.wso2.carbon.apimgt.impl.APIManagerConfigurationService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setAPIManagerConfigurationService"
|
||||
* unbind="unsetAPIManagerConfigurationService"
|
||||
* <p/>
|
||||
* Adding reference to API Manager Configuration service is an unavoidable hack to get rid of NPEs thrown while
|
||||
* initializing APIMgtDAOs attempting to register APIs programmatically. APIMgtDAO needs to be proper cleaned up
|
||||
* to avoid as an ideal fix
|
||||
*/
|
||||
public class MobileDeviceManagementServiceComponent {
|
||||
|
||||
private ServiceRegistration androidServiceRegRef;
|
||||
private ServiceRegistration iOSServiceRegRef;
|
||||
private ServiceRegistration windowsServiceRegRef;
|
||||
|
||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class);
|
||||
|
||||
protected void activate(ComponentContext ctx) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Activating Mobile Device Management Service Component");
|
||||
}
|
||||
try {
|
||||
BundleContext bundleContext = ctx.getBundleContext();
|
||||
|
||||
/* Initialize the datasource configuration */
|
||||
MobileDeviceConfigurationManager.getInstance().initConfig();
|
||||
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
|
||||
.getMobileDeviceManagementConfig();
|
||||
MobileDataSourceConfig dsConfig =
|
||||
config.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
|
||||
|
||||
MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig);
|
||||
|
||||
androidServiceRegRef =
|
||||
bundleContext.registerService(DeviceManagerService.class.getName(),
|
||||
new AndroidDeviceManagerService(), null);
|
||||
iOSServiceRegRef =
|
||||
bundleContext.registerService(DeviceManagerService.class.getName(),
|
||||
new IOSDeviceManagerService(), null);
|
||||
windowsServiceRegRef =
|
||||
bundleContext.registerService(DeviceManagerService.class.getName(),
|
||||
new WindowsDeviceManagerService(), null);
|
||||
|
||||
/* Initialize all API configurations with corresponding API Providers */
|
||||
this.initAPIConfigs();
|
||||
/* Publish all mobile device management related JAX-RS services as APIs */
|
||||
this.publishAPIs();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Mobile Device Management Service Component has been successfully activated");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while activating Mobile Device Management Service Component", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void deactivate(ComponentContext ctx) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("De-activating Mobile Device Management Service Component");
|
||||
}
|
||||
try {
|
||||
BundleContext bundleContext = ctx.getBundleContext();
|
||||
|
||||
androidServiceRegRef.unregister();
|
||||
iOSServiceRegRef.unregister();
|
||||
windowsServiceRegRef.unregister();
|
||||
|
||||
/* Removing all APIs published upon start-up for mobile device management related JAX-RS
|
||||
services */
|
||||
this.removeAPIs();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Mobile Device Management Service Component has been successfully de-activated");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while de-activating Mobile Device Management bundle", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void initAPIConfigs() throws DeviceManagementException {
|
||||
List<APIConfig> apiConfigs =
|
||||
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
||||
getApiPublisherConfig().getAPIs();
|
||||
for (APIConfig apiConfig : apiConfigs) {
|
||||
try {
|
||||
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
|
||||
apiConfig.init(provider);
|
||||
} catch (APIManagementException e) {
|
||||
throw new DeviceManagementException("Error occurred while initializing API Config '" +
|
||||
apiConfig.getName() + "'", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void publishAPIs() throws DeviceManagementException {
|
||||
List<APIConfig> apiConfigs =
|
||||
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
||||
getApiPublisherConfig().getAPIs();
|
||||
for (APIConfig apiConfig : apiConfigs) {
|
||||
DeviceManagementAPIPublisherUtil.publishAPI(apiConfig);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeAPIs() throws DeviceManagementException {
|
||||
List<APIConfig> apiConfigs =
|
||||
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
||||
getApiPublisherConfig().getAPIs();
|
||||
for (APIConfig apiConfig : apiConfigs) {
|
||||
DeviceManagementAPIPublisherUtil.removeAPI(apiConfig);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService service) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2015 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.policy.evaluator;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface FeatureFilter {
|
||||
|
||||
List<Feature> evaluate(List<Policy> policyList, List<FeatureRules> featureRulesList);
|
||||
|
||||
List<Feature> extractFeatures(List<Policy> policyList);
|
||||
|
||||
List<Feature> evaluateFeatures(List<Feature> featureList, List<FeatureRules> featureRulesList);
|
||||
|
||||
void getDenyOverridesFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
|
||||
void getPermitOverridesFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
|
||||
void getFirstApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
|
||||
void getLastApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
|
||||
void getAllApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
|
||||
void getHighestApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
|
||||
void getLowestApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
}
|
@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Copyright (c) 2015 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.policy.evaluator;
|
||||
|
||||
import org.wso2.carbon.policy.evaluator.utils.Constants;
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is responsible for evaluating the policy (Configurations sets) and returning
|
||||
* the effective features set.
|
||||
*/
|
||||
|
||||
public class FeatureFilterImpl implements FeatureFilter {
|
||||
|
||||
/**
|
||||
* This method returns the effective feature list when policy list and feature aggregation rules are supplied.
|
||||
* @param policyList
|
||||
* @param featureRulesList
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Feature> evaluate(List<Policy> policyList, List<FeatureRules> featureRulesList) {
|
||||
return evaluateFeatures(extractFeatures(policyList), featureRulesList);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method extract the features from the given policy list in the order they are provided in the list.
|
||||
* @param policyList
|
||||
* @return
|
||||
*/
|
||||
public List<Feature> extractFeatures(List<Policy> policyList) {
|
||||
List<Feature> featureList = new ArrayList<Feature>();
|
||||
for (Policy policy : policyList) {
|
||||
featureList.addAll(policy.getFeaturesList());
|
||||
}
|
||||
return featureList;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is responsible for supplying tasks to other methods to evaluate given features.
|
||||
* @param featureList
|
||||
* @param featureRulesList
|
||||
* @return
|
||||
*/
|
||||
public List<Feature> evaluateFeatures(List<Feature> featureList, List<FeatureRules> featureRulesList) {
|
||||
List<Feature> effectiveFeatureList = new ArrayList<Feature>();
|
||||
for (FeatureRules rule : featureRulesList) {
|
||||
String ruleName = rule.getEvaluationCriteria();
|
||||
String featureName = rule.getName();
|
||||
if (ruleName.equalsIgnoreCase(Constants.DENY_OVERRIDES)) {
|
||||
getDenyOverridesFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
if (ruleName.equalsIgnoreCase(Constants.PERMIT_OVERRIDES)) {
|
||||
getPermitOverridesFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
if (ruleName.equalsIgnoreCase(Constants.FIRST_APPLICABLE)) {
|
||||
getFirstApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
if (ruleName.equalsIgnoreCase(Constants.LAST_APPLICABLE)) {
|
||||
getLastApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
if (ruleName.equalsIgnoreCase(Constants.ALL_APPLICABLE)) {
|
||||
getAllApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
if (ruleName.equalsIgnoreCase(Constants.HIGHEST_APPLICABLE)) {
|
||||
getHighestApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
if (ruleName.equalsIgnoreCase(Constants.LOWEST_APPLICABLE)) {
|
||||
getLowestApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
}
|
||||
return effectiveFeatureList;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks up denied features, if there is no denied features it will add to the list, the final permitted feature.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getDenyOverridesFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
Feature evaluatedFeature = null;
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
if (feature.getRuleValue().equalsIgnoreCase("Deny")) {
|
||||
evaluatedFeature = feature;
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
return;
|
||||
} else {
|
||||
evaluatedFeature = feature;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (evaluatedFeature != null) {
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks up permitted features, if there is no permitted features it will add to the list, the final denied feature.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getPermitOverridesFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
Feature evaluatedFeature = null;
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
if (feature.getRuleValue().equalsIgnoreCase("Permit")) {
|
||||
evaluatedFeature = feature;
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
return;
|
||||
} else {
|
||||
evaluatedFeature = feature;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (evaluatedFeature != null) {
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks the first features of the give type.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getFirstApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
effectiveFeatureList.add(feature);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks the last features of the give type.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getLastApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
Feature evaluatedFeature = null;
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
evaluatedFeature = feature;
|
||||
}
|
||||
}
|
||||
if (evaluatedFeature != null) {
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks the all features of the give type.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getAllApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
effectiveFeatureList.add(feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks the feature with the highest value of given type.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getHighestApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
Feature evaluatedFeature = null;
|
||||
int intValve = 0;
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
if (Integer.parseInt(feature.getRuleValue()) > intValve) {
|
||||
intValve = Integer.parseInt(feature.getRuleValue());
|
||||
evaluatedFeature = feature;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (evaluatedFeature != null) {
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks the feature with the lowest value of given type.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getLowestApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
Feature evaluatedFeature = null;
|
||||
int intValve = 0;
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
if (Integer.parseInt(feature.getRuleValue()) < intValve) {
|
||||
intValve = Integer.parseInt(feature.getRuleValue());
|
||||
evaluatedFeature = feature;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (evaluatedFeature != null) {
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2015 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.policy.evaluator;
|
||||
|
||||
public class FeatureRules {
|
||||
|
||||
private String name;
|
||||
private String evaluationCriteria;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEvaluationCriteria() {
|
||||
return evaluationCriteria;
|
||||
}
|
||||
|
||||
public void setEvaluationCriteria(String evaluationCriteria) {
|
||||
this.evaluationCriteria = evaluationCriteria;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.policy.evaluator;
|
||||
|
||||
import org.wso2.carbon.policy.evaluator.spi.PDPService;
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PDPServiceImpl implements PDPService {
|
||||
@Override
|
||||
public List<Policy> getEffectivePolicyList(List<Policy> policies, List<String> roles, String deviceType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getEffectiveFeatureList(List<Policy> policies, List<FeatureRules> featureRulesList) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2015 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.policy.evaluator;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PolicyFilter {
|
||||
|
||||
/**
|
||||
* This method will extract the policies related a given roles list from the policy list available.
|
||||
* @param policyList
|
||||
* @param roles
|
||||
* @return
|
||||
*/
|
||||
public List<Policy> extractPoliciesRelatedToRoles(List<Policy> policyList, List<String> roles);
|
||||
|
||||
/**
|
||||
* This mehtod extract the policies related to a given device type from policy list.
|
||||
* @param policyList
|
||||
* @param deviceType
|
||||
* @return
|
||||
*/
|
||||
public List<Policy> extractPoliciesRelatedToDeviceType(List<Policy> policyList, String deviceType);
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2015 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.policy.evaluator;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyFilterImpl implements PolicyFilter {
|
||||
|
||||
|
||||
/**
|
||||
* This method will extract the policies related a given roles list from the policy list available.
|
||||
*
|
||||
* @param policyList
|
||||
* @param roles
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Policy> extractPoliciesRelatedToRoles(List<Policy> policyList, List<String> roles) {
|
||||
|
||||
List<Policy> policies = new ArrayList<Policy>();
|
||||
|
||||
for (Policy policy : policyList) {
|
||||
List<String> roleList = policy.getRoleList();
|
||||
|
||||
for (String role : roleList) {
|
||||
if (roles.contains(role)) {
|
||||
policies.add(policy);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return policies;
|
||||
}
|
||||
|
||||
/**
|
||||
* This mehtod extract the policies related to a given device type from policy list.
|
||||
*
|
||||
* @param policyList
|
||||
* @param deviceType
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Policy> extractPoliciesRelatedToDeviceType(List<Policy> policyList, String deviceType) {
|
||||
List<Policy> policies = new ArrayList<Policy>();
|
||||
|
||||
for (Policy policy : policyList) {
|
||||
if (policy.getDeviceType().equalsIgnoreCase(deviceType)) {
|
||||
policies.add(policy);
|
||||
}
|
||||
}
|
||||
return policies;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2015 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.policy.evaluator.utils;
|
||||
|
||||
public class Constants {
|
||||
|
||||
public static final String DENY_OVERRIDES="deny_overrides";
|
||||
public static final String PERMIT_OVERRIDES="permit_overrides";
|
||||
public static final String FIRST_APPLICABLE="first_applicable";
|
||||
public static final String LAST_APPLICABLE="last_applicable";
|
||||
public static final String ALL_APPLICABLE="all_applicable";
|
||||
public static final String HIGHEST_APPLICABLE="highest_applicable";
|
||||
public static final String LOWEST_APPLICABLE="lowest_applicable";
|
||||
}
|
@ -1,24 +1,21 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* 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.policy.mgt.core.util;
|
||||
|
||||
public final class PolicyManagementConstants {
|
||||
|
||||
public static final String DEVICE_CONFIG_XML_NAME = "cdm-config.xml";
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE
|
||||
(
|
||||
ID INT(11) auto_increment NOT NULL,
|
||||
NAME VARCHAR(300) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE
|
||||
(
|
||||
ID INT auto_increment NOT NULL,
|
||||
DESCRIPTION TEXT NULL DEFAULT NULL,
|
||||
NAME VARCHAR(100) NULL DEFAULT NULL,
|
||||
DATE_OF_ENROLLMENT BIGINT NULL DEFAULT NULL,
|
||||
DATE_OF_LAST_UPDATE BIGINT NULL DEFAULT NULL,
|
||||
OWNERSHIP VARCHAR(45) NULL DEFAULT NULL,
|
||||
STATUS VARCHAR(15) NULL DEFAULT NULL,
|
||||
DEVICE_TYPE_ID INT(11) NULL DEFAULT NULL,
|
||||
DEVICE_IDENTIFICATION VARCHAR(300) NULL DEFAULT NULL,
|
||||
OWNER VARCHAR(45) NULL DEFAULT NULL,
|
||||
TENANT_ID INTEGER DEFAULT 0,
|
||||
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');
|
@ -0,0 +1,35 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_DEVICE_TYPE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`NAME` VARCHAR(300) NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `DM_DEVICE` (
|
||||
`ID` VARCHAR(20) NOT NULL ,
|
||||
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
|
||||
`NAME` VARCHAR(100) NULL DEFAULT NULL ,
|
||||
`DATE_OF_ENROLLMENT` DATETIME NULL DEFAULT NULL ,
|
||||
`DATE_OF_LAST_UPDATE` DATETIME NULL DEFAULT NULL ,
|
||||
`OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`STATUS` VARCHAR(15) NULL DEFAULT NULL ,
|
||||
`DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL ,
|
||||
`DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL ,
|
||||
`OWNER` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
TENANT_ID INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2_idx` (`DEVICE_TYPE_ID` ASC) ,
|
||||
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)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue