diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java new file mode 100644 index 0000000000..5bef9e6226 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java @@ -0,0 +1,39 @@ +/* + * + * * 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.device.mgt.core.dto.operation.mgt; + +public class CommandOperation extends Operation { + + private boolean enabled; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public Type getType() { + return Type.COMMAND; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java new file mode 100644 index 0000000000..8e99dda978 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java @@ -0,0 +1,82 @@ +/* + * + * * 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.device.mgt.core.dto.operation.mgt; + +import java.util.ArrayList; +import java.util.List; + +public class ConfigOperation extends Operation { + + private List properties; + + public ConfigOperation() { + properties = new ArrayList(); + } + + public List getConfigProperties() { + return properties; + } + + public void addConfigProperty(String name, Object value, Class type) { + properties.add(new Property(name, value, type)); + } + + public class Property { + private String name; + private Object value; + private Class type; + + public Property(String name, Object value, Class type) { + this.name = name; + this.value = value; + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public Class getType() { + return type; + } + + public void setType(Class type) { + this.type = type; + } + } + + public Type getType() { + return Type.CONFIG; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java new file mode 100644 index 0000000000..08a26c38f6 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java @@ -0,0 +1,126 @@ +/* + * + * * 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.device.mgt.core.dto.operation.mgt; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.io.Serializable; +import java.util.Properties; + +@XmlRootElement +public class Operation implements Serializable { + + public enum Type { + CONFIG, MESSAGE, INFO, COMMAND, PROFILE + } + + public enum Status { + IN_PROGRESS, PENDING, COMPLETED, ERROR + } + + private String code; + private Properties properties; + private Type type; + private int id; + private Status status; + private String receivedTimeStamp; + private String createdTimeStamp; + private boolean isEnabled; + private Object payLoad; + + @XmlElement + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + @XmlElement + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + + @XmlElement + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + + public String getReceivedTimeStamp() { + return receivedTimeStamp; + } + + public void setReceivedTimeStamp(String receivedTimeStamp) { + this.receivedTimeStamp = receivedTimeStamp; + } + + public String getCreatedTimeStamp() { + return createdTimeStamp; + } + + public void setCreatedTimeStamp(String createdTimeStamp) { + this.createdTimeStamp = createdTimeStamp; + } + + public boolean isEnabled() { + return isEnabled; + } + + public void setEnabled(boolean isEnabled) { + this.isEnabled = isEnabled; + } + + public Object getPayLoad() { + return payLoad; + } + + public void setPayLoad(Object payLoad) { + this.payLoad = payLoad; + } + + +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java new file mode 100644 index 0000000000..45ca2612e0 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java @@ -0,0 +1,31 @@ +/* + * + * * 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.device.mgt.core.dto.operation.mgt; + +import java.io.Serializable; + +public class ProfileOperation extends ConfigOperation implements Serializable { + + public Type getType() { + return Type.PROFILE; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java new file mode 100644 index 0000000000..3025496814 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java @@ -0,0 +1,87 @@ +/* + * 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.device.mgt.core.operation.mgt.dao.util; + +import org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation; +import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation; + +public class OperationDAOUtil { + + public static Operation convertOperation(org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation){ + + Operation dtoOperation = null; + + if (operation.getType().equals(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.COMMAND)){ + dtoOperation = new CommandOperation(); + }else if(operation.getType().equals(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.PROFILE)){ + dtoOperation = new ProfileOperation(); + }else{ + dtoOperation = new Operation(); + } + + dtoOperation.setEnabled(operation.isEnabled()); + dtoOperation.setCode(operation.getCode()); + + if (operation.getType() != null){ + dtoOperation.setType(Operation.Type.valueOf(operation.getType().toString())); + }else{ + dtoOperation.setType(null); + } + + dtoOperation.setCreatedTimeStamp(operation.getCreatedTimeStamp()); + + if (operation.getStatus() != null){ + dtoOperation.setStatus(Operation.Status.valueOf(operation.getStatus().toString())); + }else{ + dtoOperation.setStatus(null); + } + + dtoOperation.setId(operation.getId()); + dtoOperation.setPayLoad(operation.getPayLoad()); + dtoOperation.setReceivedTimeStamp(operation.getReceivedTimeStamp()); + + return dtoOperation; + } + + public static org.wso2.carbon.device.mgt.common.operation.mgt.Operation convertOperation(Operation dtoOperation){ + + org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null; + + if (dtoOperation.getType().equals(Operation.Type.COMMAND)){ + operation = new org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation(); + }else if(dtoOperation.getType().equals(Operation.Type.PROFILE)){ + operation = new org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation(); + }else{ + operation = new org.wso2.carbon.device.mgt.common.operation.mgt.Operation(); + } + operation.setEnabled(dtoOperation.isEnabled()); + operation.setCode(dtoOperation.getCode()); + operation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.valueOf(dtoOperation + .getType().toString())); + operation.setCreatedTimeStamp(dtoOperation.getCreatedTimeStamp()); + operation.setStatus(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Status.valueOf(dtoOperation + .getStatus().toString())); + operation.setId(dtoOperation.getId()); + operation.setPayLoad(dtoOperation.getPayLoad()); + operation.setReceivedTimeStamp(dtoOperation.getReceivedTimeStamp()); + + return operation; + } +}