Changing apis to return activity when an operation is added

revert-70aa11f8
geethkokila 9 years ago
parent afba711969
commit c64a6e0ec5

@ -20,6 +20,7 @@
package org.wso2.carbon.device.mgt.common.app.mgt; package org.wso2.carbon.device.mgt.common.app.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import java.util.List; import java.util.List;
@ -66,12 +67,12 @@ public interface ApplicationManager {
throws ApplicationManagementException; throws ApplicationManagementException;
void installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIdentifiers) Activity installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws ApplicationManagementException; throws ApplicationManagementException;
void installApplicationForUsers(Operation operation, List<String> userNameList) Activity installApplicationForUsers(Operation operation, List<String> userNameList)
throws ApplicationManagementException; throws ApplicationManagementException;
void installApplicationForUserRoles(Operation operation, List<String> userRoleList) Activity installApplicationForUserRoles(Operation operation, List<String> userRoleList)
throws ApplicationManagementException; throws ApplicationManagementException;
} }

@ -0,0 +1,65 @@
/*
* 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.operation.mgt;
public class Activity {
public enum Type {
CONFIG, MESSAGE, INFO, COMMAND, PROFILE, POLICY
}
private String activityId;
private String code;
private Type type;
private String createdTimeStamp;
public String getActivityId() {
return activityId;
}
public void setActivityId(String activityId) {
this.activityId = activityId;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public String getCreatedTimeStamp() {
return createdTimeStamp;
}
public void setCreatedTimeStamp(String createdTimeStamp) {
this.createdTimeStamp = createdTimeStamp;
}
}

@ -0,0 +1,68 @@
/*
* 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.operation.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import java.util.List;
public class ActivityStatus {
public enum Status {
IN_PROGRESS, PENDING, COMPLETED, ERROR, REPEATED
}
private DeviceIdentifier deviceIdentifier;
private Status status;
private List<OperationResponse> responses;
private String updatedTimestamp;
public DeviceIdentifier getDeviceIdentifier() {
return deviceIdentifier;
}
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
this.deviceIdentifier = deviceIdentifier;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public List<OperationResponse> getResponses() {
return responses;
}
public void setResponses(List<OperationResponse> responses) {
this.responses = responses;
}
public String getUpdatedTimestamp() {
return updatedTimestamp;
}
public void setUpdatedTimestamp(String updatedTimestamp) {
this.updatedTimestamp = updatedTimestamp;
}
}

@ -38,7 +38,7 @@ public interface OperationManager {
* @throws OperationManagementException If some unusual behaviour is observed while adding the * @throws OperationManagementException If some unusual behaviour is observed while adding the
* operation * operation
*/ */
int addOperation(Operation operation, List<DeviceIdentifier> devices) throws OperationManagementException; Activity addOperation(Operation operation, List<DeviceIdentifier> devices) throws OperationManagementException;
/** /**
* Method to retrieve the list of all operations to a device. * Method to retrieve the list of all operations to a device.

@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.TransactionManagementException; import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
@ -91,7 +92,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
} }
@Override @Override
public void installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIds) public Activity installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIds)
throws ApplicationManagementException { throws ApplicationManagementException {
try { try {
//TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()" //TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
@ -99,10 +100,11 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
if (deviceIds.size() > 0) { if (deviceIds.size() > 0) {
type = deviceIds.get(0).getType(); type = deviceIds.get(0).getType();
} }
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(type, operation, Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
deviceIds); addOperation(type, operation, deviceIds);
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().notifyOperationToDevices DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().notifyOperationToDevices
(operation, deviceIds); (operation, deviceIds);
return activity;
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
throw new ApplicationManagementException("Error in add operation at app installation", e); throw new ApplicationManagementException("Error in add operation at app installation", e);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
@ -111,7 +113,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
} }
@Override @Override
public void installApplicationForUsers(Operation operation, List<String> userNameList) public Activity installApplicationForUsers(Operation operation, List<String> userNameList)
throws ApplicationManagementException { throws ApplicationManagementException {
String userName = null; String userName = null;
@ -138,9 +140,10 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
if (deviceIdentifierList.size() > 0) { if (deviceIdentifierList.size() > 0) {
type = deviceIdentifierList.get(0).getType(); type = deviceIdentifierList.get(0).getType();
} }
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.addOperation(type, operation, deviceIdentifierList); .addOperation(type, operation, deviceIdentifierList);
return activity;
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new ApplicationManagementException("Error in get devices for user: " + userName + throw new ApplicationManagementException("Error in get devices for user: " + userName +
" in app installation", e); " in app installation", e);
@ -152,7 +155,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
} }
@Override @Override
public void installApplicationForUserRoles(Operation operation, List<String> userRoleList) public Activity installApplicationForUserRoles(Operation operation, List<String> userRoleList)
throws ApplicationManagementException { throws ApplicationManagementException {
String userRole = null; String userRole = null;
@ -178,9 +181,9 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
if (deviceIdentifierList.size() > 0) { if (deviceIdentifierList.size() > 0) {
type = deviceIdentifierList.get(0).getType(); type = deviceIdentifierList.get(0).getType();
} }
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(type, operation, Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(type, operation,
deviceIdentifierList); deviceIdentifierList);
return activity;
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new ApplicationManagementException("Error in get devices for user role " + userRole + throw new ApplicationManagementException("Error in get devices for user role " + userRole +
" in app installation", e); " in app installation", e);

@ -24,6 +24,7 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
@ -47,6 +48,7 @@ import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerImpl;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -83,7 +85,7 @@ public class OperationManagerImpl implements OperationManager {
} }
@Override @Override
public int addOperation(Operation operation, public Activity addOperation(Operation operation,
List<DeviceIdentifier> deviceIds) throws OperationManagementException { List<DeviceIdentifier> deviceIds) throws OperationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("operation:[" + operation.toString() + "]"); log.debug("operation:[" + operation.toString() + "]");
@ -96,7 +98,7 @@ public class OperationManagerImpl implements OperationManager {
List<DeviceIdentifier> authorizedDeviceList = this.getAuthorizedDevices(operation, deviceIds); List<DeviceIdentifier> authorizedDeviceList = this.getAuthorizedDevices(operation, deviceIds);
if (authorizedDeviceList.size() <= 0) { if (authorizedDeviceList.size() <= 0) {
log.info("User : " + getUser() + " is not authorized to perform operations on given device-list."); log.info("User : " + getUser() + " is not authorized to perform operations on given device-list.");
return -1; return null;
} }
List<EnrolmentInfo> enrolments = this.getEnrollmentsByStatus(deviceIds); List<EnrolmentInfo> enrolments = this.getEnrollmentsByStatus(deviceIds);
@ -128,7 +130,12 @@ public class OperationManagerImpl implements OperationManager {
} }
} }
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();
return operationId; Activity activity = new Activity();
activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
activity.setCode(operationDto.getCode());
activity.setCreatedTimeStamp(new Date().toString());
activity.setType(Activity.Type.valueOf(operationDto.getType().toString()));
return activity;
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
OperationManagementDAOFactory.rollbackTransaction(); OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException("Error occurred while adding operation", e); throw new OperationManagementException("Error occurred while adding operation", e);

@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
@ -43,9 +44,9 @@ public class PushNotificationBasedOperationManager implements OperationManager {
} }
@Override @Override
public int addOperation(Operation operation, public Activity addOperation(Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException { List<DeviceIdentifier> devices) throws OperationManagementException {
int operationId = this.operationManager.addOperation(operation, devices); Activity activity = this.operationManager.addOperation(operation, devices);
for (DeviceIdentifier deviceId : devices) { for (DeviceIdentifier deviceId : devices) {
try { try {
this.notificationProvider.execute(new NotificationContext(deviceId)); this.notificationProvider.execute(new NotificationContext(deviceId));
@ -53,7 +54,7 @@ public class PushNotificationBasedOperationManager implements OperationManager {
throw new OperationManagementException("Error occurred while sending push notification to device", e); throw new OperationManagementException("Error occurred while sending push notification to device", e);
} }
} }
return operationId; return activity;
} }
@Override @Override

@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
@ -216,7 +217,7 @@ public interface DeviceManagementProviderService {
void notifyOperationToDevices(Operation operation, void notifyOperationToDevices(Operation operation,
List<DeviceIdentifier> deviceIds) throws DeviceManagementException; List<DeviceIdentifier> deviceIds) throws DeviceManagementException;
int addOperation(String type, Operation operation, Activity addOperation(String type, Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException; List<DeviceIdentifier> devices) throws OperationManagementException;
List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException; List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException;

@ -33,6 +33,7 @@ import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
@ -816,7 +817,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public int addOperation(String type, Operation operation, public Activity addOperation(String type, Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException { List<DeviceIdentifier> devices) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices); return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices);
} }

Loading…
Cancel
Save