Skip to content

Latest commit

 

History

History
258 lines (191 loc) · 11.1 KB

classifications.md

File metadata and controls

258 lines (191 loc) · 11.1 KB

Classifications

Classfications are a type of metadata that allows users and applications to define and assign a content classification to files and folders.

Classifications use the metadata APIs to add and remove classifications, and assign them to files. For more details on metadata templates please see the metadata documentation.

Add initial classifications

If an enterprise does not already have a classification defined, the first classification(s) can be added with the createMetadataTemplate method.

MetadataTemplate.Field classification = new MetadataTemplate.Field();
classification.setType("enum");
classification.setKey(Metadata.CLASSIFICATION_KEY);
classification.setDisplayName("Classification");
classification.setHidden("false");

List<String> options = new ArrayList<String>();
options.add("Top Secret");
classification.setOptions(topSecret)

List<MetadataTemplate.Field> fields = new ArrayList<MetadataTemplate.Field>();
fields.add(classification);

MetadataTemplate template = MetadataTemplate.createMetadataTemplate(api, Metadata.ENTERPRISE_METADATA_SCOPE, Metadata.CLASSIFICATION_TEMPLATE_KEY, "Classification", false, fields);

List all classifications

To retrieve a list of all the classifications in an enterprise call the getMetadataTemplate method to get the classifciations template, which will contain a list of all the classifications

MetadataTemplate template = MetadataTemplate.getMetadataTemplate(api, Metadata.CLASSIFICATION_TEMPLATE_KEY);

Add another classification

To add another classification, call the updateMetadataTemplate method with the an operation to add a new classification to the template.

List<MetadataTemplate.FieldOperation> updates = new ArrayList<MetadataTemplate.FieldOperation>();

String update = "{\n  op: \"addEnumOption\",\n  fieldKey: \"Box__Security__Classification__Key\",\n  data: {\n    key: \"Sensitive\"\n }\n}";

updates.add(new MetadataTemplate.FieldOperation(addCategoryFieldJSON));

MetadataTemplate.updateMetadataTemplate(api, Metadata.ENTERPRISE_METADATA_SCOPE, Metadata.CLASSIFICATION_TEMPLATE_KEY, updates);

Update a classification

To update an existing classification, call the updateMetadataTemplate method with the an operation to update the existing classification already present on the template.

List<MetadataTemplate.FieldOperation> updates = new ArrayList<MetadataTemplate.FieldOperation>();

String update = "{\n  op: \"editEnumOption\",\n  fieldKey: \"Box__Security__Classification__Key\",\n  enumOptionKey: \"Sensitive\",\n  data: {\n    key: \"Very Sensitive\"\n }\n}";

updates.add(new MetadataTemplate.FieldOperation(addCategoryFieldJSON));

MetadataTemplate.updateMetadataTemplate(api, Metadata.ENTERPRISE_METADATA_SCOPE, Metadata.CLASSIFICATION_TEMPLATE_KEY, updates);

Delete a classification

To remove an existing classification, call the updateMetadataTemplate method with the an operation to remove the existing classification from the metadata template.

List<MetadataTemplate.FieldOperation> updates = new ArrayList<MetadataTemplate.FieldOperation>();

String update = "{\n  op: \"removeEnumOption\",\n  fieldKey: \"Box__Security__Classification__Key\",\n  enumOptionKey: \"Sensitive\"\n}";

updates.add(new MetadataTemplate.FieldOperation(addCategoryFieldJSON));

MetadataTemplate.updateMetadataTemplate(api, Metadata.ENTERPRISE_METADATA_SCOPE, Metadata.CLASSIFICATION_TEMPLATE_KEY, updates);

Delete all classifications

To remove all classifications in an enterprise, call the deleteMetadataTemplate method with the an name of the classification metadata template.

MetadataTemplate.deleteMetadataTemplate(api, Metadata.ENTERPRISE_METADATA_SCOPE, Metadata.CLASSIFICATION_TEMPLATE_KEY);

Add classification to file

To add a classification to a file, call setMetadata(String templateKey, String templateScope, Metadata properties) with the name of the classification template, as well as the details of the classification to add to the file.

BoxFile file = new BoxFile(api, "id");
Metadata metadata = new Metadata()
metadata.add(Metadata.CLASSIFICATION_KEY, "Sensitive")
file.setMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY, Metadata.ENTERPRISE_METADATA_SCOPE, metadata);

Update classification on file

To update a classification on a file, call setMetadata(String templateKey, String templateScope, Metadata properties) with the name of the classification template, as well as the details of the classification to add to the file.

BoxFile file = new BoxFile(api, "id");
Metadata metadata = new Metadata()
metadata.add(Metadata.CLASSIFICATION_KEY, "Sensitive")
file.setMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY, Metadata.ENTERPRISE_METADATA_SCOPE, metadata);

Get classification on file

Retrieve the classification on a file by calling getMetadata(String templateKey) with the ID of the file.

BoxFile file = new BoxFile(api, "id");
Metadata metadata = file.getMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY);

Remove classification from file

A classification can be removed from a file by calling deleteMetadata.

BoxFile file = new BoxFile(api, "id");
file.deleteMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY);

Add classification to folder

To add a classification to a folder, call setMetadata(String templateKey, String templateScope, Metadata properties) with the name of the classification template, as well as the details of the classification to add to the folder.

BoxFolder folder = new BoxFolder(api, "id");
Metadata metadata = new Metadata()
metadata.add(Metadata.CLASSIFICATION_KEY, "Sensitive")
folder.setMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY, Metadata.ENTERPRISE_METADATA_SCOPE, metadata);

Update classification on folder

To update a classification on a folder, call setMetadata(String templateKey, String templateScope, Metadata properties) with the name of the classification template, as well as the details of the classification to add to the folder.

BoxFolder folder = new BoxFolder(api, "id");
Metadata metadata = new Metadata()
metadata.add(Metadata.CLASSIFICATION_KEY, "Sensitive")
folder.setMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY, Metadata.ENTERPRISE_METADATA_SCOPE, metadata);

Get classification on folder

Retrieve the classification on a folder by calling getMetadata(String templateKey) with the ID of the folder.

BoxFolder folder = new BoxFolder(api, "id");
Metadata metadata = folder.getMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY);

Remove classification from folder

A classification can be removed from a folder by calling deleteMetadata.

BoxFolder folder = new BoxFolder(api, "id");
folder.deleteMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY);