Search in sources :

Example 6 with JsonStoreEntry

use of com.walmartlabs.concord.server.org.jsonstore.JsonStoreEntry in project concord by walmartlabs.

the class InventoryDataResource method data.

/**
 * Modifies inventory data
 *
 * @param orgName       organization's name
 * @param inventoryName inventory's name
 * @param itemPath      inventory's data path
 * @param data          inventory's data
 * @return full inventory data by path
 */
@POST
@ApiOperation("Modify inventory data")
@Path("/{orgName}/inventory/{inventoryName}/data/{itemPath:.*}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Object data(@ApiParam @PathParam("orgName") String orgName, @ApiParam @PathParam("inventoryName") String inventoryName, @ApiParam @PathParam("itemPath") String itemPath, @ApiParam Object data) {
    // we expect all top-level entries to be JSON objects
    if (!itemPath.contains("/") && !(data instanceof Map)) {
        throw new ValidationErrorsException("Top-level inventory entries must be JSON objects. Got: " + data.getClass());
    }
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    JsonStoreEntry inventory = inventoryManager.assertAccess(org.getId(), null, inventoryName, ResourceAccessLevel.WRITER, true);
    inventoryDataDao.merge(inventory.id(), itemPath, data);
    return build(inventory.id(), itemPath);
}
Also used : JsonStoreEntry(com.walmartlabs.concord.server.org.jsonstore.JsonStoreEntry) Map(java.util.Map) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

JsonStoreEntry (com.walmartlabs.concord.server.org.jsonstore.JsonStoreEntry)6 OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)5 ApiOperation (io.swagger.annotations.ApiOperation)4 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)2 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)1 Map (java.util.Map)1 UUID (java.util.UUID)1 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)1