Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by krishna_at ( 6 years ago )
package com.amazon.adslabelingrequestbfflambda.service;

import com.amazon.adslabelingrequestbfflambda.LabelingRequestSearchResponseMetadata;
import com.amazon.labellingrequest.client.lib.LabellingRequestHelperClient;
import com.amazon.labellingrequest.client.lib.exceptions.LabellingRequestClientDependencyNonRetryableException;
import com.amazon.labellingrequest.client.lib.exceptions.LabellingRequestClientDependencyRetryableException;
import com.amazon.labellingrequest.client.lib.interfaces.LabellingRequestClient;
import com.amazon.labellingrequest.client.lib.model.LabellingRequestMetaData;
import com.amazonaws.auth.AWSCredentialsProvider;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.client.Client;
import java.util.List;
import java.util.stream.Collectors;

/**
 * This class returns the search details for the list of labelling requests according to the search parameters
 */
@AllArgsConstructor(onConstructor = @__(@Inject))
@Slf4j
public class SearchLabelingRequestsService {


    @Named("CloudAuthEnableRestClient")
    private Client client;

    @Named("defaultAWSCredentialsProvider")
    private AWSCredentialsProvider awsCredentialsProvider;

    @Named("wfmServiceEndpoint")
    private String wfmServiceEndpoint;

    @Named("labellingRequestClient")
    private LabellingRequestClient lrHelperClient;

    /**
     * It returns list of labeling requests created for a customer group using LabelingRequestClientLibrary {@link LabellingRequestHelperClient}
     * @param customerGroupId - Customer Group Id
     * @return - Metadata for the labelling requests submitted for the customerGroupId.
     */
    public List<LabelingRequestSearchResponseMetadata> searchLabellingRequests(@NonNull final String customerGroupId)
            throws LabellingRequestClientDependencyNonRetryableException,
            LabellingRequestClientDependencyRetryableException{
        log.info("Request for searching labeling requests for customerGroupId {}", customerGroupId);
        List<LabellingRequestMetaData> lrSearchData = lrHelperClient.searchLabellingRequestsByCustomerGroupId(customerGroupId);
        List<LabelingRequestSearchResponseMetadata> searchResponse = lrSearchData.stream().map(lrMetadata->
                LabelingRequestSearchResponseMetadata.builder()
                        .withLabelingRequestId(lrMetadata.getRequestId())
                        .withCreatedByUserId(lrMetadata.getCreatedByUserId())
                        .withCreatedOnDate(lrMetadata.getCreatedOnDate())
                        .withRequestName(lrMetadata.getRequestName())
                        .withRequestStatus(lrMetadata.getRequestStatus().toString())
                        .build()
        ).collect(Collectors.toList());
        log.info("Labeling requests for customerGroupId {} are {}", customerGroupId, searchResponse.toString());
        return searchResponse;
    }
}

 

Revise this Paste

Your Name: Code Language: