AtlasOfLivingAustralia / doi-service

ALA DOI minting service - integrates with ANDS to produce the DOI, provides a landing page, and stores the associated file
https://doi.ala.org.au/
0 stars 4 forks source link

Mint DOI API call: Provider metadata should be generated from general metadata. #30

Closed javier-molina closed 12 months ago

javier-molina commented 6 years ago

Currently the mint DOI API call requires a caller to fill in the providerMetadata that will be passed to ANDS, most of that information however is redundant as it is the general information that the DOI service already stores locally when minting a new DOI.

The DOI service must be able to generate the appropriate providerMetadata if the caller does not provide any, this will effectively hide the implementation details from the client which should only be concerned with talking to the DOI service only.

Below is a code snippet of how currently biocache-service deals with populating the doi-service and provider specific metadata, this the provider metadata code can be reused for implementing this ticket in the DOI service.

    /**
     * Mint a new DOI
     *
     * @param downloadInfo
     * @throws IOException If unable to connect to the DOI service backend
     */
    public CreateDoiResponse mintDoi(DownloadDoiDTO downloadInfo) throws IOException {
        CreateDoiRequest request = new CreateDoiRequest();

        request.setAuthors(doiAuthor);
        request.setTitle(downloadInfo.getTitle());
        request.setApplicationUrl(downloadInfo.getApplicationUrl());
        request.setDescription(doiDescription);
        request.setLicence(downloadInfo.getLicence());
        request.setUserId(downloadInfo.getRequesterId());

        request.setProvider(Provider.ANDS.name());
        request.setFileUrl(downloadInfo.getFileUrl());

        Map providerMetadata = generateProviderMetadataPayload(downloadInfo);

        request.setProviderMetadata(providerMetadata);

        Map applicationMetadata = new HashMap<String, String>();
        applicationMetadata.put("searchUrl", downloadInfo.getApplicationUrl());
        applicationMetadata.put("datasets", downloadInfo.getDatasetMetadata());
        applicationMetadata.put("requestedOn", downloadInfo.getRequestTime());
        applicationMetadata.put("recordCount", Long.toString(downloadInfo.getRecordCount()));
        applicationMetadata.put("queryTitle", downloadInfo.getQueryTitle());

        request.setApplicationMetadata(applicationMetadata);

        return mintDoi(request);
    }

    private Map generateProviderMetadataPayload(DownloadDoiDTO downloadInfo) {
        Map providerMetadata = new HashMap<String, String>();

        List<String> authorsList = new ArrayList<>();
        authorsList.add(doiAuthor);

        providerMetadata.put("authors", authorsList);
        providerMetadata.put("publisher", doiAuthor);
        providerMetadata.put("title", downloadInfo.getTitle());

        providerMetadata.put("resourceType", "Text");
        providerMetadata.put("resourceText", doiResourceText);

        List<Map> contributorsList = new ArrayList<>();
        Map <String, String> contributorMap = new HashMap<>();
        contributorMap.put("name", downloadInfo.getRequesterName());
        contributorMap.put("type", "Distributor");

        contributorsList.add(contributorMap);
        providerMetadata.put("contributors", contributorsList);

        List<Map> descriptionsList = new ArrayList<>();
        Map <String, String> descriptionMap = new HashMap<>();
        descriptionMap.put("text", doiDescription);
        descriptionMap.put("type", "Other");

        descriptionsList.add(descriptionMap);
        providerMetadata.put("descriptions", descriptionsList);

        List<Map<String, String>> creators = new ArrayList<>();

        for(Map<String, String> datasetProvider: downloadInfo.getDatasetMetadata()) {
            Map<String, String> creator = new HashMap<>();
            creator.put("name", datasetProvider.get("name"));
            creator.put("type", "Producer" );
            creators.add(creator);
        }

        providerMetadata.put("creator", creators);

        return providerMetadata;
    }
adam-collins commented 12 months ago

No planned usage of DOI application requires this at this time.