_id stringlengths 2 7 | title stringlengths 3 140 | partition stringclasses 3
values | text stringlengths 73 34.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q7000 | LocationCollectionClient.uninstall | train | static boolean uninstall() {
boolean uninstalled = false;
synchronized (lock) {
if (locationCollectionClient != null) {
locationCollectionClient.locationEngineController.onDestroy();
locationCollectionClient.settingsChangeHandlerThread.quit();
locationCollectionClient.sharedPreferences.unregisterOnSharedPreferenceChangeListener(locationCollectionClient);
locationCollectionClient = null;
uninstalled = true;
}
}
return uninstalled;
} | java | {
"resource": ""
} |
q7001 | GeoTarget.getCanonAncestor | train | @Nullable public GeoTarget getCanonAncestor(GeoTarget.Type type) {
for (GeoTarget target = this; target != null; target = target.canonParent()) {
if (target.key.type == type) {
return target;
}
}
return null;
} | java | {
"resource": ""
} |
q7002 | DoubleClickCrypto.encrypt | train | public byte[] encrypt(byte[] plainData) {
checkArgument(plainData.length >= OVERHEAD_SIZE,
"Invalid plainData, %s bytes", plainData.length);
// workBytes := initVector || payload || zeros:4
byte[] workBytes = plainData.clone();
ByteBuffer workBuffer = ByteBuffer.wrap(workBytes);
boolean success = false;
try {
// workBytes := initVector || payload || I(signature)
int signature = hmacSignature(workBytes);
workBuffer.putInt(workBytes.length - SIGNATURE_SIZE, signature);
// workBytes := initVector || E(payload) || I(signature)
xorPayloadToHmacPad(workBytes);
if (logger.isDebugEnabled()) {
logger.debug(dump("Encrypted", plainData, workBytes));
}
success = true;
return workBytes;
} finally {
if (!success && logger.isDebugEnabled()) {
logger.debug(dump("Encrypted (failed)", plainData, workBytes));
}
}
} | java | {
"resource": ""
} |
q7003 | BoxConfig.readFrom | train | public static BoxConfig readFrom(Reader reader) throws IOException {
JsonObject config = JsonObject.readFrom(reader);
JsonObject settings = (JsonObject) config.get("boxAppSettings");
String clientId = settings.get("clientID").asString();
String clientSecret = settings.get("clientSecret").asString();
JsonObject appAuth = (JsonObject) settings.get("appAuth");
String publicKeyId = appAuth.get("publicKeyID").asString();
String privateKey = appAuth.get("privateKey").asString();
String passphrase = appAuth.get("passphrase").asString();
String enterpriseId = config.get("enterpriseID").asString();
return new BoxConfig(clientId, clientSecret, enterpriseId, publicKeyId, privateKey, passphrase);
} | java | {
"resource": ""
} |
q7004 | BoxCollaborationWhitelist.create | train | public static BoxCollaborationWhitelist.Info create(final BoxAPIConnection api, String domain,
WhitelistDirection direction) {
URL url = COLLABORATION_WHITELIST_ENTRIES_URL_TEMPLATE.build(api.getBaseURL());
BoxJSONRequest request = new BoxJSONRequest(api, url, HttpMethod.POST);
JsonObject requestJSON = new JsonObject()
.add("domain", domain)
.add("direction", direction.toString());
request.setBody(requestJSON.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
BoxCollaborationWhitelist domainWhitelist =
new BoxCollaborationWhitelist(api, responseJSON.get("id").asString());
return domainWhitelist.new Info(responseJSON);
} | java | {
"resource": ""
} |
q7005 | BoxCollaborationWhitelist.delete | train | public void delete() {
BoxAPIConnection api = this.getAPI();
URL url = COLLABORATION_WHITELIST_ENTRY_URL_TEMPLATE.build(api.getBaseURL(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(api, url, HttpMethod.DELETE);
BoxAPIResponse response = request.send();
response.disconnect();
} | java | {
"resource": ""
} |
q7006 | CollectionUtils.map | train | public static <T_Result, T_Source> List<T_Result> map(Collection<T_Source> source,
Mapper<T_Result, T_Source> mapper) {
List<T_Result> result = new LinkedList<T_Result>();
for (T_Source element : source) {
result.add(mapper.map(element));
}
return result;
} | java | {
"resource": ""
} |
q7007 | BoxFolder.createFolder | train | public BoxFolder.Info createFolder(String name) {
JsonObject parent = new JsonObject();
parent.add("id", this.getID());
JsonObject newFolder = new JsonObject();
newFolder.add("name", name);
newFolder.add("parent", parent);
BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), CREATE_FOLDER_URL.build(this.getAPI().getBaseURL()),
"POST");
request.setBody(newFolder.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
BoxFolder createdFolder = new BoxFolder(this.getAPI(), responseJSON.get("id").asString());
return createdFolder.new Info(responseJSON);
} | java | {
"resource": ""
} |
q7008 | BoxFolder.rename | train | public void rename(String newName) {
URL url = FOLDER_INFO_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "PUT");
JsonObject updateInfo = new JsonObject();
updateInfo.add("name", newName);
request.setBody(updateInfo.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
response.getJSON();
} | java | {
"resource": ""
} |
q7009 | BoxFolder.uploadFile | train | public BoxFile.Info uploadFile(InputStream fileContent, String name, long fileSize, ProgressListener listener) {
FileUploadParams uploadInfo = new FileUploadParams()
.setContent(fileContent)
.setName(name)
.setSize(fileSize)
.setProgressListener(listener);
return this.uploadFile(uploadInfo);
} | java | {
"resource": ""
} |
q7010 | BoxFolder.uploadFile | train | public BoxFile.Info uploadFile(FileUploadParams uploadParams) {
URL uploadURL = UPLOAD_FILE_URL.build(this.getAPI().getBaseUploadURL());
BoxMultipartRequest request = new BoxMultipartRequest(getAPI(), uploadURL);
JsonObject fieldJSON = new JsonObject();
JsonObject parentIdJSON = new JsonObject();
parentIdJSON.add("id", getID());
fieldJSON.add("name", uploadParams.getName());
fieldJSON.add("parent", parentIdJSON);
if (uploadParams.getCreated() != null) {
fieldJSON.add("content_created_at", BoxDateFormat.format(uploadParams.getCreated()));
}
if (uploadParams.getModified() != null) {
fieldJSON.add("content_modified_at", BoxDateFormat.format(uploadParams.getModified()));
}
if (uploadParams.getSHA1() != null && !uploadParams.getSHA1().isEmpty()) {
request.setContentSHA1(uploadParams.getSHA1());
}
if (uploadParams.getDescription() != null) {
fieldJSON.add("description", uploadParams.getDescription());
}
request.putField("attributes", fieldJSON.toString());
if (uploadParams.getSize() > 0) {
request.setFile(uploadParams.getContent(), uploadParams.getName(), uploadParams.getSize());
} else if (uploadParams.getContent() != null) {
request.setFile(uploadParams.getContent(), uploadParams.getName());
} else {
request.setUploadFileCallback(uploadParams.getUploadFileCallback(), uploadParams.getName());
}
BoxJSONResponse response;
if (uploadParams.getProgressListener() == null) {
response = (BoxJSONResponse) request.send();
} else {
response = (BoxJSONResponse) request.send(uploadParams.getProgressListener());
}
JsonObject collection = JsonObject.readFrom(response.getJSON());
JsonArray entries = collection.get("entries").asArray();
JsonObject fileInfoJSON = entries.get(0).asObject();
String uploadedFileID = fileInfoJSON.get("id").asString();
BoxFile uploadedFile = new BoxFile(getAPI(), uploadedFileID);
return uploadedFile.new Info(fileInfoJSON);
} | java | {
"resource": ""
} |
q7011 | BoxFolder.getChildren | train | public Iterable<BoxItem.Info> getChildren(final String... fields) {
return new Iterable<BoxItem.Info>() {
@Override
public Iterator<BoxItem.Info> iterator() {
String queryString = new QueryStringBuilder().appendParam("fields", fields).toString();
URL url = GET_ITEMS_URL.buildWithQuery(getAPI().getBaseURL(), queryString, getID());
return new BoxItemIterator(getAPI(), url);
}
};
} | java | {
"resource": ""
} |
q7012 | BoxFolder.getChildren | train | public Iterable<BoxItem.Info> getChildren(String sort, SortDirection direction, final String... fields) {
QueryStringBuilder builder = new QueryStringBuilder()
.appendParam("sort", sort)
.appendParam("direction", direction.toString());
if (fields.length > 0) {
builder.appendParam("fields", fields).toString();
}
final String query = builder.toString();
return new Iterable<BoxItem.Info>() {
@Override
public Iterator<BoxItem.Info> iterator() {
URL url = GET_ITEMS_URL.buildWithQuery(getAPI().getBaseURL(), query, getID());
return new BoxItemIterator(getAPI(), url);
}
};
} | java | {
"resource": ""
} |
q7013 | BoxFolder.getChildrenRange | train | public PartialCollection<BoxItem.Info> getChildrenRange(long offset, long limit, String... fields) {
QueryStringBuilder builder = new QueryStringBuilder()
.appendParam("limit", limit)
.appendParam("offset", offset);
if (fields.length > 0) {
builder.appendParam("fields", fields).toString();
}
URL url = GET_ITEMS_URL.buildWithQuery(getAPI().getBaseURL(), builder.toString(), getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
String totalCountString = responseJSON.get("total_count").toString();
long fullSize = Double.valueOf(totalCountString).longValue();
PartialCollection<BoxItem.Info> children = new PartialCollection<BoxItem.Info>(offset, limit, fullSize);
JsonArray jsonArray = responseJSON.get("entries").asArray();
for (JsonValue value : jsonArray) {
JsonObject jsonObject = value.asObject();
BoxItem.Info parsedItemInfo = (BoxItem.Info) BoxResource.parseInfo(this.getAPI(), jsonObject);
if (parsedItemInfo != null) {
children.add(parsedItemInfo);
}
}
return children;
} | java | {
"resource": ""
} |
q7014 | BoxFolder.iterator | train | @Override
public Iterator<BoxItem.Info> iterator() {
URL url = GET_ITEMS_URL.build(this.getAPI().getBaseURL(), BoxFolder.this.getID());
return new BoxItemIterator(BoxFolder.this.getAPI(), url);
} | java | {
"resource": ""
} |
q7015 | BoxFolder.createMetadata | train | public Metadata createMetadata(String templateName, Metadata metadata) {
String scope = Metadata.scopeBasedOnType(templateName);
return this.createMetadata(templateName, scope, metadata);
} | java | {
"resource": ""
} |
q7016 | BoxFolder.createMetadata | train | public Metadata createMetadata(String templateName, String scope, Metadata metadata) {
URL url = METADATA_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID(), scope, templateName);
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "POST");
request.addHeader("Content-Type", "application/json");
request.setBody(metadata.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
return new Metadata(JsonObject.readFrom(response.getJSON()));
} | java | {
"resource": ""
} |
q7017 | BoxFolder.setMetadata | train | public Metadata setMetadata(String templateName, String scope, Metadata metadata) {
Metadata metadataValue = null;
try {
metadataValue = this.createMetadata(templateName, scope, metadata);
} catch (BoxAPIException e) {
if (e.getResponseCode() == 409) {
Metadata metadataToUpdate = new Metadata(scope, templateName);
for (JsonValue value : metadata.getOperations()) {
if (value.asObject().get("value").isNumber()) {
metadataToUpdate.add(value.asObject().get("path").asString(),
value.asObject().get("value").asFloat());
} else if (value.asObject().get("value").isString()) {
metadataToUpdate.add(value.asObject().get("path").asString(),
value.asObject().get("value").asString());
} else if (value.asObject().get("value").isArray()) {
ArrayList<String> list = new ArrayList<String>();
for (JsonValue jsonValue : value.asObject().get("value").asArray()) {
list.add(jsonValue.asString());
}
metadataToUpdate.add(value.asObject().get("path").asString(), list);
}
}
metadataValue = this.updateMetadata(metadataToUpdate);
}
}
return metadataValue;
} | java | {
"resource": ""
} |
q7018 | BoxFolder.getMetadata | train | public Metadata getMetadata(String templateName) {
String scope = Metadata.scopeBasedOnType(templateName);
return this.getMetadata(templateName, scope);
} | java | {
"resource": ""
} |
q7019 | BoxFolder.deleteMetadata | train | public void deleteMetadata(String templateName) {
String scope = Metadata.scopeBasedOnType(templateName);
this.deleteMetadata(templateName, scope);
} | java | {
"resource": ""
} |
q7020 | BoxFolder.deleteMetadata | train | public void deleteMetadata(String templateName, String scope) {
URL url = METADATA_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID(), scope, templateName);
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "DELETE");
BoxAPIResponse response = request.send();
response.disconnect();
} | java | {
"resource": ""
} |
q7021 | BoxFolder.addClassification | train | public String addClassification(String classificationType) {
Metadata metadata = new Metadata().add(Metadata.CLASSIFICATION_KEY, classificationType);
Metadata classification = this.createMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY,
"enterprise", metadata);
return classification.getString(Metadata.CLASSIFICATION_KEY);
} | java | {
"resource": ""
} |
q7022 | BoxFolder.uploadLargeFile | train | public BoxFile.Info uploadLargeFile(InputStream inputStream, String fileName, long fileSize)
throws InterruptedException, IOException {
URL url = UPLOAD_SESSION_URL_TEMPLATE.build(this.getAPI().getBaseUploadURL());
return new LargeFileUpload().
upload(this.getAPI(), this.getID(), inputStream, url, fileName, fileSize);
} | java | {
"resource": ""
} |
q7023 | BoxFolder.getMetadataCascadePolicies | train | public Iterable<BoxMetadataCascadePolicy.Info> getMetadataCascadePolicies(String... fields) {
Iterable<BoxMetadataCascadePolicy.Info> cascadePoliciesInfo =
BoxMetadataCascadePolicy.getAll(this.getAPI(), this.getID(), fields);
return cascadePoliciesInfo;
} | java | {
"resource": ""
} |
q7024 | BoxRetentionPolicy.createIndefinitePolicy | train | public static BoxRetentionPolicy.Info createIndefinitePolicy(BoxAPIConnection api, String name) {
return createRetentionPolicy(api, name, TYPE_INDEFINITE, 0, ACTION_REMOVE_RETENTION);
} | java | {
"resource": ""
} |
q7025 | BoxRetentionPolicy.createFinitePolicy | train | public static BoxRetentionPolicy.Info createFinitePolicy(BoxAPIConnection api, String name, int length,
String action, RetentionPolicyParams optionalParams) {
return createRetentionPolicy(api, name, TYPE_FINITE, length, action, optionalParams);
} | java | {
"resource": ""
} |
q7026 | BoxRetentionPolicy.createRetentionPolicy | train | private static BoxRetentionPolicy.Info createRetentionPolicy(BoxAPIConnection api, String name, String type,
int length, String action) {
return createRetentionPolicy(api, name, type, length, action, null);
} | java | {
"resource": ""
} |
q7027 | BoxRetentionPolicy.createRetentionPolicy | train | private static BoxRetentionPolicy.Info createRetentionPolicy(BoxAPIConnection api, String name, String type,
int length, String action,
RetentionPolicyParams optionalParams) {
URL url = RETENTION_POLICIES_URL_TEMPLATE.build(api.getBaseURL());
BoxJSONRequest request = new BoxJSONRequest(api, url, "POST");
JsonObject requestJSON = new JsonObject()
.add("policy_name", name)
.add("policy_type", type)
.add("disposition_action", action);
if (!type.equals(TYPE_INDEFINITE)) {
requestJSON.add("retention_length", length);
}
if (optionalParams != null) {
requestJSON.add("can_owner_extend_retention", optionalParams.getCanOwnerExtendRetention());
requestJSON.add("are_owners_notified", optionalParams.getAreOwnersNotified());
List<BoxUser.Info> customNotificationRecipients = optionalParams.getCustomNotificationRecipients();
if (customNotificationRecipients.size() > 0) {
JsonArray users = new JsonArray();
for (BoxUser.Info user : customNotificationRecipients) {
JsonObject userJSON = new JsonObject()
.add("type", "user")
.add("id", user.getID());
users.add(userJSON);
}
requestJSON.add("custom_notification_recipients", users);
}
}
request.setBody(requestJSON.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
BoxRetentionPolicy createdPolicy = new BoxRetentionPolicy(api, responseJSON.get("id").asString());
return createdPolicy.new Info(responseJSON);
} | java | {
"resource": ""
} |
q7028 | BoxRetentionPolicy.getFolderAssignments | train | public Iterable<BoxRetentionPolicyAssignment.Info> getFolderAssignments(int limit, String ... fields) {
return this.getAssignments(BoxRetentionPolicyAssignment.TYPE_FOLDER, limit, fields);
} | java | {
"resource": ""
} |
q7029 | BoxRetentionPolicy.getEnterpriseAssignments | train | public Iterable<BoxRetentionPolicyAssignment.Info> getEnterpriseAssignments(int limit, String ... fields) {
return this.getAssignments(BoxRetentionPolicyAssignment.TYPE_ENTERPRISE, limit, fields);
} | java | {
"resource": ""
} |
q7030 | BoxRetentionPolicy.getAllAssignments | train | public Iterable<BoxRetentionPolicyAssignment.Info> getAllAssignments(int limit, String ... fields) {
return this.getAssignments(null, limit, fields);
} | java | {
"resource": ""
} |
q7031 | BoxRetentionPolicy.getAssignments | train | private Iterable<BoxRetentionPolicyAssignment.Info> getAssignments(String type, int limit, String ... fields) {
QueryStringBuilder queryString = new QueryStringBuilder();
if (type != null) {
queryString.appendParam("type", type);
}
if (fields.length > 0) {
queryString.appendParam("fields", fields);
}
URL url = ASSIGNMENTS_URL_TEMPLATE.buildWithQuery(getAPI().getBaseURL(), queryString.toString(), getID());
return new BoxResourceIterable<BoxRetentionPolicyAssignment.Info>(getAPI(), url, limit) {
@Override
protected BoxRetentionPolicyAssignment.Info factory(JsonObject jsonObject) {
BoxRetentionPolicyAssignment assignment
= new BoxRetentionPolicyAssignment(getAPI(), jsonObject.get("id").asString());
return assignment.new Info(jsonObject);
}
};
} | java | {
"resource": ""
} |
q7032 | BoxRetentionPolicy.assignTo | train | public BoxRetentionPolicyAssignment.Info assignTo(BoxFolder folder) {
return BoxRetentionPolicyAssignment.createAssignmentToFolder(this.getAPI(), this.getID(), folder.getID());
} | java | {
"resource": ""
} |
q7033 | BoxRetentionPolicy.assignToMetadataTemplate | train | public BoxRetentionPolicyAssignment.Info assignToMetadataTemplate(String templateID,
MetadataFieldFilter... fieldFilters) {
return BoxRetentionPolicyAssignment.createAssignmentToMetadata(this.getAPI(), this.getID(), templateID,
fieldFilters);
} | java | {
"resource": ""
} |
q7034 | BoxRetentionPolicy.getAll | train | public static Iterable<BoxRetentionPolicy.Info> getAll(final BoxAPIConnection api, String ... fields) {
return getAll(null, null, null, DEFAULT_LIMIT, api, fields);
} | java | {
"resource": ""
} |
q7035 | BoxRetentionPolicy.getAll | train | public static Iterable<BoxRetentionPolicy.Info> getAll(
String name, String type, String userID, int limit, final BoxAPIConnection api, String ... fields) {
QueryStringBuilder queryString = new QueryStringBuilder();
if (name != null) {
queryString.appendParam("policy_name", name);
}
if (type != null) {
queryString.appendParam("policy_type", type);
}
if (userID != null) {
queryString.appendParam("created_by_user_id", userID);
}
if (fields.length > 0) {
queryString.appendParam("fields", fields);
}
URL url = RETENTION_POLICIES_URL_TEMPLATE.buildWithQuery(api.getBaseURL(), queryString.toString());
return new BoxResourceIterable<BoxRetentionPolicy.Info>(api, url, limit) {
@Override
protected BoxRetentionPolicy.Info factory(JsonObject jsonObject) {
BoxRetentionPolicy policy = new BoxRetentionPolicy(api, jsonObject.get("id").asString());
return policy.new Info(jsonObject);
}
};
} | java | {
"resource": ""
} |
q7036 | EventStream.start | train | public void start() {
if (this.started) {
throw new IllegalStateException("Cannot start the EventStream because it isn't stopped.");
}
final long initialPosition;
if (this.startingPosition == STREAM_POSITION_NOW) {
BoxAPIRequest request = new BoxAPIRequest(this.api, EVENT_URL.build(this.api.getBaseURL(), "now"), "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject jsonObject = JsonObject.readFrom(response.getJSON());
initialPosition = jsonObject.get("next_stream_position").asLong();
} else {
assert this.startingPosition >= 0 : "Starting position must be non-negative";
initialPosition = this.startingPosition;
}
this.poller = new Poller(initialPosition);
this.pollerThread = new Thread(this.poller);
this.pollerThread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
EventStream.this.notifyException(e);
}
});
this.pollerThread.start();
this.started = true;
} | java | {
"resource": ""
} |
q7037 | EventStream.isDuplicate | train | protected boolean isDuplicate(String eventID) {
if (this.receivedEvents == null) {
this.receivedEvents = new LRUCache<String>();
}
return !this.receivedEvents.add(eventID);
} | java | {
"resource": ""
} |
q7038 | BoxRetentionPolicyAssignment.createAssignmentToEnterprise | train | public static BoxRetentionPolicyAssignment.Info createAssignmentToEnterprise(BoxAPIConnection api,
String policyID) {
return createAssignment(api, policyID, new JsonObject().add("type", TYPE_ENTERPRISE), null);
} | java | {
"resource": ""
} |
q7039 | BoxRetentionPolicyAssignment.createAssignmentToFolder | train | public static BoxRetentionPolicyAssignment.Info createAssignmentToFolder(BoxAPIConnection api, String policyID,
String folderID) {
return createAssignment(api, policyID, new JsonObject().add("type", TYPE_FOLDER).add("id", folderID), null);
} | java | {
"resource": ""
} |
q7040 | BoxRetentionPolicyAssignment.createAssignmentToMetadata | train | public static BoxRetentionPolicyAssignment.Info createAssignmentToMetadata(BoxAPIConnection api,
String policyID,
String templateID,
MetadataFieldFilter... filter) {
JsonObject assignTo = new JsonObject().add("type", TYPE_METADATA).add("id", templateID);
JsonArray filters = null;
if (filter.length > 0) {
filters = new JsonArray();
for (MetadataFieldFilter f : filter) {
filters.add(f.getJsonObject());
}
}
return createAssignment(api, policyID, assignTo, filters);
} | java | {
"resource": ""
} |
q7041 | BoxRetentionPolicyAssignment.createAssignment | train | private static BoxRetentionPolicyAssignment.Info createAssignment(BoxAPIConnection api, String policyID,
JsonObject assignTo, JsonArray filter) {
URL url = ASSIGNMENTS_URL_TEMPLATE.build(api.getBaseURL());
BoxJSONRequest request = new BoxJSONRequest(api, url, "POST");
JsonObject requestJSON = new JsonObject()
.add("policy_id", policyID)
.add("assign_to", assignTo);
if (filter != null) {
requestJSON.add("filter_fields", filter);
}
request.setBody(requestJSON.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
BoxRetentionPolicyAssignment createdAssignment
= new BoxRetentionPolicyAssignment(api, responseJSON.get("id").asString());
return createdAssignment.new Info(responseJSON);
} | java | {
"resource": ""
} |
q7042 | Metadata.getAllMetadata | train | public static Iterable<Metadata> getAllMetadata(BoxItem item, String ... fields) {
QueryStringBuilder builder = new QueryStringBuilder();
if (fields.length > 0) {
builder.appendParam("fields", fields);
}
return new BoxResourceIterable<Metadata>(
item.getAPI(),
GET_ALL_METADATA_URL_TEMPLATE.buildWithQuery(item.getItemURL().toString(), builder.toString()),
DEFAULT_LIMIT) {
@Override
protected Metadata factory(JsonObject jsonObject) {
return new Metadata(jsonObject);
}
};
} | java | {
"resource": ""
} |
q7043 | Metadata.add | train | public Metadata add(String path, String value) {
this.values.add(this.pathToProperty(path), value);
this.addOp("add", path, value);
return this;
} | java | {
"resource": ""
} |
q7044 | Metadata.add | train | public Metadata add(String path, List<String> values) {
JsonArray arr = new JsonArray();
for (String value : values) {
arr.add(value);
}
this.values.add(this.pathToProperty(path), arr);
this.addOp("add", path, arr);
return this;
} | java | {
"resource": ""
} |
q7045 | Metadata.replace | train | public Metadata replace(String path, String value) {
this.values.set(this.pathToProperty(path), value);
this.addOp("replace", path, value);
return this;
} | java | {
"resource": ""
} |
q7046 | Metadata.remove | train | public Metadata remove(String path) {
this.values.remove(this.pathToProperty(path));
this.addOp("remove", path, (String) null);
return this;
} | java | {
"resource": ""
} |
q7047 | Metadata.get | train | @Deprecated
public String get(String path) {
final JsonValue value = this.values.get(this.pathToProperty(path));
if (value == null) {
return null;
}
if (!value.isString()) {
return value.toString();
}
return value.asString();
} | java | {
"resource": ""
} |
q7048 | Metadata.getDate | train | public Date getDate(String path) throws ParseException {
return BoxDateFormat.parse(this.getValue(path).asString());
} | java | {
"resource": ""
} |
q7049 | Metadata.getMultiSelect | train | public List<String> getMultiSelect(String path) {
List<String> values = new ArrayList<String>();
for (JsonValue val : this.getValue(path).asArray()) {
values.add(val.asString());
}
return values;
} | java | {
"resource": ""
} |
q7050 | Metadata.getPropertyPaths | train | public List<String> getPropertyPaths() {
List<String> result = new ArrayList<String>();
for (String property : this.values.names()) {
if (!property.startsWith("$")) {
result.add(this.propertyToPath(property));
}
}
return result;
} | java | {
"resource": ""
} |
q7051 | Metadata.pathToProperty | train | private String pathToProperty(String path) {
if (path == null || !path.startsWith("/")) {
throw new IllegalArgumentException("Path must be prefixed with a \"/\".");
}
return path.substring(1);
} | java | {
"resource": ""
} |
q7052 | Metadata.addOp | train | private void addOp(String op, String path, String value) {
if (this.operations == null) {
this.operations = new JsonArray();
}
this.operations.add(new JsonObject()
.add("op", op)
.add("path", path)
.add("value", value));
} | java | {
"resource": ""
} |
q7053 | BoxCollaboration.create | train | protected static BoxCollaboration.Info create(BoxAPIConnection api, JsonObject accessibleBy, JsonObject item,
BoxCollaboration.Role role, Boolean notify, Boolean canViewPath) {
String queryString = "";
if (notify != null) {
queryString = new QueryStringBuilder().appendParam("notify", notify.toString()).toString();
}
URL url;
if (queryString.length() > 0) {
url = COLLABORATIONS_URL_TEMPLATE.buildWithQuery(api.getBaseURL(), queryString);
} else {
url = COLLABORATIONS_URL_TEMPLATE.build(api.getBaseURL());
}
JsonObject requestJSON = new JsonObject();
requestJSON.add("item", item);
requestJSON.add("accessible_by", accessibleBy);
requestJSON.add("role", role.toJSONString());
if (canViewPath != null) {
requestJSON.add("can_view_path", canViewPath.booleanValue());
}
BoxJSONRequest request = new BoxJSONRequest(api, url, "POST");
request.setBody(requestJSON.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
BoxCollaboration newCollaboration = new BoxCollaboration(api, responseJSON.get("id").asString());
return newCollaboration.new Info(responseJSON);
} | java | {
"resource": ""
} |
q7054 | BoxCollaboration.getPendingCollaborations | train | public static Collection<Info> getPendingCollaborations(BoxAPIConnection api) {
URL url = PENDING_COLLABORATIONS_URL.build(api.getBaseURL());
BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
int entriesCount = responseJSON.get("total_count").asInt();
Collection<BoxCollaboration.Info> collaborations = new ArrayList<BoxCollaboration.Info>(entriesCount);
JsonArray entries = responseJSON.get("entries").asArray();
for (JsonValue entry : entries) {
JsonObject entryObject = entry.asObject();
BoxCollaboration collaboration = new BoxCollaboration(api, entryObject.get("id").asString());
BoxCollaboration.Info info = collaboration.new Info(entryObject);
collaborations.add(info);
}
return collaborations;
} | java | {
"resource": ""
} |
q7055 | BoxCollaboration.getInfo | train | public Info getInfo() {
BoxAPIConnection api = this.getAPI();
URL url = COLLABORATION_URL_TEMPLATE.build(api.getBaseURL(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject jsonObject = JsonObject.readFrom(response.getJSON());
return new Info(jsonObject);
} | java | {
"resource": ""
} |
q7056 | BoxCollaboration.updateInfo | train | public void updateInfo(Info info) {
BoxAPIConnection api = this.getAPI();
URL url = COLLABORATION_URL_TEMPLATE.build(api.getBaseURL(), this.getID());
BoxJSONRequest request = new BoxJSONRequest(api, url, "PUT");
request.setBody(info.getPendingChanges());
BoxAPIResponse boxAPIResponse = request.send();
if (boxAPIResponse instanceof BoxJSONResponse) {
BoxJSONResponse response = (BoxJSONResponse) boxAPIResponse;
JsonObject jsonObject = JsonObject.readFrom(response.getJSON());
info.update(jsonObject);
}
} | java | {
"resource": ""
} |
q7057 | BoxCollaboration.delete | train | public void delete() {
BoxAPIConnection api = this.getAPI();
URL url = COLLABORATION_URL_TEMPLATE.build(api.getBaseURL(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(api, url, "DELETE");
BoxAPIResponse response = request.send();
response.disconnect();
} | java | {
"resource": ""
} |
q7058 | BoxLegalHoldAssignment.create | train | public static BoxLegalHoldAssignment.Info create(BoxAPIConnection api,
String policyID, String resourceType, String resourceID) {
URL url = ASSIGNMENTS_URL_TEMPLATE.build(api.getBaseURL());
BoxJSONRequest request = new BoxJSONRequest(api, url, "POST");
JsonObject requestJSON = new JsonObject()
.add("policy_id", policyID)
.add("assign_to", new JsonObject()
.add("type", resourceType)
.add("id", resourceID));
request.setBody(requestJSON.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
BoxLegalHoldAssignment createdAssignment = new BoxLegalHoldAssignment(api, responseJSON.get("id").asString());
return createdAssignment.new Info(responseJSON);
} | java | {
"resource": ""
} |
q7059 | RetentionPolicyParams.addCustomNotificationRecipient | train | public void addCustomNotificationRecipient(String userID) {
BoxUser user = new BoxUser(null, userID);
this.customNotificationRecipients.add(user.new Info());
} | java | {
"resource": ""
} |
q7060 | BoxCollection.getAllCollections | train | public static Iterable<BoxCollection.Info> getAllCollections(final BoxAPIConnection api) {
return new Iterable<BoxCollection.Info>() {
public Iterator<BoxCollection.Info> iterator() {
URL url = GET_COLLECTIONS_URL_TEMPLATE.build(api.getBaseURL());
return new BoxCollectionIterator(api, url);
}
};
} | java | {
"resource": ""
} |
q7061 | BoxCollection.getItemsRange | train | public PartialCollection<BoxItem.Info> getItemsRange(long offset, long limit, String... fields) {
QueryStringBuilder builder = new QueryStringBuilder()
.appendParam("offset", offset)
.appendParam("limit", limit);
if (fields.length > 0) {
builder.appendParam("fields", fields).toString();
}
URL url = GET_COLLECTION_ITEMS_URL.buildWithQuery(getAPI().getBaseURL(), builder.toString(), getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
String totalCountString = responseJSON.get("total_count").toString();
long fullSize = Double.valueOf(totalCountString).longValue();
PartialCollection<BoxItem.Info> items = new PartialCollection<BoxItem.Info>(offset, limit, fullSize);
JsonArray entries = responseJSON.get("entries").asArray();
for (JsonValue entry : entries) {
BoxItem.Info entryInfo = (BoxItem.Info) BoxResource.parseInfo(this.getAPI(), entry.asObject());
if (entryInfo != null) {
items.add(entryInfo);
}
}
return items;
} | java | {
"resource": ""
} |
q7062 | BoxCollection.iterator | train | @Override
public Iterator<BoxItem.Info> iterator() {
URL url = GET_COLLECTION_ITEMS_URL.build(this.getAPI().getBaseURL(), BoxCollection.this.getID());
return new BoxItemIterator(BoxCollection.this.getAPI(), url);
} | java | {
"resource": ""
} |
q7063 | BoxCollaborationWhitelistExemptTarget.create | train | public static BoxCollaborationWhitelistExemptTarget.Info create(final BoxAPIConnection api, String userID) {
URL url = COLLABORATION_WHITELIST_EXEMPT_TARGET_ENTRIES_URL_TEMPLATE.build(api.getBaseURL());
BoxJSONRequest request = new BoxJSONRequest(api, url, HttpMethod.POST);
JsonObject requestJSON = new JsonObject()
.add("user", new JsonObject()
.add("type", "user")
.add("id", userID));
request.setBody(requestJSON.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
BoxCollaborationWhitelistExemptTarget userWhitelist = new BoxCollaborationWhitelistExemptTarget(api,
responseJSON.get("id").asString());
return userWhitelist.new Info(responseJSON);
} | java | {
"resource": ""
} |
q7064 | BoxCollaborationWhitelistExemptTarget.getInfo | train | public BoxCollaborationWhitelistExemptTarget.Info getInfo() {
URL url = COLLABORATION_WHITELIST_EXEMPT_TARGET_ENTRY_URL_TEMPLATE.build(this.getAPI().getBaseURL(),
this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, HttpMethod.GET);
BoxJSONResponse response = (BoxJSONResponse) request.send();
return new Info(JsonObject.readFrom(response.getJSON()));
} | java | {
"resource": ""
} |
q7065 | BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection | train | public static BoxDeveloperEditionAPIConnection getAppEnterpriseConnection(String enterpriseId, String clientId,
String clientSecret, JWTEncryptionPreferences encryptionPref, IAccessTokenCache accessTokenCache) {
BoxDeveloperEditionAPIConnection connection = new BoxDeveloperEditionAPIConnection(enterpriseId,
DeveloperEditionEntityType.ENTERPRISE, clientId, clientSecret, encryptionPref, accessTokenCache);
connection.tryRestoreUsingAccessTokenCache();
return connection;
} | java | {
"resource": ""
} |
q7066 | BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection | train | public static BoxDeveloperEditionAPIConnection getAppEnterpriseConnection(BoxConfig boxConfig) {
BoxDeveloperEditionAPIConnection connection = getAppEnterpriseConnection(boxConfig.getEnterpriseId(),
boxConfig.getClientId(), boxConfig.getClientSecret(), boxConfig.getJWTEncryptionPreferences());
return connection;
} | java | {
"resource": ""
} |
q7067 | BoxDeveloperEditionAPIConnection.getAppUserConnection | train | public static BoxDeveloperEditionAPIConnection getAppUserConnection(String userId, String clientId,
String clientSecret, JWTEncryptionPreferences encryptionPref, IAccessTokenCache accessTokenCache) {
BoxDeveloperEditionAPIConnection connection = new BoxDeveloperEditionAPIConnection(userId,
DeveloperEditionEntityType.USER, clientId, clientSecret, encryptionPref, accessTokenCache);
connection.tryRestoreUsingAccessTokenCache();
return connection;
} | java | {
"resource": ""
} |
q7068 | BoxDeveloperEditionAPIConnection.getAppUserConnection | train | public static BoxDeveloperEditionAPIConnection getAppUserConnection(String userId, BoxConfig boxConfig) {
return getAppUserConnection(userId, boxConfig.getClientId(), boxConfig.getClientSecret(),
boxConfig.getJWTEncryptionPreferences());
} | java | {
"resource": ""
} |
q7069 | BoxDeveloperEditionAPIConnection.authenticate | train | public void authenticate() {
URL url;
try {
url = new URL(this.getTokenURL());
} catch (MalformedURLException e) {
assert false : "An invalid token URL indicates a bug in the SDK.";
throw new RuntimeException("An invalid token URL indicates a bug in the SDK.", e);
}
String jwtAssertion = this.constructJWTAssertion();
String urlParameters = String.format(JWT_GRANT_TYPE, this.getClientID(), this.getClientSecret(), jwtAssertion);
BoxAPIRequest request = new BoxAPIRequest(this, url, "POST");
request.shouldAuthenticate(false);
request.setBody(urlParameters);
String json;
try {
BoxJSONResponse response = (BoxJSONResponse) request.send();
json = response.getJSON();
} catch (BoxAPIException ex) {
// Use the Date advertised by the Box server as the current time to synchronize clocks
List<String> responseDates = ex.getHeaders().get("Date");
NumericDate currentTime;
if (responseDates != null) {
String responseDate = responseDates.get(0);
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss zzz");
try {
Date date = dateFormat.parse(responseDate);
currentTime = NumericDate.fromMilliseconds(date.getTime());
} catch (ParseException e) {
currentTime = NumericDate.now();
}
} else {
currentTime = NumericDate.now();
}
// Reconstruct the JWT assertion, which regenerates the jti claim, with the new "current" time
jwtAssertion = this.constructJWTAssertion(currentTime);
urlParameters = String.format(JWT_GRANT_TYPE, this.getClientID(), this.getClientSecret(), jwtAssertion);
// Re-send the updated request
request = new BoxAPIRequest(this, url, "POST");
request.shouldAuthenticate(false);
request.setBody(urlParameters);
BoxJSONResponse response = (BoxJSONResponse) request.send();
json = response.getJSON();
}
JsonObject jsonObject = JsonObject.readFrom(json);
this.setAccessToken(jsonObject.get("access_token").asString());
this.setLastRefresh(System.currentTimeMillis());
this.setExpires(jsonObject.get("expires_in").asLong() * 1000);
//if token cache is specified, save to cache
if (this.accessTokenCache != null) {
String key = this.getAccessTokenCacheKey();
JsonObject accessTokenCacheInfo = new JsonObject()
.add("accessToken", this.getAccessToken())
.add("lastRefresh", this.getLastRefresh())
.add("expires", this.getExpires());
this.accessTokenCache.put(key, accessTokenCacheInfo.toString());
}
} | java | {
"resource": ""
} |
q7070 | BoxDeveloperEditionAPIConnection.refresh | train | public void refresh() {
this.getRefreshLock().writeLock().lock();
try {
this.authenticate();
} catch (BoxAPIException e) {
this.notifyError(e);
this.getRefreshLock().writeLock().unlock();
throw e;
}
this.notifyRefresh();
this.getRefreshLock().writeLock().unlock();
} | java | {
"resource": ""
} |
q7071 | BoxFile.addTask | train | public BoxTask.Info addTask(BoxTask.Action action, String message, Date dueAt) {
JsonObject itemJSON = new JsonObject();
itemJSON.add("type", "file");
itemJSON.add("id", this.getID());
JsonObject requestJSON = new JsonObject();
requestJSON.add("item", itemJSON);
requestJSON.add("action", action.toJSONString());
if (message != null && !message.isEmpty()) {
requestJSON.add("message", message);
}
if (dueAt != null) {
requestJSON.add("due_at", BoxDateFormat.format(dueAt));
}
URL url = ADD_TASK_URL_TEMPLATE.build(this.getAPI().getBaseURL());
BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "POST");
request.setBody(requestJSON.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
BoxTask addedTask = new BoxTask(this.getAPI(), responseJSON.get("id").asString());
return addedTask.new Info(responseJSON);
} | java | {
"resource": ""
} |
q7072 | BoxFile.getDownloadURL | train | public URL getDownloadURL() {
URL url = CONTENT_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
request.setFollowRedirects(false);
BoxRedirectResponse response = (BoxRedirectResponse) request.send();
return response.getRedirectURL();
} | java | {
"resource": ""
} |
q7073 | BoxFile.downloadRange | train | public void downloadRange(OutputStream output, long rangeStart, long rangeEnd) {
this.downloadRange(output, rangeStart, rangeEnd, null);
} | java | {
"resource": ""
} |
q7074 | BoxFile.downloadRange | train | public void downloadRange(OutputStream output, long rangeStart, long rangeEnd, ProgressListener listener) {
URL url = CONTENT_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
if (rangeEnd > 0) {
request.addHeader("Range", String.format("bytes=%s-%s", Long.toString(rangeStart),
Long.toString(rangeEnd)));
} else {
request.addHeader("Range", String.format("bytes=%s-", Long.toString(rangeStart)));
}
BoxAPIResponse response = request.send();
InputStream input = response.getBody(listener);
byte[] buffer = new byte[BUFFER_SIZE];
try {
int n = input.read(buffer);
while (n != -1) {
output.write(buffer, 0, n);
n = input.read(buffer);
}
} catch (IOException e) {
throw new BoxAPIException("Couldn't connect to the Box API due to a network error.", e);
} finally {
response.disconnect();
}
} | java | {
"resource": ""
} |
q7075 | BoxFile.rename | train | public void rename(String newName) {
URL url = FILE_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "PUT");
JsonObject updateInfo = new JsonObject();
updateInfo.add("name", newName);
request.setBody(updateInfo.toString());
BoxAPIResponse response = request.send();
response.disconnect();
} | java | {
"resource": ""
} |
q7076 | BoxFile.getRepresentationContent | train | public void getRepresentationContent(String representationHint, String assetPath, OutputStream output) {
List<Representation> reps = this.getInfoWithRepresentations(representationHint).getRepresentations();
if (reps.size() < 1) {
throw new BoxAPIException("No matching representations found");
}
Representation representation = reps.get(0);
String repState = representation.getStatus().getState();
if (repState.equals("viewable") || repState.equals("success")) {
this.makeRepresentationContentRequest(representation.getContent().getUrlTemplate(),
assetPath, output);
return;
} else if (repState.equals("pending") || repState.equals("none")) {
String repContentURLString = null;
while (repContentURLString == null) {
repContentURLString = this.pollRepInfo(representation.getInfo().getUrl());
}
this.makeRepresentationContentRequest(repContentURLString, assetPath, output);
return;
} else if (repState.equals("error")) {
throw new BoxAPIException("Representation had error status");
} else {
throw new BoxAPIException("Representation had unknown status");
}
} | java | {
"resource": ""
} |
q7077 | BoxFile.getVersions | train | public Collection<BoxFileVersion> getVersions() {
URL url = VERSIONS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject jsonObject = JsonObject.readFrom(response.getJSON());
JsonArray entries = jsonObject.get("entries").asArray();
Collection<BoxFileVersion> versions = new ArrayList<BoxFileVersion>();
for (JsonValue entry : entries) {
versions.add(new BoxFileVersion(this.getAPI(), entry.asObject(), this.getID()));
}
return versions;
} | java | {
"resource": ""
} |
q7078 | BoxFile.canUploadVersion | train | public boolean canUploadVersion(String name, long fileSize) {
URL url = CONTENT_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "OPTIONS");
JsonObject preflightInfo = new JsonObject();
if (name != null) {
preflightInfo.add("name", name);
}
preflightInfo.add("size", fileSize);
request.setBody(preflightInfo.toString());
try {
BoxAPIResponse response = request.send();
return response.getResponseCode() == 200;
} catch (BoxAPIException ex) {
if (ex.getResponseCode() >= 400 && ex.getResponseCode() < 500) {
// This looks like an error response, menaing the upload would fail
return false;
} else {
// This looks like a network error or server error, rethrow exception
throw ex;
}
}
} | java | {
"resource": ""
} |
q7079 | BoxFile.getThumbnail | train | public byte[] getThumbnail(ThumbnailFileType fileType, int minWidth, int minHeight, int maxWidth, int maxHeight) {
QueryStringBuilder builder = new QueryStringBuilder();
builder.appendParam("min_width", minWidth);
builder.appendParam("min_height", minHeight);
builder.appendParam("max_width", maxWidth);
builder.appendParam("max_height", maxHeight);
URLTemplate template;
if (fileType == ThumbnailFileType.PNG) {
template = GET_THUMBNAIL_PNG_TEMPLATE;
} else if (fileType == ThumbnailFileType.JPG) {
template = GET_THUMBNAIL_JPG_TEMPLATE;
} else {
throw new BoxAPIException("Unsupported thumbnail file type");
}
URL url = template.buildWithQuery(this.getAPI().getBaseURL(), builder.toString(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
BoxAPIResponse response = request.send();
ByteArrayOutputStream thumbOut = new ByteArrayOutputStream();
InputStream body = response.getBody();
byte[] buffer = new byte[BUFFER_SIZE];
try {
int n = body.read(buffer);
while (n != -1) {
thumbOut.write(buffer, 0, n);
n = body.read(buffer);
}
} catch (IOException e) {
throw new BoxAPIException("Error reading thumbnail bytes from response body", e);
} finally {
response.disconnect();
}
return thumbOut.toByteArray();
} | java | {
"resource": ""
} |
q7080 | BoxFile.getComments | train | public List<BoxComment.Info> getComments() {
URL url = GET_COMMENTS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
int totalCount = responseJSON.get("total_count").asInt();
List<BoxComment.Info> comments = new ArrayList<BoxComment.Info>(totalCount);
JsonArray entries = responseJSON.get("entries").asArray();
for (JsonValue value : entries) {
JsonObject commentJSON = value.asObject();
BoxComment comment = new BoxComment(this.getAPI(), commentJSON.get("id").asString());
BoxComment.Info info = comment.new Info(commentJSON);
comments.add(info);
}
return comments;
} | java | {
"resource": ""
} |
q7081 | BoxFile.getTasks | train | public List<BoxTask.Info> getTasks(String... fields) {
QueryStringBuilder builder = new QueryStringBuilder();
if (fields.length > 0) {
builder.appendParam("fields", fields).toString();
}
URL url = GET_TASKS_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), builder.toString(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
int totalCount = responseJSON.get("total_count").asInt();
List<BoxTask.Info> tasks = new ArrayList<BoxTask.Info>(totalCount);
JsonArray entries = responseJSON.get("entries").asArray();
for (JsonValue value : entries) {
JsonObject taskJSON = value.asObject();
BoxTask task = new BoxTask(this.getAPI(), taskJSON.get("id").asString());
BoxTask.Info info = task.new Info(taskJSON);
tasks.add(info);
}
return tasks;
} | java | {
"resource": ""
} |
q7082 | BoxFile.createMetadata | train | public Metadata createMetadata(String typeName, Metadata metadata) {
String scope = Metadata.scopeBasedOnType(typeName);
return this.createMetadata(typeName, scope, metadata);
} | java | {
"resource": ""
} |
q7083 | BoxFile.updateClassification | train | public String updateClassification(String classificationType) {
Metadata metadata = new Metadata("enterprise", Metadata.CLASSIFICATION_TEMPLATE_KEY);
metadata.add("/Box__Security__Classification__Key", classificationType);
Metadata classification = this.updateMetadata(metadata);
return classification.getString(Metadata.CLASSIFICATION_KEY);
} | java | {
"resource": ""
} |
q7084 | BoxFile.setClassification | train | public String setClassification(String classificationType) {
Metadata metadata = new Metadata().add(Metadata.CLASSIFICATION_KEY, classificationType);
Metadata classification = null;
try {
classification = this.createMetadata(Metadata.CLASSIFICATION_TEMPLATE_KEY, "enterprise", metadata);
} catch (BoxAPIException e) {
if (e.getResponseCode() == 409) {
metadata = new Metadata("enterprise", Metadata.CLASSIFICATION_TEMPLATE_KEY);
metadata.replace(Metadata.CLASSIFICATION_KEY, classificationType);
classification = this.updateMetadata(metadata);
} else {
throw e;
}
}
return classification.getString(Metadata.CLASSIFICATION_KEY);
} | java | {
"resource": ""
} |
q7085 | BoxFile.lock | train | public BoxLock lock(Date expiresAt, boolean isDownloadPrevented) {
String queryString = new QueryStringBuilder().appendParam("fields", "lock").toString();
URL url = FILE_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), queryString, this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "PUT");
JsonObject lockConfig = new JsonObject();
lockConfig.add("type", "lock");
if (expiresAt != null) {
lockConfig.add("expires_at", BoxDateFormat.format(expiresAt));
}
lockConfig.add("is_download_prevented", isDownloadPrevented);
JsonObject requestJSON = new JsonObject();
requestJSON.add("lock", lockConfig);
request.setBody(requestJSON.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
JsonValue lockValue = responseJSON.get("lock");
JsonObject lockJSON = JsonObject.readFrom(lockValue.toString());
return new BoxLock(lockJSON, this.getAPI());
} | java | {
"resource": ""
} |
q7086 | BoxFile.unlock | train | public void unlock() {
String queryString = new QueryStringBuilder().appendParam("fields", "lock").toString();
URL url = FILE_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), queryString, this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "PUT");
JsonObject lockObject = new JsonObject();
lockObject.add("lock", JsonObject.NULL);
request.setBody(lockObject.toString());
request.send();
} | java | {
"resource": ""
} |
q7087 | BoxFile.updateMetadata | train | public Metadata updateMetadata(Metadata metadata) {
String scope;
if (metadata.getScope().equals(Metadata.GLOBAL_METADATA_SCOPE)) {
scope = Metadata.GLOBAL_METADATA_SCOPE;
} else {
scope = Metadata.ENTERPRISE_METADATA_SCOPE;
}
URL url = METADATA_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID(),
scope, metadata.getTemplateName());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "PUT");
request.addHeader("Content-Type", "application/json-patch+json");
request.setBody(metadata.getPatch());
BoxJSONResponse response = (BoxJSONResponse) request.send();
return new Metadata(JsonObject.readFrom(response.getJSON()));
} | java | {
"resource": ""
} |
q7088 | BoxFile.createUploadSession | train | public BoxFileUploadSession.Info createUploadSession(long fileSize) {
URL url = UPLOAD_SESSION_URL_TEMPLATE.build(this.getAPI().getBaseUploadURL(), this.getID());
BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "POST");
request.addHeader("Content-Type", "application/json");
JsonObject body = new JsonObject();
body.add("file_size", fileSize);
request.setBody(body.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject jsonObject = JsonObject.readFrom(response.getJSON());
String sessionId = jsonObject.get("id").asString();
BoxFileUploadSession session = new BoxFileUploadSession(this.getAPI(), sessionId);
return session.new Info(jsonObject);
} | java | {
"resource": ""
} |
q7089 | EventLog.getEnterpriseEvents | train | public static EventLog getEnterpriseEvents(BoxAPIConnection api, Date after, Date before, BoxEvent.Type... types) {
return getEnterpriseEvents(api, null, after, before, ENTERPRISE_LIMIT, types);
} | java | {
"resource": ""
} |
q7090 | BoxStoragePolicy.getInfo | train | public BoxStoragePolicy.Info getInfo(String... fields) {
QueryStringBuilder builder = new QueryStringBuilder();
if (fields.length > 0) {
builder.appendParam("fields", fields);
}
URL url = STORAGE_POLICY_WITH_ID_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), builder.toString(),
this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
return new Info(response.getJSON());
} | java | {
"resource": ""
} |
q7091 | LargeFileUpload.upload | train | public BoxFile.Info upload(BoxAPIConnection boxApi, String folderId, InputStream stream, URL url,
String fileName, long fileSize) throws InterruptedException, IOException {
//Create a upload session
BoxFileUploadSession.Info session = this.createUploadSession(boxApi, folderId, url, fileName, fileSize);
return this.uploadHelper(session, stream, fileSize);
} | java | {
"resource": ""
} |
q7092 | LargeFileUpload.generateDigest | train | public String generateDigest(InputStream stream) {
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance(DIGEST_ALGORITHM_SHA1);
} catch (NoSuchAlgorithmException ae) {
throw new BoxAPIException("Digest algorithm not found", ae);
}
//Calcuate the digest using the stream.
DigestInputStream dis = new DigestInputStream(stream, digest);
try {
int value = dis.read();
while (value != -1) {
value = dis.read();
}
} catch (IOException ioe) {
throw new BoxAPIException("Reading the stream failed.", ioe);
}
//Get the calculated digest for the stream
byte[] digestBytes = digest.digest();
return Base64.encode(digestBytes);
} | java | {
"resource": ""
} |
q7093 | BoxSharedLink.setPermissions | train | public void setPermissions(Permissions permissions) {
if (this.permissions == permissions) {
return;
}
this.removeChildObject("permissions");
this.permissions = permissions;
this.addChildObject("permissions", permissions);
} | java | {
"resource": ""
} |
q7094 | BoxTrash.deleteFolder | train | public void deleteFolder(String folderID) {
URL url = FOLDER_INFO_URL_TEMPLATE.build(this.api.getBaseURL(), folderID);
BoxAPIRequest request = new BoxAPIRequest(this.api, url, "DELETE");
BoxAPIResponse response = request.send();
response.disconnect();
} | java | {
"resource": ""
} |
q7095 | BoxTrash.getFolderInfo | train | public BoxFolder.Info getFolderInfo(String folderID) {
URL url = FOLDER_INFO_URL_TEMPLATE.build(this.api.getBaseURL(), folderID);
BoxAPIRequest request = new BoxAPIRequest(this.api, url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject jsonObject = JsonObject.readFrom(response.getJSON());
BoxFolder folder = new BoxFolder(this.api, jsonObject.get("id").asString());
return folder.new Info(response.getJSON());
} | java | {
"resource": ""
} |
q7096 | BoxTrash.getFolderInfo | train | public BoxFolder.Info getFolderInfo(String folderID, String... fields) {
String queryString = new QueryStringBuilder().appendParam("fields", fields).toString();
URL url = FOLDER_INFO_URL_TEMPLATE.buildWithQuery(this.api.getBaseURL(), queryString, folderID);
BoxAPIRequest request = new BoxAPIRequest(this.api, url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject jsonObject = JsonObject.readFrom(response.getJSON());
BoxFolder folder = new BoxFolder(this.api, jsonObject.get("id").asString());
return folder.new Info(response.getJSON());
} | java | {
"resource": ""
} |
q7097 | BoxTrash.restoreFolder | train | public BoxFolder.Info restoreFolder(String folderID) {
URL url = RESTORE_FOLDER_URL_TEMPLATE.build(this.api.getBaseURL(), folderID);
BoxAPIRequest request = new BoxAPIRequest(this.api, url, "POST");
JsonObject requestJSON = new JsonObject()
.add("", "");
request.setBody(requestJSON.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
BoxFolder restoredFolder = new BoxFolder(this.api, responseJSON.get("id").asString());
return restoredFolder.new Info(responseJSON);
} | java | {
"resource": ""
} |
q7098 | BoxTrash.restoreFolder | train | public BoxFolder.Info restoreFolder(String folderID, String newName, String newParentID) {
JsonObject requestJSON = new JsonObject();
if (newName != null) {
requestJSON.add("name", newName);
}
if (newParentID != null) {
JsonObject parent = new JsonObject();
parent.add("id", newParentID);
requestJSON.add("parent", parent);
}
URL url = RESTORE_FOLDER_URL_TEMPLATE.build(this.api.getBaseURL(), folderID);
BoxJSONRequest request = new BoxJSONRequest(this.api, url, "POST");
request.setBody(requestJSON.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
BoxFolder restoredFolder = new BoxFolder(this.api, responseJSON.get("id").asString());
return restoredFolder.new Info(responseJSON);
} | java | {
"resource": ""
} |
q7099 | BoxTrash.deleteFile | train | public void deleteFile(String fileID) {
URL url = FILE_INFO_URL_TEMPLATE.build(this.api.getBaseURL(), fileID);
BoxAPIRequest request = new BoxAPIRequest(this.api, url, "DELETE");
BoxAPIResponse response = request.send();
response.disconnect();
} | java | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.