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.
- Classifications
- Add initial classifications
- List all classifications
- Add another classification
- Update a classification
- Delete a classification
- Delete all classifications
- Add classification to file
- Update classification on file
- Get classification on file
- Remove classification from file
- Add classification to folder
- Update classification on folder
- Get classification on folder
- Remove classification from folder
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);
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);
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);
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);
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);
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);
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);
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);
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);
A classification can be removed from a file by calling
deleteMetadata
.
BoxFile file = new BoxFile(api, "id");
file.deleteMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY);
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);
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);
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);
A classification can be removed from a folder by calling
deleteMetadata
.
BoxFolder folder = new BoxFolder(api, "id");
folder.deleteMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY);