fixed few issues after testing

revert-70aa11f8
ayyoob 7 years ago
parent 194e4d99b5
commit f3393080ba

@ -87,13 +87,7 @@ public class PullNotificationSubscriberImpl implements PullNotificationSubscribe
return null; return null;
} }
// Parsing json string to get compliance features. // Parsing json string to get compliance features.
JsonElement jsonElement; JsonElement jsonElement = new JsonParser().parse(compliancePayloadString);
if (compliancePayloadString instanceof String) {
jsonElement = new JsonParser().parse(compliancePayloadString);
} else {
throw new PolicyComplianceException("Invalid policy compliance payload");
}
JsonArray jsonArray = jsonElement.getAsJsonArray(); JsonArray jsonArray = jsonElement.getAsJsonArray();
Gson gson = new Gson(); Gson gson = new Gson();
ComplianceFeature complianceFeature; ComplianceFeature complianceFeature;

@ -245,7 +245,7 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
} }
if (payload.size() != attributes.size()) { if (payload.size() != attributes.size()) {
String msg = "payload does not match the stream definition"; String msg = "payload does not match with the stream definition";
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} }
eventAttributeList = new EventAttributeList(); eventAttributeList = new EventAttributeList();

@ -16,10 +16,8 @@ import org.wso2.carbon.analytics.stream.persistence.stub.EventStreamPersistenceA
import org.wso2.carbon.analytics.stream.persistence.stub.dto.AnalyticsTable; import org.wso2.carbon.analytics.stream.persistence.stub.dto.AnalyticsTable;
import org.wso2.carbon.analytics.stream.persistence.stub.dto.AnalyticsTableRecord; import org.wso2.carbon.analytics.stream.persistence.stub.dto.AnalyticsTableRecord;
import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.util.Utils;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 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.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
@ -34,7 +32,6 @@ import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceCallbackHandler; import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceCallbackHandler;
import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub; import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub;
import org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto;
import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceCallbackHandler; import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceCallbackHandler;
import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceStub; import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceStub;
import org.wso2.carbon.event.receiver.stub.types.BasicInputAdapterPropertyDto; import org.wso2.carbon.event.receiver.stub.types.BasicInputAdapterPropertyDto;
@ -42,17 +39,10 @@ import org.wso2.carbon.event.receiver.stub.types.EventReceiverConfigurationDto;
import org.wso2.carbon.event.stream.stub.EventStreamAdminServiceStub; import org.wso2.carbon.event.stream.stub.EventStreamAdminServiceStub;
import org.wso2.carbon.event.stream.stub.types.EventStreamAttributeDto; import org.wso2.carbon.event.stream.stub.types.EventStreamAttributeDto;
import org.wso2.carbon.event.stream.stub.types.EventStreamDefinitionDto; import org.wso2.carbon.event.stream.stub.types.EventStreamDefinitionDto;
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.cert.CertificateException;
import javax.validation.Valid; import javax.validation.Valid;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -64,10 +54,9 @@ import javax.ws.rs.core.Response;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
/** /**
* This is used for simple analytics purpose, to create streams and receiver dynamically and a common endpoint * This is used for device type integration with DAS, to create streams and receiver dynamically and a common endpoint
* to retrieve data. * to retrieve data.
*/ */
@Path("/events") @Path("/events")
@ -85,7 +74,12 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
private static final String MQTT_CONTENT_TRANSFORMER_TYPE = "contentTransformer"; private static final String MQTT_CONTENT_TRANSFORMER_TYPE = "contentTransformer";
private static final String MQTT_CONTENT_VALIDATOR_TYPE = "contentValidator"; private static final String MQTT_CONTENT_VALIDATOR_TYPE = "contentValidator";
private static final String MQTT_CONTENT_VALIDATOR = "default"; private static final String MQTT_CONTENT_VALIDATOR = "default";
private static final String TIMESTAMP_FIELD_NAME = "_timestamp";
/**
* Retrieves the stream definition from das for the given device type.
* @return dynamic event attribute list
*/
@GET @GET
@Path("/{type}") @Path("/{type}")
@Override @Override
@ -159,7 +153,6 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
TransportType transportType = deviceTypeEvent.getTransportType(); TransportType transportType = deviceTypeEvent.getTransportType();
EventAttributeList eventAttributes = deviceTypeEvent.getEventAttributeList(); EventAttributeList eventAttributes = deviceTypeEvent.getEventAttributeList();
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
boolean superTenantMode = false;
try { try {
if (eventAttributes == null || eventAttributes.getList() == null || eventAttributes.getList().size() == 0 || if (eventAttributes == null || eventAttributes.getList() == null || eventAttributes.getList().size() == 0 ||
deviceType == null || transportType == null || deviceType == null || transportType == null ||
@ -174,7 +167,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
publishEventReceivers(streamNameWithVersion, transportType, tenantDomain, deviceType); publishEventReceivers(streamNameWithVersion, transportType, tenantDomain, deviceType);
publishEventStore(streamName, Constants.DEFAULT_STREAM_VERSION, eventAttributes); publishEventStore(streamName, Constants.DEFAULT_STREAM_VERSION, eventAttributes);
publishWebsocketPublisherDefinition(streamNameWithVersion, deviceType); publishWebsocketPublisherDefinition(streamNameWithVersion, deviceType);
superTenantMode = true; try {
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
@ -182,7 +175,9 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
publishStreamDefinitons(streamName, Constants.DEFAULT_STREAM_VERSION, deviceType, eventAttributes); publishStreamDefinitons(streamName, Constants.DEFAULT_STREAM_VERSION, deviceType, eventAttributes);
publishEventReceivers(streamNameWithVersion, transportType, tenantDomain, deviceType); publishEventReceivers(streamNameWithVersion, transportType, tenantDomain, deviceType);
} }
DeviceMgtAPIUtils.getDynamicEventCache().remove(deviceType); } finally {
PrivilegedCarbonContext.endTenantFlow();
}
return Response.ok().build(); return Response.ok().build();
} catch (AxisFault e) { } catch (AxisFault e) {
log.error("failed to create event definitions for tenantDomain:" + tenantDomain, e); log.error("failed to create event definitions for tenantDomain:" + tenantDomain, e);
@ -203,19 +198,17 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
log.error("Failed to create event store for, tenantDomain: " + tenantDomain + " deviceType" + deviceType, log.error("Failed to create event store for, tenantDomain: " + tenantDomain + " deviceType" + deviceType,
e); e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} finally {
if (superTenantMode) {
PrivilegedCarbonContext.endTenantFlow();
}
} }
} }
/**
* Delete device type specific artifacts from DAS.
*/
@DELETE @DELETE
@Path("/{type}") @Path("/{type}")
@Override @Override
public Response deleteDeviceTypeEventDefinitions(@PathParam("type") String deviceType) { public Response deleteDeviceTypeEventDefinitions(@PathParam("type") String deviceType) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
boolean superTenantMode = false;
EventReceiverAdminServiceStub eventReceiverAdminServiceStub = null; EventReceiverAdminServiceStub eventReceiverAdminServiceStub = null;
EventPublisherAdminServiceStub eventPublisherAdminServiceStub = null; EventPublisherAdminServiceStub eventPublisherAdminServiceStub = null;
EventStreamAdminServiceStub eventStreamAdminServiceStub = null; EventStreamAdminServiceStub eventStreamAdminServiceStub = null;
@ -253,7 +246,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
eventPublisherAdminServiceStub.startundeployInactiveEventPublisherConfiguration(eventPublisherName eventPublisherAdminServiceStub.startundeployInactiveEventPublisherConfiguration(eventPublisherName
, eventPublisherAdminServiceCallbackHandler); , eventPublisherAdminServiceCallbackHandler);
superTenantMode = true; try {
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
@ -262,10 +255,16 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
tenantBasedEventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub(); tenantBasedEventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
tenantBasedEventStreamAdminServiceStub.removeEventStreamDefinition(streamName, tenantBasedEventStreamAdminServiceStub.removeEventStreamDefinition(streamName,
Constants.DEFAULT_STREAM_VERSION); Constants.DEFAULT_STREAM_VERSION);
tenantBasedEventReceiverAdminServiceStub.startundeployInactiveEventReceiverConfiguration( tenantBasedEventReceiverAdminServiceStub.startundeployInactiveEventReceiverConfiguration(
eventReceiverName, eventReceiverAdminServiceCallbackHandler); eventReceiverName, eventReceiverAdminServiceCallbackHandler);
} }
} finally {
cleanup(tenantBasedEventReceiverAdminServiceStub);
cleanup(tenantBasedEventStreamAdminServiceStub);
PrivilegedCarbonContext.endTenantFlow();
}
return Response.ok().build(); return Response.ok().build();
} catch (AxisFault e) { } catch (AxisFault e) {
log.error("failed to delete event definitions for tenantDomain:" + tenantDomain, e); log.error("failed to delete event definitions for tenantDomain:" + tenantDomain, e);
@ -283,19 +282,17 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
log.error("Failed to access device management service, tenantDomain: " + tenantDomain, e); log.error("Failed to access device management service, tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} finally { } finally {
if (superTenantMode) {
PrivilegedCarbonContext.endTenantFlow();
}
cleanup(eventStreamAdminServiceStub); cleanup(eventStreamAdminServiceStub);
cleanup(eventPublisherAdminServiceStub); cleanup(eventPublisherAdminServiceStub);
cleanup(eventReceiverAdminServiceStub); cleanup(eventReceiverAdminServiceStub);
cleanup(eventReceiverAdminServiceStub); cleanup(eventReceiverAdminServiceStub);
cleanup(eventStreamAdminServiceStub); cleanup(eventStreamAdminServiceStub);
cleanup(tenantBasedEventReceiverAdminServiceStub);
cleanup(tenantBasedEventStreamAdminServiceStub);
} }
} }
/**
* Returns device specific data for the give period of time.
*/
@GET @GET
@Path("/{type}/{deviceId}") @Path("/{type}/{deviceId}")
@Override @Override
@ -324,7 +321,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
} }
List<SortByField> sortByFields = new ArrayList<>(); List<SortByField> sortByFields = new ArrayList<>();
SortByField sortByField = new SortByField("_timestamp", SortType.DESC); SortByField sortByField = new SortByField(TIMESTAMP_FIELD_NAME, SortType.DESC);
sortByFields.add(sortByField); sortByFields.add(sortByField);
EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, offset, limit); EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, offset, limit);
return Response.status(Response.Status.OK.getStatusCode()).entity(eventRecords).build(); return Response.status(Response.Status.OK.getStatusCode()).entity(eventRecords).build();
@ -342,6 +339,9 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
} }
} }
/**
* Returns the last know data point of the device type.
*/
@GET @GET
@Path("/last-known/{type}/{deviceId}") @Path("/last-known/{type}/{deviceId}")
@Override @Override
@ -361,7 +361,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
} }
List<SortByField> sortByFields = new ArrayList<>(); List<SortByField> sortByFields = new ArrayList<>();
SortByField sortByField = new SortByField("_timestamp", SortType.DESC); SortByField sortByField = new SortByField(TIMESTAMP_FIELD_NAME, SortType.DESC);
sortByFields.add(sortByField); sortByFields.add(sortByField);
EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, 0, 1); EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, 0, 1);
return Response.status(Response.Status.OK.getStatusCode()).entity(eventRecords).build(); return Response.status(Response.Status.OK.getStatusCode()).entity(eventRecords).build();
@ -531,12 +531,6 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
return basicInputAdapterPropertyDto; return basicInputAdapterPropertyDto;
} }
private static String generateUUID() {
UUID uuid = UUID.randomUUID();
long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong();
return Long.toString(l, Character.MAX_RADIX);
}
private String getTableName(String streamName) { private String getTableName(String streamName) {
return streamName.toUpperCase().replace('.', '_'); return streamName.toUpperCase().replace('.', '_');
} }
@ -545,7 +539,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
return deviceType.replace(" ", "_").trim() + "-" + tenantDomain + "-" + transportType.toString() + "-receiver"; return deviceType.replace(" ", "_").trim() + "-" + tenantDomain + "-" + transportType.toString() + "-receiver";
} }
public static AnalyticsDataAPI getAnalyticsDataAPI() { private static AnalyticsDataAPI getAnalyticsDataAPI() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
AnalyticsDataAPI analyticsDataAPI = AnalyticsDataAPI analyticsDataAPI =
(AnalyticsDataAPI) ctx.getOSGiService(AnalyticsDataAPI.class, null); (AnalyticsDataAPI) ctx.getOSGiService(AnalyticsDataAPI.class, null);
@ -557,7 +551,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
return analyticsDataAPI; return analyticsDataAPI;
} }
protected static EventRecords getAllEventsForDevice(String tableName, String query, List<SortByField> sortByFields private static EventRecords getAllEventsForDevice(String tableName, String query, List<SortByField> sortByFields
, int offset, int limit) throws AnalyticsException { , int offset, int limit) throws AnalyticsException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
AnalyticsDataAPI analyticsDataAPI = getAnalyticsDataAPI(); AnalyticsDataAPI analyticsDataAPI = getAnalyticsDataAPI();

@ -47,6 +47,8 @@ import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService; import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException; import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
@ -62,6 +64,7 @@ import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import javax.security.auth.login.Configuration;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@ -88,6 +91,7 @@ import java.util.List;
public class DeviceManagementServiceImpl implements DeviceManagementService { public class DeviceManagementServiceImpl implements DeviceManagementService {
private static final Log log = LogFactory.getLog(DeviceManagementServiceImpl.class); private static final Log log = LogFactory.getLog(DeviceManagementServiceImpl.class);
public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
@GET @GET
@Path("/{type}/{id}/status") @Path("/{type}/{id}/status")
@ -100,7 +104,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
if (result) { if (result) {
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} else { } else {
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NO_CONTENT).build();
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while checking enrollment status of the device."; String msg = "Error occurred while checking enrollment status of the device.";
@ -558,7 +562,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
RequestValidationUtil.validateDeviceIdentifier(type, id); RequestValidationUtil.validateDeviceIdentifier(type, id);
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
Policy policy; Policy policy;
NonComplianceData complianceData = null; NonComplianceData complianceData;
DeviceCompliance deviceCompliance = new DeviceCompliance(); DeviceCompliance deviceCompliance = new DeviceCompliance();
try { try {
@ -650,8 +654,28 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
deviceIdentifier.setType(type); deviceIdentifier.setType(type);
deviceIdentifiers.add(deviceIdentifier); deviceIdentifiers.add(deviceIdentifier);
} }
Activity activity = DeviceMgtAPIUtils.getDeviceManagementService().addOperation(type Operation operation;
, operationRequest.getOperation(), deviceIdentifiers); if (operationType == Operation.Type.COMMAND) {
Operation commandOperation = operationRequest.getOperation();
operation = new CommandOperation();
operation.setType(Operation.Type.COMMAND);
operation.setCode(commandOperation.getCode());
operation.setEnabled(commandOperation.isEnabled());
operation.setStatus(commandOperation.getStatus());
} else {
Operation configOperation = operationRequest.getOperation();
operation = new ConfigOperation();
operation.setType(Operation.Type.CONFIG);
operation.setCode(configOperation.getCode());
operation.setEnabled(configOperation.isEnabled());
operation.setPayLoad(configOperation.getPayLoad());
operation.setStatus(configOperation.getStatus());
}
String date = new SimpleDateFormat(DATE_FORMAT_NOW).format(new Date());
operation.setCreatedTimeStamp(date);
Activity activity = DeviceMgtAPIUtils.getDeviceManagementService().addOperation(type, operation,
deviceIdentifiers);
return Response.status(Response.Status.CREATED).entity(activity).build(); return Response.status(Response.Status.CREATED).entity(activity).build();
} else { } else {
String message = "Only Command and Config operation is supported through this api"; String message = "Only Command and Config operation is supported through this api";

@ -74,7 +74,7 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen
DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService); DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService);
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred at server side while fetching device list."; String msg = "Error occurred at server side while adding a device type.";
log.error(msg, e); log.error(msg, e);
return Response.serverError().entity(msg).build(); return Response.serverError().entity(msg).build();
} }
@ -97,7 +97,7 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen
DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService); DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService);
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred at server side while fetching device list."; String msg = "Error occurred at server side while updating the device type.";
log.error(msg, e); log.error(msg, e);
return Response.serverError().entity(msg).build(); return Response.serverError().entity(msg).build();
} }

