public ReturnResult updateStatus()

in src/main/java/com/awsblog/queueing/sdk/QueueSdkClient.java [353:427]


	public ReturnResult updateStatus(String id, StatusEnum newStatus) {
	
		ReturnResult result = new ReturnResult(id);
		
		if (Utils.checkIfNullOrEmptyString(id)) {

			System.out.printf("ERROR: ID is not provided ... cannot retrieve the record!%n");
			result.setReturnValue(ReturnStatusEnum.FAILED_ID_NOT_FOUND);
			return result;
		}

		Map<String,AttributeValue> key = new HashMap<>();
		key.put("id", new AttributeValue().withS(id));

		DynamoDB ddb = new DynamoDB(this.dynamoDB);
		Table table = ddb.getTable(this.actualTableName);

		Shipment shipment = this.get(id);

		if (Utils.checkIfNullObject(shipment)) {

			System.out.printf("ERROR: Customer with ID [%s] cannot be found!%n", id);
			result.setReturnValue(ReturnStatusEnum.FAILED_ID_NOT_FOUND);
			return result;
		}

		StatusEnum prevStatus = shipment.getSystemInfo().getStatus();
		int version = shipment.getSystemInfo().getVersion();

		result.setStatus(newStatus);

		if (prevStatus == newStatus) {
            result.setVersion(version);
            result.setLastUpdatedTimestamp(shipment.getLastUpdatedTimestamp());
			result.setReturnValue(ReturnStatusEnum.SUCCESS);
			return result;
		}
		
		OffsetDateTime odt = OffsetDateTime.now(ZoneOffset.UTC);

        try {

            UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("id", id)
                .withUpdateExpression("ADD #sys.#v :inc SET #sys.#st = :st, #sys.last_updated_timestamp = :lut, last_updated_timestamp = :lut")
                .withNameMap(new NameMap()
                		.with("#v", "version")
                		.with("#st", "status")
                		.with("#sys", "system_info"))
                .withValueMap(
                    new ValueMap()
                    	.withInt(":inc", 1)
                    	.withInt(":v", version)
                    	.withString(":lut", odt.toString())
                    	.withString(":st", newStatus.toString()))
                .withConditionExpression("#sys.#v = :v")
                .withReturnValues(ReturnValue.ALL_NEW);

            UpdateItemOutcome outcome = table.updateItem(updateItemSpec);

            Map<String, Object> sysMap = outcome.getItem().getRawMap("system_info");
            result.setStatus(StatusEnum.valueOf((String)sysMap.get("status")));
            result.setVersion(((BigDecimal)sysMap.get("version")).intValue());
            result.setLastUpdatedTimestamp((String)sysMap.get("last_updated_timestamp"));
        }
        catch (Exception e) {
            System.err.println("updateFullyConstructedFlag() - failed to update multiple attributes in " + this.actualTableName);
            System.err.println(e.getMessage());

            result.setReturnValue(ReturnStatusEnum.FAILED_DYNAMO_ERROR);
    		return result;
        }

        result.setReturnValue(ReturnStatusEnum.SUCCESS);
		return result;
	}