agave-metadata/metadata-api/src/main/java/org/iplantc/service/metadata/resources/MetadataCollection.java
/**
     * HTTP POST for Creating and Updating Metadata
     *
     * @param entity the posted request entity
     */
HTTP POST for Creating and Updating Metadata
@param entity the posted request entity
HTTP POST for Creating and Updating Metadata @param entity the posted request entity
@Override
    public void acceptRepresentation(Representation entity) {
        AgaveLogServiceClient.log(METADATA02.name(),
                MetaCreate.name(),
                username,
                "",
                getRequest().getClientInfo().getUpstreamAddress());
        String strMetadataItem = "";
        try {
            MetadataSearch search = new MetadataSearch(this.username);
            if (includeRecordsWithImplicitPermissions)
                search.setAccessibleOwnersImplicit();
            else
                search.setAccessibleOwnersExplicit();
            MetadataItem metadataItem;
            JsonHandler jsonHandler;
            try {
                JsonNode jsonMetadata = super.getPostedEntityAsObjectNode(false);
                jsonHandler = new JsonHandler();
                MetadataValidation validation = new MetadataValidation();
                metadataItem = validation.validateMetadataNodeFields(jsonMetadata, username);
                MetadataRequestPermissionProcessor permissionProcessor = new MetadataRequestPermissionProcessor(metadataItem);
                permissionProcessor.process(jsonHandler.getPermissions());
                metadataItem = permissionProcessor.getMetadataItem();
            } catch (ResourceException e) {
                throw e;
            } catch (Exception e) {
                throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
                        "Unable to parse form. " + e.getMessage(), e);
            }
            MetadataItem addedMetadataItem;
            try {
                metadataItem.setInternalUsername(internalUsername);
                metadataItem.setUuid(new AgaveUUID(UUIDType.METADATA).toString());
                metadataItem.setCreated(new Date());
                metadataItem.setLastUpdated(metadataItem.getCreated());
                metadataItem.setOwner(this.username);
                addedMetadataItem = search.insertMetadataItem(metadataItem);
            } catch (Exception e) {
                throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
                        "Unable to add metadata. " + e.getMessage());
            }
            MetadataRequestNotificationProcessor notificationProcessor = new MetadataRequestNotificationProcessor(
                    username,
                    addedMetadataItem.getUuid());
            notificationProcessor.process(jsonHandler.getNotifications());
            MetadataItemSerializer metadataItemSerializer = new MetadataItemSerializer();
            strMetadataItem = metadataItemSerializer.formatMetadataItemJsonResult(addedMetadataItem).toString();
            eventProcessor.processContentEvent(addedMetadataItem.getUuid(),
                    MetadataEventType.CREATED,
                    username,
                    strMetadataItem);
            getResponse().setStatus(Status.SUCCESS_CREATED);
            getResponse().setEntity(new IplantSuccessRepresentation(strMetadataItem));
        } catch (ResourceException e) {
            log.error("Failed to add metadata ", e);
            getResponse().setStatus(e.getStatus());
            getResponse().setEntity(new IplantErrorRepresentation(e.getMessage()));
        } catch (Throwable e) {
            log.error("Failed to add metadata ", e);
            getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
            getResponse().setEntity(new IplantErrorRepresentation(
                    "An error occurred while fetching the metadata item. " +
                            "If this problem persists, " +
                            "please contact the system administrators. added item: " + strMetadataItem + " -- " + e.getMessage()));
        }
    }
@ Override public void acceptRepresentation ( Representation entity ) { AgaveLogServiceClient . log ( METADATA02 . name ( ) , MetaCreate . name ( ) , username , "" , getRequest ( ) . getClientInfo ( ) . getUpstreamAddress ( ) ) ; String strMetadataItem = "" ; try { MetadataSearch search = new MetadataSearch ( this . username ) ; if ( includeRecordsWithImplicitPermissions ) search . setAccessibleOwnersImplicit ( ) ; else search . setAccessibleOwnersExplicit ( ) ; MetadataItem metadataItem ; JsonHandler jsonHandler ; try { JsonNode jsonMetadata = super . getPostedEntityAsObjectNode ( false ) ; jsonHandler = new JsonHandler ( ) ; MetadataValidation validation = new MetadataValidation ( ) ; metadataItem = validation . validateMetadataNodeFields ( jsonMetadata , username ) ; MetadataRequestPermissionProcessor permissionProcessor = new MetadataRequestPermissionProcessor ( metadataItem ) ; permissionProcessor . process ( jsonHandler . getPermissions ( ) ) ; metadataItem = permissionProcessor . getMetadataItem ( ) ; } catch ( ResourceException e ) { throw e ; } catch ( Exception e ) { throw new ResourceException ( Status . CLIENT_ERROR_BAD_REQUEST , "Unable to parse form. " + e . getMessage ( ) , e ) ; } MetadataItem addedMetadataItem ; try { metadataItem . setInternalUsername ( internalUsername ) ; metadataItem . setUuid ( new AgaveUUID ( UUIDType . METADATA ) . toString ( ) ) ; metadataItem . setCreated ( new Date ( ) ) ; metadataItem . setLastUpdated ( metadataItem . getCreated ( ) ) ; metadataItem . setOwner ( this . username ) ; addedMetadataItem = search . insertMetadataItem ( metadataItem ) ; } catch ( Exception e ) { throw new ResourceException ( Status . CLIENT_ERROR_BAD_REQUEST , "Unable to add metadata. " + e . getMessage ( ) ) ; } MetadataRequestNotificationProcessor notificationProcessor = new MetadataRequestNotificationProcessor ( username , addedMetadataItem . getUuid ( ) ) ; notificationProcessor . process ( jsonHandler . getNotifications ( ) ) ; MetadataItemSerializer metadataItemSerializer = new MetadataItemSerializer ( ) ; strMetadataItem = metadataItemSerializer . formatMetadataItemJsonResult ( addedMetadataItem ) . toString ( ) ; eventProcessor . processContentEvent ( addedMetadataItem . getUuid ( ) , MetadataEventType . CREATED , username , strMetadataItem ) ; getResponse ( ) . setStatus ( Status . SUCCESS_CREATED ) ; getResponse ( ) . setEntity ( new IplantSuccessRepresentation ( strMetadataItem ) ) ; } catch ( ResourceException e ) { log . error ( "Failed to add metadata " , e ) ; getResponse ( ) . setStatus ( e . getStatus ( ) ) ; getResponse ( ) . setEntity ( new IplantErrorRepresentation ( e . getMessage ( ) ) ) ; } catch ( Throwable e ) { log . error ( "Failed to add metadata " , e ) ; getResponse ( ) . setStatus ( Status . SERVER_ERROR_INTERNAL ) ; getResponse ( ) . setEntity ( new IplantErrorRepresentation ( "An error occurred while fetching the metadata item. " + "If this problem persists, " + "please contact the system administrators. added item: " + strMetadataItem + " -- " + e . getMessage ( ) ) ) ; } }
HTTP POST for Creating and Updating Metadata
 @param entity the posted request entity
HTTP POST for Creating and Updating Metadata @param entity the posted request entity
//validate //process permissions // ensure the uuid is not able to be set by the user // process any embedded notifications