Search in sources :

Example 16 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.

the class Devices method getPackages.

/**
 * Returns the list of packages deployed on a device.
 *
 * @param deviceId
 *            The client ID of the Device requested.
 * @return The list of the installed packages.
 */
@GET
@Path("{deviceId}/packages")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public DevicePackages getPackages(@PathParam("deviceId") String deviceId) {
    DevicePackages result = packageFactory.newDeviceDeploymentPackages();
    try {
        KapuaId scopeId = KapuaSecurityUtils.getSession().getScopeId();
        KapuaId id = KapuaEid.parseShortId(deviceId);
        result = packageService.getInstalled(scopeId, id, null);
    } catch (Throwable t) {
        handleException(t);
    }
    return returnNotNullEntity(result);
}
Also used : KapuaId(org.eclipse.kapua.model.id.KapuaId) DevicePackages(org.eclipse.kapua.service.device.management.packages.model.DevicePackages)

Example 17 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.

the class Devices method rollbackSnapshot.

/**
 * Creates a new Device based on the information provided in DeviceCreator parameter.
 *
 * @param deviceId
 *            The id of the device
 * @param snapshotId
 *            The id of the snapshot to be rolled bac
 * @return The newly created Device object.
 */
@POST
@Path("{deviceId}/rollback/{snapshotId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response rollbackSnapshot(@PathParam("deviceId") String deviceId, @PathParam("snapshotId") String snapshotId) {
    try {
        KapuaId scopeId = KapuaSecurityUtils.getSession().getScopeId();
        KapuaId id = KapuaEid.parseShortId(deviceId);
        snapshotService.rollback(scopeId, id, snapshotId, null);
    } catch (Throwable t) {
        handleException(t);
    }
    return Response.ok().build();
}
Also used : KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 18 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.

the class Devices method deleteDevice.

/**
 * Deletes a device based on the id provided in deviceId parameter.
 *
 * @param deviceId
 *            Provides the id of the device to delete.
 */
@DELETE
@Path("{deviceId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteDevice(@PathParam("deviceId") String deviceId) {
    try {
        KapuaId deviceKapuaId = KapuaEid.parseShortId(deviceId);
        KapuaId scopeId = KapuaSecurityUtils.getSession().getScopeId();
        deviceRegistryService.delete(scopeId, deviceKapuaId);
    } catch (Throwable t) {
        handleException(t);
    }
    return Response.ok().build();
}
Also used : KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 19 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.

the class Users method getAccount.

/**
 * Returns the User specified by the "userId" path parameter.
 *
 * @param userId
 *            The id of the User requested.
 * @return The requested User object.
 */
@GET
@Path("{userId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public User getAccount(@PathParam("userId") String userId) {
    User user = null;
    try {
        KapuaId id = KapuaEid.parseShortId(userId);
        user = userService.find(KapuaSecurityUtils.getSession().getScopeId(), id);
    } catch (Throwable t) {
        handleException(t);
    }
    return returnNotNullEntity(user);
}
Also used : User(org.eclipse.kapua.service.user.User) KapuaId(org.eclipse.kapua.model.id.KapuaId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 20 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.

the class DeviceLifeCycleServiceImpl method death.

@Override
public void death(KapuaId connectionId, KapuaDisconnectMessage message) throws KapuaException {
    KapuaPayload payload = message.getPayload();
    KapuaId scopeId = message.getScopeId();
    KapuaId deviceId = message.getDeviceId();
    // 
    // Device update
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
    Device device = deviceRegistryService.find(scopeId, deviceId);
    // 
    // Event create
    DeviceEventService deviceEventService = locator.getService(DeviceEventService.class);
    DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
    DeviceEventCreator deviceEventCreator = deviceEventFactory.newCreator(scopeId, deviceId, message.getReceivedOn(), "DEATH");
    deviceEventCreator.setReceivedOn(message.getReceivedOn());
    // TODO check this change
    deviceEventCreator.setResponseCode(KapuaResponseCode.ACCEPTED);
    deviceEventCreator.setSentOn(message.getSentOn());
    KapuaPosition position = message.getPosition();
    if (position != null) {
        deviceEventCreator.setPosition(position);
    }
    deviceEventService.create(deviceEventCreator);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaPosition(org.eclipse.kapua.message.KapuaPosition) Device(org.eclipse.kapua.service.device.registry.Device) KapuaPayload(org.eclipse.kapua.message.KapuaPayload) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) DeviceEventCreator(org.eclipse.kapua.service.device.registry.event.DeviceEventCreator) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Aggregations

KapuaId (org.eclipse.kapua.model.id.KapuaId)75 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)54 Account (org.eclipse.kapua.service.account.Account)14 AccountService (org.eclipse.kapua.service.account.AccountService)14 ArrayList (java.util.ArrayList)13 Date (java.util.Date)11 Device (org.eclipse.kapua.service.device.registry.Device)11 Test (org.junit.Test)11 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)10 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)9 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)9 DeviceEventService (org.eclipse.kapua.service.device.registry.event.DeviceEventService)9 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)8 IdGeneratorService (org.eclipse.kapua.service.generator.id.IdGeneratorService)8 GwtAccount (org.eclipse.kapua.app.console.shared.model.GwtAccount)7 GwtAccountService (org.eclipse.kapua.app.console.shared.service.GwtAccountService)7 KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)7 DeviceEventCreator (org.eclipse.kapua.service.device.registry.event.DeviceEventCreator)7 User (org.eclipse.kapua.service.user.User)7 GwtDevice (org.eclipse.kapua.app.console.shared.model.GwtDevice)6