@ -20,6 +20,6 @@ package org.wso2.carbon.device.mgt.common.type.mgt;
public interface DeviceTypeDefinitionProvider { public interface DeviceTypeDefinitionProvider {
DeviceTypeMetaDefinition getDeviceTypeMeta(); DeviceTypeMetaDefinition getDeviceTypeMetaDefinition();
} }

@ -89,7 +89,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier( DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(
provider.getType()); provider.getType());
DeviceManagementServiceHolder existingProvider = providers.get(deviceTypeIdentifier); DeviceManagementServiceHolder existingProvider = providers.get(deviceTypeIdentifier);
deviceTypeDefinition = ((DeviceTypeDefinitionProvider) provider).getDeviceTypeMeta(); deviceTypeDefinition = ((DeviceTypeDefinitionProvider) provider).getDeviceTypeMetaDefinition();
if (existingProvider != null && !(existingProvider.getDeviceManagementService() if (existingProvider != null && !(existingProvider.getDeviceManagementService()
instanceof DeviceTypeDefinitionProvider)) { instanceof DeviceTypeDefinitionProvider)) {
throw new DeviceManagementException("Definition of device type " + provider.getType() throw new DeviceManagementException("Definition of device type " + provider.getType()
@ -207,7 +207,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
Gson gson = new Gson(); Gson gson = new Gson();
String dbStoredDefinition = gson.toJson(deviceTypeMetaDefinition); String dbStoredDefinition = gson.toJson(deviceTypeMetaDefinition);
deviceTypeMetaDefinition = ((DeviceTypeDefinitionProvider) deviceTypeMetaDefinition = ((DeviceTypeDefinitionProvider)
provider.getDeviceManagementService()).getDeviceTypeMeta(); provider.getDeviceManagementService()).getDeviceTypeMetaDefinition();
String cachedDefinition = gson.toJson(deviceTypeMetaDefinition); String cachedDefinition = gson.toJson(deviceTypeMetaDefinition);
if (!cachedDefinition.equals(dbStoredDefinition)) { if (!cachedDefinition.equals(dbStoredDefinition)) {
HTTPDeviceTypeManagerService deviceTypeManagerService = new HTTPDeviceTypeManagerService HTTPDeviceTypeManagerService deviceTypeManagerService = new HTTPDeviceTypeManagerService
@ -378,7 +378,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain()); int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain());
DeviceTypeMetaDefinition deviceTypeDefinition = null; DeviceTypeMetaDefinition deviceTypeDefinition = null;
if (provider instanceof DeviceTypeDefinitionProvider) { if (provider instanceof DeviceTypeDefinitionProvider) {
deviceTypeDefinition = ((DeviceTypeDefinitionProvider) provider).getDeviceTypeMeta(); deviceTypeDefinition = ((DeviceTypeDefinitionProvider) provider).getDeviceTypeMetaDefinition();
DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier( DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(
provider.getType(), tenantId); provider.getType(), tenantId);

@ -352,9 +352,9 @@ public interface DeviceManagementProviderService {
List<DeviceType> getDeviceTypes() throws DeviceManagementException; List<DeviceType> getDeviceTypes() throws DeviceManagementException;
/** /**
* This retrieves the device pull notification payload and passes to device type executor. * This retrieves the device pull notification payload and passes to device type pull notification subscriber.
* @throws PullNotificationExecutionFailedException * @throws PullNotificationExecutionFailedException
*/ */
void updatePullNotificationOperation(DeviceIdentifier deviceIdentifier, Operation operation) void notifyPullNotificationSubscriber(DeviceIdentifier deviceIdentifier, Operation operation)
throws PullNotificationExecutionFailedException; throws PullNotificationExecutionFailedException;
} }

@ -2211,7 +2211,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public void updatePullNotificationOperation(DeviceIdentifier deviceIdentifier, Operation operation) public void notifyPullNotificationSubscriber(DeviceIdentifier deviceIdentifier, Operation operation)
throws PullNotificationExecutionFailedException { throws PullNotificationExecutionFailedException {
DeviceManagementService dms = DeviceManagementService dms =
pluginRepository.getDeviceManagementService(deviceIdentifier.getType(), this.getTenantId()); pluginRepository.getDeviceManagementService(deviceIdentifier.getType(), this.getTenantId());

@ -42,8 +42,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* This is the template for device type manager service. This will create and instance of device management service * This inherits the capabiliy that is provided through the file based device type manager service.
* through the json payload. * This will create and instance of device management service through a json payload.
*/ */
public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService implements DeviceTypeDefinitionProvider { public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService implements DeviceTypeDefinitionProvider {
@ -174,7 +174,7 @@ public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService imple
} }
@Override @Override
public DeviceTypeMetaDefinition getDeviceTypeMeta() { public DeviceTypeMetaDefinition getDeviceTypeMetaDefinition() {
return deviceTypeMetaDefinition; return deviceTypeMetaDefinition;
} }
} }

@ -202,11 +202,12 @@ $(document).ready(function () {
$('div[name^="deviceFeature"]').each(function() { $('div[name^="deviceFeature"]').each(function() {
var featureName = $(this).find("#feature-name").val(); var featureName = $(this).find("#feature-name").val();
var featureCode = $(this).find("#feature-code").val(); var featureCode = $(this).find("#feature-code").val();
var featureDescription = $(this).find("#feature-description").val();
if (featureName && featureName.trim() != "" && featureCode && featureCode.trim() != "") { if (featureName && featureName.trim() != "" && featureCode && featureCode.trim() != "") {
var feature = {}; var feature = {};
feature.name = featureName.trim(); feature.name = featureName.trim();
feature.code = featureCode.trim(); feature.code = featureCode.trim();
feature.description = $("#feature-description").val(); feature.description = featureDescription.trim();
features.push(feature); features.push(feature);
} }
}); });

Loading…
Cancel
Save