• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk / #3909

12 Jul 2024 01:30PM CUT coverage: 72.476% (+0.04%) from 72.438%
#3909

Pull #1258

github

web-flow
Merge 6eb7aa968 into f08844889
Pull Request #1258: test: Add test for uploading file using stream

7681 of 10598 relevant lines covered (72.48%)

0.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/box/sdk/BoxMetadataQueryItem.java
1
package com.box.sdk;
2

3
import com.eclipsesource.json.JsonObject;
4
import com.eclipsesource.json.JsonValue;
5
import java.util.ArrayList;
6
import java.util.HashMap;
7

8
/**
9
 * Represents an individual item returned by a metadata query item.
10
 *
11
 * <p>Unless otherwise noted, the methods in this class can throw an unchecked {@link BoxAPIException} (unchecked
12
 * meaning that the compiler won't force you to handle it) if an error occurs. If you wish to implement custom error
13
 * handling for errors related to the Box REST API, you should capture this exception explicitly.
14
 */
15
public class BoxMetadataQueryItem extends BoxJSONObject {
×
16
    private BoxItem.Info item;
17
    private HashMap<String, ArrayList<Metadata>> metadata;
18
    private BoxAPIConnection api;
19

20
    /**
21
     * Construct a BoxMetadataQueryItem.
22
     *
23
     * @param jsonObject the parsed JSON object.
24
     * @param api        the API connection to be used to fetch interacted item
25
     */
26
    public BoxMetadataQueryItem(JsonObject jsonObject, BoxAPIConnection api) {
27
        super(jsonObject);
×
28
        this.api = api;
×
29
    }
×
30

31
    @Override
32
    protected void parseJSONMember(JsonObject.Member member) {
33
        super.parseJSONMember(member);
×
34

35
        String memberName = member.getName();
×
36
        JsonValue value = member.getValue();
×
37
        if (memberName.equals("item")) {
×
38
            String id = value.asObject().get("id").asString();
×
39
            String type = value.asObject().get("type").asString();
×
40
            this.item = new BoxFile(this.api, id).new Info(value.asObject());
×
41
            if (type.equals("folder")) {
×
42
                BoxFolder folder = new BoxFolder(this.api, id);
×
43
                this.item = folder.new Info(value.asObject());
×
44
            } else if (type.equals("file")) {
×
45
                BoxFile file = new BoxFile(this.api, id);
×
46
                this.item = file.new Info(value.asObject());
×
47
            } else if (type.equals("web_link")) {
×
48
                BoxWebLink link = new BoxWebLink(this.api, id);
×
49
                this.item = link.new Info(value.asObject());
×
50
            } else {
×
51
                assert false : "Unsupported item type: " + type;
×
52
                throw new BoxAPIException("Unsupported item type: " + type);
×
53
            }
54
        } else if (memberName.equals("metadata")) {
×
55
            this.metadata = new HashMap<String, ArrayList<Metadata>>();
×
56
            JsonObject metadataObject = value.asObject();
×
57
            for (JsonObject.Member enterprise : metadataObject) {
×
58
                String enterpriseName = enterprise.getName();
×
59
                JsonObject templates = enterprise.getValue().asObject();
×
60
                ArrayList<Metadata> enterpriseMetadataArray = new ArrayList<Metadata>();
×
61
                for (JsonObject.Member template : templates) {
×
62
                    String templateName = template.getName();
×
63
                    JsonObject templateValue = template.getValue().asObject();
×
64
                    Metadata metadataOfTemplate = new Metadata(templateValue);
×
65
                    metadataOfTemplate.add("/$scope", enterpriseName);
×
66
                    metadataOfTemplate.add("/$template", templateName);
×
67
                    enterpriseMetadataArray.add(metadataOfTemplate);
×
68
                }
×
69
                this.metadata.put(enterpriseName, enterpriseMetadataArray);
×
70
            }
×
71
        }
72
    }
×
73

74
    /**
75
     * Get the item which was interacted with.
76
     *
77
     * @return box item
78
     */
79
    public BoxItem.Info getItem() {
80
        return this.item;
×
81
    }
82

83
    /**
84
     * Get the metadata on the item.
85
     *
86
     * @return HashMap of metadata
87
     */
88
    public HashMap<String, ArrayList<Metadata>> getMetadata() {
89
        return this.metadata;
×
90
    }
91

92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc