All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ironcorelabs.DocumentMetadata Maven / Gradle / Ivy

The newest version!
package com.ironcorelabs;

import java.util.Map;
import java.util.HashMap;

/**
 * Holds metadata fields as part of an encrypted document. Each encrypted
 * document will have metadata that associates it to a tenant ID, which service
 * is accessing the data, it's classification, as well as any other arbitrary
 * key/value pairs to use.
 */
public class DocumentMetadata {
    private final String tenantID;
    private final String requestingUserOrServiceID;
    private final String dataLabel;
    private final Map otherData;

    /**
     * Constructor for DocumentMetadata class which also contains other arbitrary
     * key/value pairs to send to the EncryptionService.
     *
     * @param tenantID                  Unique ID of tenant that owns this document.
     * @param requestingUserOrServiceID Unique ID of user/service that is processing
     *                                  data.
     * @param dataLabel                 Classification of data being processed.
     * @param otherData                 Additional String key/value pairs to add to
     *                                  metadata.
     * @throws IllegalArgumentException If the provided tenantID is not set
     */
    public DocumentMetadata(String tenantID, String requestingUserOrServiceID, String dataLabel,
            Map otherData) throws IllegalArgumentException {
        if (tenantID == null || tenantID.isEmpty()) {
            throw new IllegalArgumentException("Tenant ID value must be provided as part of document metadata.");
        }
        this.tenantID = tenantID;
        this.requestingUserOrServiceID = requestingUserOrServiceID;
        this.dataLabel = dataLabel;
        this.otherData = otherData == null ? new HashMap() : otherData;
    }

    /**
     * Constructor for DocumentMetadata class which has no additional metadata.
     *
     * @param tenantID                  Unique ID of tenant that owns this document.
     * @param requestingUserOrServiceID Unique ID of user/service that is processing
     *                                  data.
     * @param dataLabel                 Classification of data being processed.
     * @throws IllegalArgumentException If the provided tenantID is not set
     */
    public DocumentMetadata(String tenantID, String requestingUserOrServiceID, String dataLabel) {
        this(tenantID, requestingUserOrServiceID, dataLabel, null);
    }

    /**
     * Get the tenant ID.
     *
     * @return Metadata tenant ID
     */
    public String getTenantID() {
        return tenantID;
    }

    /**
     * Get the requesting user or service ID.
     *
     * @return Requesting user or service ID
     */
    public String getRequestingUserOrServiceID() {
        return requestingUserOrServiceID;
    }

    /**
     * Get the data classification label.
     *
     * @return Data classification label
     */
    public String getDataLabel() {
        return dataLabel;
    }

    /**
     * Get any other metadata.
     *
     * @return Any other key/value metadata
     */
    public Map getOtherData() {
        return otherData;
    }

    /**
     * Convert all of the metadata into a HashMap that can be used to POST all the
     * data to the EncryptionService. Adds all standard fields to the Map and then
     * builds up a sub object for any custom fields.
     *
     * @return Metadata converted into POST data Map
     */
    public Map getAsPostData() {
        Map postData = new HashMap<>();
        postData.put("tenantID", tenantID);
        postData.put("requestingID", requestingUserOrServiceID);
        postData.put("dataLabel", dataLabel);
        Map customFields = new HashMap<>();
        for (Map.Entry entry : otherData.entrySet()) {
            customFields.put(entry.getKey(), entry.getValue());
        }
        postData.put("customFields", customFields);
        return postData;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy