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

kit-data-manager / ro-crate-java / #381

29 Apr 2025 02:09PM UTC coverage: 88.884%. First build
#381

Pull #233

github

Pfeil
feat: add Javadoc generation step to CI pipeline
Pull Request #233: Version 2.1.0

598 of 700 new or added lines in 28 files covered. (85.43%)

1879 of 2114 relevant lines covered (88.88%)

0.89 hits per line

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

83.87
/src/main/java/edu/kit/datamanager/ro_crate/externalproviders/organizationprovider/RorProvider.java
1
package edu.kit.datamanager.ro_crate.externalproviders.organizationprovider;
2

3
import com.fasterxml.jackson.databind.JsonNode;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
import com.fasterxml.jackson.databind.node.ObjectNode;
6

7
import edu.kit.datamanager.ro_crate.entities.contextual.OrganizationEntity;
8
import edu.kit.datamanager.ro_crate.objectmapper.MyObjectMapper;
9

10
import java.io.IOException;
11
import java.util.ArrayList;
12

13
import org.apache.http.HttpStatus;
14
import org.apache.http.client.methods.CloseableHttpResponse;
15
import org.apache.http.client.methods.HttpGet;
16
import org.apache.http.impl.client.CloseableHttpClient;
17
import org.apache.http.impl.client.HttpClients;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

21
/**
22
 * Class providing possibility to import organization entities from ror.com.
23
 */
24
public class RorProvider {
25

26
    private static final Logger logger = LoggerFactory.getLogger(RorProvider.class);
1✔
27

28
    private RorProvider() {
29
    }
30

31
    /**
32
     * The method that parses a ror entry to a crate entity.
33
     *
34
     * @param url the url of the ror entry.
35
     * @return the created Organization entity.
36
     */
37
    public static OrganizationEntity getOrganization(String url) {
38
        if (!url.startsWith("https://ror.org/")) {
1✔
39
            throw new IllegalArgumentException("Should provide ror url");
1✔
40
        }
41
        String newUrl = "https://api.ror.org/v2/organizations/" + url.replaceAll("https://ror.org/", "");
1✔
42
        HttpGet request = new HttpGet(newUrl);
1✔
43

44
        try (
45
                CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = httpClient.execute(request)) {
1✔
46
            boolean isError = response.getStatusLine().getStatusCode() != HttpStatus.SC_OK;
1✔
47
            if (isError) {
1✔
48
                String errorMessage = String.format("Identifier not found: %s", response.getStatusLine().toString());
1✔
49
                logger.error(errorMessage);
1✔
50
                return null;
1✔
51
            }
52
            ObjectNode jsonNode = MyObjectMapper.getMapper().readValue(response.getEntity().getContent(),
1✔
53
                    ObjectNode.class);
54

55
            return new OrganizationEntity.OrganizationEntityBuilder()
1✔
56
                    .setId(jsonNode.path("id").asText())
1✔
57
                    .addProperty("name", getOrganizationNameV2(jsonNode.path("names")))
1✔
58
                    .addProperty("email", jsonNode.path("email_address"))
1✔
59
                    .addProperty("url", jsonNode.path("id").asText())
1✔
60
                    .build();
1✔
61
        } catch (IOException e) {
1✔
NEW
62
            String errorMessage = String.format("IO error: %s", e.getMessage());
×
NEW
63
            logger.error(errorMessage);
×
64
        }
NEW
65
        return null;
×
66
    }
67

68
    private static String getOrganizationNameV2(JsonNode node) {
69
        if (node.isArray()) {
1✔
70
            for (JsonNode n : node) {
1✔
71
                if (n.has("types") && n.path("types").isArray()) {
1✔
72
                    ArrayList<?> l = new ObjectMapper().convertValue(n.path("types"), ArrayList.class);
1✔
73
                    if (l.contains("ror_display")) {
1✔
74
                        return n.path("value").asText();
1✔
75
                    }
76
                }
77
            }
1✔
78
            //fallback
NEW
79
            return node.path(0).path("value").asText();
×
80
        } else {
NEW
81
            return node.asText();
×
82
        }
83
    }
84

85
}
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

© 2026 Coveralls, Inc