agave-metadata/metadata-core/src/main/java/org/iplantc/service/metadata/dao/MetadataSchemaPermissionDao.java
/**
     * Saves a new metadata permission. Upates existing ones.
     * @param pem the permission to delete
     * @throws org.iplantc.service.metadata.exceptions.MetadataException
     */
Saves a new metadata permission. Upates existing ones.
@param pem the permission to delete
@throws org.iplantc.service.metadata.exceptions.MetadataException
Saves a new metadata permission . Upates existing ones . @param pem the permission to delete @throws org . iplantc . service . metadata . exceptions . MetadataException
public static MetadataSchemaPermission persist(MetadataSchemaPermission pem) throws MetadataException, MetadataStoreException {
        if (pem == null)
            throw new MetadataException("Permission cannot be null");
        MongoCollection<MetadataSchemaPermission> metadataSchemaPermissionCollection;
        UpdateResult update;
        try {
            metadataSchemaPermissionCollection = getDefaultMetadataSchemaPermissionCollection();
            Bson uuidAndTenantQuery = and(eq("username", pem.getUsername()), eq("schemaId", pem.getSchemaId()));
            Document doc = new Document();
            doc.putAll(Map.of(
                    "permission", pem.getPermission().name(),
                    "lastUpdated", new Date()));
            update = metadataSchemaPermissionCollection.updateOne(uuidAndTenantQuery, new Document("$set", doc));
            if (update.getModifiedCount() == 0) {
                metadataSchemaPermissionCollection.insertOne(pem);
            }
            MetadataSchemaPermission updatedItem = getByUsernameAndSchemaId(pem.getUsername(), pem.getSchemaId());
            if (updatedItem != null) {
                return updatedItem;
            } else {
                throw new MetadataStoreException("Metadata item " + pem.getSchemaId() + " is no longer present.");
            }
        } catch (MetadataStoreException e) {
            throw e;
        } catch (Exception e) {
            String msg = "Failed to update permission: " + e.getMessage();
            throw new MetadataStoreException(msg, e);
        }
    }
public static MetadataSchemaPermission persist ( MetadataSchemaPermission pem ) throws MetadataException , MetadataStoreException { if ( pem == null ) throw new MetadataException ( "Permission cannot be null" ) ; MongoCollection < MetadataSchemaPermission > metadataSchemaPermissionCollection ; UpdateResult update ; try { metadataSchemaPermissionCollection = getDefaultMetadataSchemaPermissionCollection ( ) ; Bson uuidAndTenantQuery = and ( eq ( "username" , pem . getUsername ( ) ) , eq ( "schemaId" , pem . getSchemaId ( ) ) ) ; Document doc = new Document ( ) ; doc . putAll ( Map . of ( "permission" , pem . getPermission ( ) . name ( ) , "lastUpdated" , new Date ( ) ) ) ; update = metadataSchemaPermissionCollection . updateOne ( uuidAndTenantQuery , new Document ( "$set" , doc ) ) ; if ( update . getModifiedCount ( ) == 0 ) { metadataSchemaPermissionCollection . insertOne ( pem ) ; } MetadataSchemaPermission updatedItem = getByUsernameAndSchemaId ( pem . getUsername ( ) , pem . getSchemaId ( ) ) ; if ( updatedItem != null ) { return updatedItem ; } else { throw new MetadataStoreException ( "Metadata item " + pem . getSchemaId ( ) + " is no longer present." ) ; } } catch ( MetadataStoreException e ) { throw e ; } catch ( Exception e ) { String msg = "Failed to update permission: " + e . getMessage ( ) ; throw new MetadataStoreException ( msg , e ) ; } }
Saves a new metadata permission.
Saves a new metadata permission .
//get collection //update success. fetch the doc