Doing a partial commit for pull

revert-70aa11f8
geethkokila 9 years ago
parent be890c2e9a
commit 1826c9ee49

@ -0,0 +1,64 @@
/*
* Copyright (c) 2016, 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.device.details;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
public class DeviceWrapper {
private Device device;
private DeviceIdentifier deviceIdentifier;
private DeviceInfo deviceInfo;
private DeviceLocation deviceLocation;
public Device getDevice() {
return device;
}
public void setDevice(Device device) {
this.device = device;
}
public DeviceIdentifier getDeviceIdentifier() {
return deviceIdentifier;
}
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
this.deviceIdentifier = deviceIdentifier;
}
public DeviceInfo getDeviceInfo() {
return deviceInfo;
}
public void setDeviceInfo(DeviceInfo deviceInfo) {
this.deviceInfo = deviceInfo;
}
public DeviceLocation getDeviceLocation() {
return deviceLocation;
}
public void setDeviceLocation(DeviceLocation deviceLocation) {
this.deviceLocation = deviceLocation;
}
}

@ -0,0 +1,42 @@
/*
* Copyright (c) 2016, 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.search;
public class Condition {
private String key;
private String value;
public String mark;
private State state;
public enum State {
AND, OR;
};
public State getState(){
return state;
}
public void setState(State state){
this.state = state;
}
}

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016, 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.search;
public class SearchContext {
}

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016, 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.device.details.mgt;
public class DeviceDetailsMgtException {
}

@ -0,0 +1,79 @@
/*
* Copyright (c) 2016, 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.device.details.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
/**
* This class will manage the storing of device details related generic information such as cpu/memory utilization, battery level,
* plugged in to a power source or operation on battery.
* In CDM framework, we only keep the snapshot of the device information. So previous details are deleted as soon as new
* data is arrived.
*/
public interface DeviceInformationManager {
/**
* This method will manage the storing of the device information as key value pairs.
* @param deviceInfo - Device info object.
* @throws DeviceDetailsMgtException
*/
void addDeviceInfo(DeviceInfo deviceInfo) throws DeviceDetailsMgtException;
/**
* This method will return the device information.
* @param deviceIdentifier - Device identifier, device type.
* @return - Device information object.
* @throws DeviceDetailsMgtException
*/
DeviceInfo getDeviceInfo(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException;
/**
* This method will manage storing the device location as latitude, longitude, address, zip, country etc..
* @param deviceLocation - Device location object.
* @throws DeviceDetailsMgtException
*/
void addDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtException;
/**
* This method will return the device location with latitude, longitude, address etc..
* @param deviceIdentifier - Device identifier, device type.
* @return Device location object.
* @throws DeviceDetailsMgtException
*/
DeviceLocation getDeviceLocation(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException;
// /**
// * This method will manage the storing of device application list.
// * @param deviceApplication - Device application list.
// * @throws DeviceDetailsMgtException
// */
// void addDeviceApplications(DeviceApplication deviceApplication) throws DeviceDetailsMgtException;
//
// /**
// * This method will return the application list of the device.
// * @param deviceIdentifier - Device identifier, device type.
// * @return - Device application list with device identifier.
// * @throws DeviceDetailsMgtException
// */
// DeviceApplication getDeviceApplication(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException;
}

@ -0,0 +1,78 @@
/*
* Copyright (c) 2016, 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.device.details.mgt.dao;
import org.wso2.carbon.device.mgt.common.device.details.DeviceApplication;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtDAOException;
/**
* This class will store device details related generic information such as cpu/memory utilization, battery level,
* plugged in to a power source or operation on battery.
*/
public interface DeviceDetailsDAO {
/**
* This method will add device information to the database.
* @param deviceInfo - Device information object.
* @throws DeviceDetailsMgtDAOException
*/
void addDeviceInformation(DeviceInfo deviceInfo) throws DeviceDetailsMgtDAOException;
/**
* This method will return the device information when device id is provided.
* @param deviceId - device Id
* @return DeviceInfo
* @throws DeviceDetailsMgtDAOException
*/
DeviceInfo getDeviceInformation(int deviceId) throws DeviceDetailsMgtDAOException;
/**
* This method will add device location to database.
* @param deviceLocation - Device location with latitude and longitude.
* @throws DeviceDetailsMgtDAOException
*/
void addDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtDAOException;
/**
* This method will return the device location object when the device id is provided.
* @param deviceId - id of the device.
* @return - Device location object.
* @throws DeviceDetailsMgtDAOException
*/
DeviceLocation getDeviceLocation(int deviceId) throws DeviceDetailsMgtDAOException;
/**
* This method will add device application to database.
* @param deviceApplication - Device application
* @throws DeviceDetailsMgtDAOException
*/
void addDeviceApplications(DeviceApplication deviceApplication) throws DeviceDetailsMgtDAOException;
/**
* This method will return the device application list once device id is provided.
* @param deviceId
* @return
* @throws DeviceDetailsMgtDAOException
*/
DeviceApplication getDeviceApplications(int deviceId) throws DeviceDetailsMgtDAOException;
}

@ -0,0 +1,61 @@
/*
* Copyright (c) 2016, 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.device.details.mgt.dao;
public class DeviceDetailsMgtDAOException extends Exception{
private static final long serialVersionUID = -3151279311366666499L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public DeviceDetailsMgtDAOException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public DeviceDetailsMgtDAOException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public DeviceDetailsMgtDAOException(String msg) {
super(msg);
setErrorMessage(msg);
}
public DeviceDetailsMgtDAOException() {
super();
}
public DeviceDetailsMgtDAOException(Throwable cause) {
super(cause);
}
}

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016, 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.device.details.mgt.dao.impl;
public class DeviceDetailsDAOImpl {
}

@ -0,0 +1,142 @@
/*
* Copyright (c) 2016, 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.device.details.mgt.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInfomationManager;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import java.sql.SQLException;
public class DeviceInformationManagerImpl implements DeviceInfomationManager {
private static Log log = LogFactory.getLog(DeviceInformationManagerImpl.class);
private DeviceDetailsDAO deviceDetailsDAO;
public DeviceInformationManagerImpl() {
this.deviceDetailsDAO = DeviceManagementDAOFactory.getDeviceDetailsDAO();
}
@Override
public void addDeviceInfo(DeviceInfo deviceInfo) throws DeviceDetailsMgtException {
try {
DeviceManagementDAOFactory.beginTransaction();
deviceDetailsDAO.deleteDeviceInformation(deviceInfo.getDeviceId());
deviceDetailsDAO.deleteDeviceProperties(deviceInfo.getDeviceId());
deviceDetailsDAO.addDeviceInformation(deviceInfo);
deviceDetailsDAO.addDeviceProperties(deviceInfo.getDeviceDetailsMap(), deviceInfo.getDeviceId());
DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceDetailsMgtException("Transactional error occurred while adding the device information.");
} catch (DeviceDetailsMgtDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceDetailsMgtException("Error occurred while adding the device information.");
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Override
public DeviceInfo getDeviceInfo(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException {
try {
Device device = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getDevice(deviceIdentifier);
DeviceManagementDAOFactory.openConnection();
DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(device.getId());
deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(device.getId()));
return deviceInfo;
} catch (SQLException e) {
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e);
} catch (DeviceManagementException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving the device.", e);
} catch (DeviceDetailsMgtDAOException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving device details.", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Override
public void addDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtException {
try {
DeviceManagementDAOFactory.beginTransaction();
deviceDetailsDAO.deleteDeviceLocation(deviceLocation.getDeviceId());
deviceDetailsDAO.addDeviceLocation(deviceLocation);
DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceDetailsMgtException("Transactional error occurred while adding the device location information.");
} catch (DeviceDetailsMgtDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceDetailsMgtException("Error occurred while adding the device location information.");
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Override
public DeviceLocation getDeviceLocation(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException {
try {
Device device = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getDevice(deviceIdentifier);
DeviceManagementDAOFactory.openConnection();
return deviceDetailsDAO.getDeviceLocation(device.getId());
} catch (SQLException e) {
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e);
} catch (DeviceManagementException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving the device.", e);
} catch (DeviceDetailsMgtDAOException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving device location.", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
// @Override
// public void addDeviceApplications(DeviceApplication deviceApplication) throws DeviceDetailsMgtException {
//
// }
//
// @Override
// public DeviceApplication getDeviceApplication(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException {
// return null;
// }
}

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016, 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.search.mgt;
public class Constants {
}

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016, 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.search.mgt;
public class InvalidOperatorException {
}

@ -0,0 +1,38 @@
/*
* Copyright (c) 2016, 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.search.mgt;
import org.wso2.carbon.device.mgt.common.search.Condition;
import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException;
import java.util.List;
public interface QueryBuilder {
void processAND(List<Condition> conditions) throws InvalidOperatorException;
void processOR(List<Condition> conditions) throws InvalidOperatorException;
void processEQUALS(List<Condition> conditions) throws InvalidOperatorException;
void processGREATERTHAN(List<Condition> conditions) throws InvalidOperatorException;
void processLESSTHAN(List<Condition> conditions) throws InvalidOperatorException;
}

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016, 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.search.mgt;
public class SearchMgtException {
}

@ -0,0 +1,23 @@
/*
* Copyright (c) 2016, 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.search.mgt.dao;
public interface SearchDAO {
}

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016, 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.search.mgt.dao.impl;
public class SearchDAOImpl {
}

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016, 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.search.mgt.impl;
public class ProcessorImpl {
}

@ -0,0 +1,66 @@
/*
* Copyright (c) 2016, 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.search.mgt.impl;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.core.search.mgt.ResultSetAggregator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ResultSetAggregatorImpl implements ResultSetAggregator {
@Override
public List<DeviceWrapper> aggregate(Map<String, List<DeviceWrapper>> deviceWrappers) {
Map<Integer, DeviceWrapper> generalQueryMap = this.convertToMap(deviceWrappers.get("GENERAL"));
Map<Integer, DeviceWrapper> andMap = this.convertToMap(deviceWrappers.get("PROP_AND"));
Map<Integer, DeviceWrapper> orMap = this.convertToMap(deviceWrappers.get("PROP_OR"));
List<DeviceWrapper> finalResult = new ArrayList<>();
for (Integer a : andMap.keySet()) {
if(generalQueryMap.containsKey(a)) {
finalResult.add(andMap.get(a));
}
}
for (Integer a : orMap.keySet()) {
finalResult.add(orMap.get(a));
}
return finalResult;
}
private Map<Integer, DeviceWrapper> convertToMap(List<DeviceWrapper> deviceWrappers) {
if (deviceWrappers == null) {
return null;
}
Map<Integer, DeviceWrapper> deviceWrapperMap = new HashMap<>();
for (DeviceWrapper dw : deviceWrappers) {
deviceWrapperMap.put(dw.getDevice().getId(), dw);
}
return deviceWrapperMap;
}
}

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016, 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.search.mgt.impl;
public class Utils {
}

@ -0,0 +1,60 @@
/*
* Copyright (c) 2016, 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.task;
public class DeviceMgtTaskException extends Exception {
private static final long serialVersionUID = -31222242646464497L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public DeviceMgtTaskException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public DeviceMgtTaskException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public DeviceMgtTaskException(String msg) {
super(msg);
setErrorMessage(msg);
}
public DeviceMgtTaskException() {
super();
}
public DeviceMgtTaskException(Throwable cause) {
super(cause);
}
}

@ -0,0 +1,33 @@
/*
* Copyright (c) 2016, 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.task;
import java.util.List;
public interface DeviceTaskManager {
/**
* This method will get the operation list from
* @return
* @throws DeviceMgtTaskException
*/
List<TaskOperation> getOperationList() throws DeviceMgtTaskException;
}

@ -0,0 +1,59 @@
/*
* Copyright (c) 2016, 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.task.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
import org.wso2.carbon.ntask.core.Task;
import java.util.Map;
public class DeviceDetailsRetrieverTask implements Task {
private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class);
private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl();
@Override
public void setProperties(Map<String, String> map) {
}
@Override
public void init() {
}
@Override
public void execute() {
if (log.isDebugEnabled()) {
log.debug("Device details retrieving task started to run.");
}
try {
deviceTaskManager.addOperations();
} catch (DeviceMgtTaskException e) {
log.error("Error occurred while trying to add the operations to device to retrieve device details.", e);
}
}
}

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016, 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.Search;
public class DeviceDetails {
}

@ -0,0 +1,24 @@
/*
* Copyright (c) 2016, 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.search.util;
public class Utils {
}
Loading…
Cancel
Save