Package com.cumulocity.rest.representation.operation

Examples of com.cumulocity.rest.representation.operation.OperationRepresentation


    public boolean contains(Object arg0) {
        //if not instance of OperationRepresentation then not contains
        if (!(arg0 instanceof OperationRepresentation)) {
            return false;
        }
        OperationRepresentation operation = (OperationRepresentation) arg0;

        //iterate over all elements in queue and compare theirs ids
        Iterator<OperationRepresentation> iterator = iterator();
        while (iterator.hasNext()) {
            OperationRepresentation current = iterator.next();
            //if element in list have the same id, we know list contains it
            if (current != null && current.getId() != null && current.getId().equals(operation.getId())) {
                return true;
            }
        }

        //if no match, then list doesn't contain that element
View Full Code Here


    DeviceControlApi deviceControlApi;

    class Executor implements Runnable {
        @Override
        public void run() {
            OperationRepresentation op = null;
            running.set(true);
            while (isActive()) {
                try {
                    op = queue.poll(queuePollTimeOut, TimeUnit.MILLISECONDS);
                    if (op != null) {
                        // TODO - refactor. This isn't pretty
                        GId gid = op.getId();
                        Boolean internalOperation = false;
                        if (gid.getValue().startsWith(OperationsQueueHandler.INTERNAL)) {
                            internalOperation = true;
                        }

                        OperationRepresentation executingOperation = null;
                        if (!internalOperation) {
                            // change status of operation in REST to "executing"
                            op.setStatus(OperationStatus.EXECUTING.toString());
                            executingOperation = deviceControlApi.update(op);
                        }

                        boolean result = operationProcessor.process(op);

                        if (!internalOperation) {
                            // change status of operation in REST according to
                            // result
                            if (result) {
                                executingOperation.setStatus(OperationStatus.SUCCESSFUL.toString());
                            } else {
                                executingOperation.setStatus(OperationStatus.FAILED.toString());
                            }
                            deviceControlApi.update(executingOperation);
                        }

                    }
View Full Code Here

    }

    @When("^I create an operation for device '([^']*)'$")
    public void iCreateAnOperationForDevice(int deviceNum) throws Exception {
        GId deviceId = getMoId(deviceNum);
        OperationRepresentation operationRepresentation = new OperationRepresentation();
        operationRepresentation.setDeviceId(deviceId);
        operationRepresentation.set("smaple_value", "sample_operation_type");
        operation1 = deviceControlResource.create(operationRepresentation);
    }
View Full Code Here

    private String getSelfUri() throws SDKException {
        return getDeviceControlRepresentation().getOperations().getSelf();
    }

    private OperationRepresentation prepareOperationForUpdate(OperationRepresentation operation) {
        OperationRepresentation toSend = new OperationRepresentation();
        toSend.setStatus(operation.getStatus());
        if (OperationStatus.FAILED.name().equals(operation.getStatus())) {
            toSend.setFailureReason(operation.getFailureReason());
        }
        toSend.setAttrs(operation.getAttrs());
        return toSend;
    }
View Full Code Here

    @Test
    public void shouldGetOperation() throws SDKException {
        // Given
        GId gid = new GId("value");
        OperationRepresentation op = new OperationRepresentation();
        when(restConnector.get(DEVICE_CONTROL_COLLECTION_URL + "/value", DeviceControlMediaType.OPERATION, OperationRepresentation.class))
                .thenReturn(op);

        // When
        OperationRepresentation retrieved = deviceControlApi.getOperation(gid);

        // Then
        assertThat(retrieved, sameInstance(op));
    }
View Full Code Here

    }

    @Test
    public void shouldCreateOperation() throws Exception {
        //Given
        OperationRepresentation operation = new OperationRepresentation();
        OperationRepresentation created = new OperationRepresentation();

        when(restConnector.post(DEVICE_CONTROL_COLLECTION_URL, DeviceControlMediaType.OPERATION, operation)).thenReturn(created);

        //when
        OperationRepresentation result = deviceControlApi.create(operation);

        // then
        assertThat(result, sameInstance(created));
    }
View Full Code Here

    }

    @Test
    public void shouldUpdateOperation() throws SDKException {
        //Given
        OperationRepresentation op = new OperationRepresentation();
        op.setStatus(OperationStatus.EXECUTING.toString());
        op.setId(new GId("myId"));
        op.setCreationTime(new Date());
        OperationRepresentation updated = new OperationRepresentation();
        when(restConnector.put(eq(DEVICE_CONTROL_COLLECTION_URL + "/myId"), eq(DeviceControlMediaType.OPERATION),
                argThat(hasOnlyUpdateFields(op)))).thenReturn(updated);

        //when
        OperationRepresentation result = deviceControlApi.update(op);

        // then
        assertThat(result, sameInstance(updated));
    }
View Full Code Here

*/
public class MeasurementRequestTask implements Runnable {
    private static final Logger LOG = LoggerFactory.getLogger(MeasurementRequestTask.class);

    public OperationRepresentation getNewMeasurementOperation() {
        OperationRepresentation newOp = Operations.createNewMeasurementOperation();
        newOp.setId(new GId(OperationsQueueHandler.INTERNAL + ":NewMeasurement-" + String.valueOf(System.currentTimeMillis())));
        return newOp;
    }
View Full Code Here

TOP

Related Classes of com.cumulocity.rest.representation.operation.OperationRepresentation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.