Java 类com.amazonaws.mturk.service.exception.ServiceException 实例源码

项目:java-aws-mturk    文件:TestRequesterServiceRaw.java   
public void testRevokeQualification() throws ServiceException { 
  String qualTypeId = getTestQualificationTypeId();

  service.assignQualification(
      qualTypeId, // qualificationTypeId
      luckyWorker, // workerId
      50, // integerValue
      false // sendNotification
    );

  service.revokeQualification(
      qualTypeId, // qualificationTypeId
      luckyWorker, // workerId
      defaultReason // reason
    );
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_GetReviewableHITsOperation.html
 */ 
public GetReviewableHITsResult getReviewableHITs(String hitTypeId, ReviewableHITStatus status, 
    SortDirection sortDirection, GetReviewableHITsSortProperty sortProperty, 
    Integer pageNumber, Integer pageSize)
  throws ServiceException { 

  GetReviewableHITsRequest request = new GetReviewableHITsRequest();
  if (hitTypeId != null)      request.setHITTypeId(hitTypeId);
  if (status != null)         request.setStatus(status);
  if (pageNumber != null)     request.setPageNumber(pageNumber);
  if (pageSize != null)       request.setPageSize(pageSize);
  if (sortDirection != null)  request.setSortDirection(sortDirection);
  if (sortProperty != null)   request.setSortProperty(sortProperty);

  GetReviewableHITsResult result = null;

  result = (GetReviewableHITsResult) executeRequest(request, 
      ResultMatch.GetReviewableHITs.name(),
      ResultMatch.GetReviewableHITs.getResultTypeName());

  if (result == null) {
    throw new ServiceException("No response");
  }

  return result;
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_GetHITsForQualificationTypeOperation.html
 */ 
public GetHITsForQualificationTypeResult getHITsForQualificationType(String qualificationTypeId, 
    Integer pageNumber, Integer pageSize)
  throws ServiceException { 

  GetHITsForQualificationTypeRequest request = new GetHITsForQualificationTypeRequest();
  if (qualificationTypeId != null)  request.setQualificationTypeId(qualificationTypeId);
  if (pageNumber != null)     request.setPageNumber(pageNumber);
  if (pageSize != null)       request.setPageSize(pageSize);

  GetHITsForQualificationTypeResult result = null;

  result = (GetHITsForQualificationTypeResult) executeRequest(request, 
      ResultMatch.GetHITsForQualificationType.name(),
      ResultMatch.GetHITsForQualificationType.getResultTypeName());

  if (result == null) {
    throw new ServiceException("No response");
  }

  return result; 
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_GetQualificationsForQualificationTypeOperation.html
 */ 
public GetQualificationsForQualificationTypeResult getQualificationsForQualificationType(String qualificationTypeId, 
    QualificationStatus status, Integer pageNumber, Integer pageSize)
  throws ServiceException { 

  GetQualificationsForQualificationTypeRequest request = new GetQualificationsForQualificationTypeRequest();
  if (status != null)     request.setStatus(status);
  if (pageNumber != null) request.setPageNumber(pageNumber);
  if (pageSize != null)   request.setPageSize(pageSize);
  if (qualificationTypeId != null)  request.setQualificationTypeId(qualificationTypeId);

  GetQualificationsForQualificationTypeResult result = null;

  result = (GetQualificationsForQualificationTypeResult) executeRequest(request, 
      ResultMatch.GetQualificationsForQualificationType.name(),
      ResultMatch.GetQualificationsForQualificationType.getResultTypeName());

  if (result == null) {
    throw new ServiceException("No response");
  }

  return result; 
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_GetAssignmentsForHITOperation.html
 */ 
public GetAssignmentsForHITResult getAssignmentsForHIT(String hitId, SortDirection sortDirection, AssignmentStatus[] status, 
    GetAssignmentsForHITSortProperty sortProperty, Integer pageNumber, Integer pageSize, String[] responseGroup)
  throws ServiceException { 

  GetAssignmentsForHITRequest request = wrapAssignmentParams(hitId, sortDirection, status, 
          sortProperty, pageNumber, pageSize, responseGroup);

  GetAssignmentsForHITResult result = null;

  result = (GetAssignmentsForHITResult) executeRequest(request, 
      ResultMatch.GetAssignmentsForHIT.name(),
      ResultMatch.GetAssignmentsForHIT.getResultTypeName());    

  if (result == null) {
    throw new ServiceException("No response");
  }

  return result; 
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
public DataPoint[] getRequesterWorkerStatistic(
    RequesterStatistic statistic, TimePeriod timePeriod,
    String workerId, Integer count, String[] responseGroup)
throws ServiceException {

  GetRequesterWorkerStatisticRequest request = new GetRequesterWorkerStatisticRequest();
  if (statistic != null) request.setStatistic(statistic);
  if (timePeriod != null) request.setTimePeriod(timePeriod);
  if (workerId != null) request.setWorkerId(workerId);
  if (count != null) request.setCount(count);
  if (responseGroup != null) request.setResponseGroup(responseGroup);

  GetStatisticResult result = null;
  result = (GetStatisticResult) executeRequest(request,
      ResultMatch.GetRequesterWorkerStatistic.name(),
      ResultMatch.GetRequesterWorkerStatistic.getResultTypeName());
  if (result == null) {
    throw new ServiceException("No response");
  }
  return result.getDataPoint();
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_SearchHITsOperation.html
 */ 
public SearchHITsResult searchHITs(SortDirection sortDirection, SearchHITsSortProperty sortProperty, 
    Integer pageNumber, Integer pageSize, String[] responseGroup)
  throws ServiceException { 

  SearchHITsRequest request = new SearchHITsRequest();

  if (pageNumber != null)     request.setPageNumber(pageNumber);
  if (pageSize != null)       request.setPageSize(pageSize);
  if (sortDirection != null)  request.setSortDirection(sortDirection);
  if (sortProperty != null)   request.setSortProperty(sortProperty);
  if (responseGroup != null)  request.setResponseGroup(responseGroup);

  SearchHITsResult result = null;

  result = (SearchHITsResult) executeRequest(request, 
      ResultMatch.SearchHITs.name(),
      ResultMatch.SearchHITs.getResultTypeName());

  if (result == null) {
    throw new ServiceException("No response");
  }

  return result;
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_GrantBonusOperation.html
 */ 
public void grantBonus(String workerId, Double bonusAmount, String assignmentId, 
    String reason) throws ServiceException { 

  GrantBonusRequest request = new GrantBonusRequest();
  if (assignmentId != null) request.setAssignmentId(assignmentId);
  if (reason != null)       request.setReason(reason);
  if (workerId != null)     request.setWorkerId(workerId);

  if (bonusAmount != null) {
    Price p = new Price();
    p.setAmount(new BigDecimal(bonusAmount));
    p.setCurrencyCode("USD");
    request.setBonusAmount(p);
  }

  executeRequest(request, ResultMatch.GrantBonus.name(),
      ResultMatch.GrantBonus.getResultTypeName());
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_GetQualificationRequestsOperation.html
 */ 
public GetQualificationRequestsResult getQualificationRequests(String qualificationTypeId, SortDirection sortDirection, 
    GetQualificationRequestsSortProperty sortProperty, Integer pageNumber, Integer pageSize)
  throws ServiceException { 

  GetQualificationRequestsRequest request = new GetQualificationRequestsRequest();

  if (qualificationTypeId != null)  request.setQualificationTypeId(qualificationTypeId);
  if (pageNumber != null)           request.setPageNumber(pageNumber);
  if (pageSize != null)             request.setPageSize(pageSize);
  if (sortDirection != null)        request.setSortDirection(sortDirection);
  if (sortProperty != null)         request.setSortProperty(sortProperty);

  GetQualificationRequestsResult result = null;

  result = (GetQualificationRequestsResult) executeRequest(request, 
      ResultMatch.GetQualificationRequests.name(),
      ResultMatch.GetQualificationRequests.getResultTypeName());

  if (result == null) {
    throw new ServiceException("No response");
  }

  return result;
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_GetQualificationTypeOperation.html
 */ 
public QualificationType getQualificationType(String qualificationTypeId) throws ServiceException { 

  GetQualificationTypeRequest request = new GetQualificationTypeRequest();
  if (qualificationTypeId != null)  request.setQualificationTypeId(qualificationTypeId);

  QualificationType result = null;

  result = (QualificationType) executeRequest(request, 
      ResultMatch.GetQualificationType.name(),
      ResultMatch.GetQualificationType.getResultTypeName());

  if (result == null) {
    throw new ServiceException("No response");
  }

  return result;
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_GetQualificationScoreOperation.html
 */ 
public Qualification getQualificationScore(String qualificationTypeId, String subjectId) 
  throws ServiceException { 

  GetQualificationScoreRequest request = new GetQualificationScoreRequest();
  if (qualificationTypeId != null)  request.setQualificationTypeId(qualificationTypeId);
  if (subjectId != null)            request.setSubjectId(subjectId);

  Qualification result = null;
  result = (Qualification) executeRequest(request, 
      ResultMatch.GetQualificationScore.name(),
      ResultMatch.GetQualificationScore.getResultTypeName());

  if (result == null) {
    throw new ServiceException("No response");
  }

  return result;
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_GetAccountBalanceOperation.html
 */ 
public GetAccountBalanceResult getAccountBalance(String unused) throws ServiceException { 

  GetAccountBalanceRequest request = new GetAccountBalanceRequest();
  if (unused != null) request.setUnused(unused);

  GetAccountBalanceResult result = null;

  result = (GetAccountBalanceResult) executeRequest(request, 
      ResultMatch.GetAccountBalance.name(),
      ResultMatch.GetAccountBalance.getResultTypeName());

  if (result == null) {
    throw new ServiceException("No response");
  }

  return result;
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_GetRequesterStatisticOperation.html
 */ 
public DataPoint[] getRequesterStatistic(RequesterStatistic statistic, TimePeriod timePeriod, 
    Integer count) throws ServiceException { 

  GetRequesterStatisticRequest request = new GetRequesterStatisticRequest();
  if (count != null)      request.setCount(count);
  if (statistic != null)  request.setStatistic(statistic);
  if (timePeriod != null) request.setTimePeriod(timePeriod);

  GetStatisticResult result = null;
  result = (GetStatisticResult) executeRequest(request, 
      ResultMatch.GetRequesterStatistic.name(),
      ResultMatch.GetRequesterStatistic.getResultTypeName());

  if (result == null || result.getDataPoint() == null) {
    throw new ServiceException("No response");
  }

  return result.getDataPoint();
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_GetWorkerAcceptLimitOperation.html
 */ 
public Information help(String[] about, HelpRequestHelpType type) throws ServiceException { 
  HelpRequest request = new HelpRequest();
  if (about != null) request.setAbout(about);
  if (type != null) request.setHelpType(type);

  Information result = null;

  result = (Information) executeRequest(request, 
      ResultMatch.Help.name(),
      ResultMatch.Help.getResultTypeName());

  if (result == null) {
    throw new ServiceException("No response");
  }

  return result;
}
项目:java-aws-mturk    文件:TestBase.java   
protected HIT createHIT(QualificationRequirement qualRequirement) throws ServiceException {
  QualificationRequirement[] qualRequirements = null;
  if (qualRequirement != null) { 
    qualRequirements = new QualificationRequirement[] { qualRequirement };
  }

  HIT hit = service.createHIT(null, // HITTypeId 
      defaultHITTitle + unique, 
      defaultHITDescription, null, // keywords 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultReward, 
      defaultAssignmentDurationInSeconds, defaultAutoApprovalDelayInSeconds, 
      defaultLifetimeInSeconds, defaultMaxAssignments, null, // requesterAnnotation 
      qualRequirements,
      null  // responseGroup
    );

  assertNotNull(hit);
  assertNotNull(hit.getHITId());

  return hit;
}
项目:java-aws-mturk    文件:RequesterService.java   
/**
 * Retrieves completed assignments for a HIT.  You can get assignments for a HIT at any time, 
 * even if the HIT is not yet "reviewable". If a HIT has multiple assignments, and has 
 * received some results but has not yet become "reviewable", you can still retrieve the partial 
 * results with this method.
 * 
 * The results are sorted by SubmitTime.  
 * 
 * @param hitId            the Id of the HIT for which completed assignments are to be returned
 * @param pageNum          The page of results to return. Once the assignments have been filtered, 
 *                         sorted, and divided into pages, the page corresponding 
 *                         to pageNum is returned as the results of the operation. 
 * @param getFullResponse  if true, all properties of the HIT are returned. If false, only the HIT Id 
 *                         and HIT type Id are returned.
 * @return an array of Assignments
 * @throws ServiceException
 */
public Assignment[] getAssignmentsForHIT(String hitId, int pageNum, boolean getFullResponse) 
throws ServiceException {

  // Include AssignmentFeedback in response
  String[] responseGroup = null;
  if (getFullResponse == true) {
    responseGroup = DEFAULT_ASSIGNMENT_RESPONSE_GROUP;
  }

  GetAssignmentsForHITResult result = super.getAssignmentsForHIT(hitId,
      DEFAULT_SORT_DIRECTION, 
      DEFAULT_ASSIGNMENT_STATUS,
      GetAssignmentsForHITSortProperty.SubmitTime,
      pageNum, DEFAULT_PAGE_SIZE, responseGroup
  );

  return result.getAssignment(); 
}
项目:java-aws-mturk    文件:RequesterService.java   
/**
 * Retrieves the Requester's HITs found on the specified page.  
 * The request uses either the default or full responseGroup.
 * 
 * @param pageNum           The page of results to return. Once the HITs
 *                          have been filtered, sorted, and divided into pages, the page 
 *                          corresponding to pageNum is returned.
 * @param getFullResponse   if true, all properties for the HIT are returned. If false, only the
 *                          HIT Id and the HIT type Id are returned.
 * @return an array of HITs
 * @throws ServiceException
 */
public HIT[] searchHITs(int pageNum, boolean getFullResponse) throws ServiceException {

  // Include HIT detail, HIT Question, and Assignment summary in response
  String[] responseGroup = null;
  if (getFullResponse == true) {
    responseGroup = new String [] { "Minimal", "HITDetail", 
        "HITQuestion", "HITAssignmentSummary" };
  }

  SearchHITsResult result = super.searchHITs(
      DEFAULT_SORT_DIRECTION, SearchHITsSortProperty.Expiration,
      pageNum, DEFAULT_PAGE_SIZE, responseGroup
  );

  return result.getHIT(); 
}
项目:java-aws-mturk    文件:TestRequesterService.java   
@SuppressWarnings("unchecked")
public void testParseAnswers() throws ServiceException {
  QuestionFormAnswers qfa = RequesterService.parseAnswers(DEFAULT_ANSWER_XML);
  List<QuestionFormAnswersType.AnswerType> answers = 
    (List<QuestionFormAnswersType.AnswerType>) qfa.getAnswer();

  for (int i=0; i< answers.size(); i++) {
    QuestionFormAnswersType.AnswerType answer = answers.get(i);
    assertNotNull(null, RequesterService.getAnswerValue(null, answer));

    // check order
    String result = RequesterService.getAnswerValue("TEST_ASSIGNMENT_ID", answer, true);
    if (i == 0) {
      assertTrue(result.equals("freeText\tfreeText_answer"));
    } else if (i == 1) {
      assertTrue(result.equals("otherSelection\totherSelection_answer"));
    } else if (i == 2) {
      assertTrue(result.startsWith("url\t"));
    } else {
      assertTrue(result.equals("selectionIdentifier\tselection_answer|selection_answer2"));
    }
  }
}
项目:java-aws-mturk    文件:TestRequesterService.java   
public void testUpdateHITReward() throws ServiceException {
  HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), 
      defaultMaxAssignments, true);

  String newHITTypeId = service.updateHIT(hit.getHITId(), 
      null, null, null, 0.50);

  HIT newHIT = service.getHIT(hit.getHITId());

  assertFalse(newHITTypeId.equals(hit.getHITTypeId()));
  assertEquals(newHITTypeId, newHIT.getHITTypeId());
  assertEquals(hit.getHITId(), newHIT.getHITId());
  assertEquals(hit.getTitle(), newHIT.getTitle());
  assertEquals(hit.getDescription(), newHIT.getDescription());
  assertEquals(hit.getKeywords(), newHIT.getKeywords());
  assertEquals(0.50, newHIT.getReward().getAmount().doubleValue());
}
项目:java-aws-mturk    文件:RequesterService.java   
/**
 * Retrieves all of the Requester's reviewable HITs of the specified HIT type.
 * 
 * @param hitTypeId  the ID of the HIT type of the HITs to consider for the query
 * @return an array of Reviewable HITs
 * @throws ServiceException
 */
public HIT[] getAllReviewableHITs(String hitTypeId) throws ServiceException {
  List<HIT> results = new ArrayList<HIT>();
  int pageNum = 1;

  do {
    HIT[] hit = this.getReviewableHITs(hitTypeId, pageNum);

    if (hit != null) {
      // Add the results
      Collections.addAll(results, hit);
    }

    // Check if we're on the last page or not
    if (hit == null || hit.length < DEFAULT_PAGE_SIZE)
      break;

    pageNum++;

  } while (true);

  return (HIT[]) results.toArray(new HIT[results.size()]);
}
项目:java-aws-mturk    文件:RequesterService.java   
/**
 * Creates a preview of a HIT in a file.
 * 
 * @param previewFileName  the file in which the HIT is copied
 * @param input            the input needed for the HIT
 * @param props            the properties of the HIT 
 * @param question         the question asked in the HIT
 * @throws ServiceException
 */
public void previewHIT(String previewFileName, HITDataInput input, HITProperties props, 
    HITQuestion question) throws ServiceException {
  try {
    String previewString = previewHIT(input, props, question);

    if (previewString != null) {
      FileUtil fts = new FileUtil(previewFileName);
      fts.saveString(previewString, false); // overwrite
    }
  }
  catch (Exception e)
  {
    throw new ServiceException("Error generating preview file " + previewFileName, e);
  }
}
项目:java-aws-mturk    文件:TestRequesterService.java   
public void testCreateHITWithInvalidHitLayoutId() throws ServiceException {
  // We only test a failure case here, because testing it with a real
  // HitLayoutId would require the user to manually get a valid HitLayoutId
  // from the requester UI.
  String layoutId = "INVALIDHITLAYOUTID";

  Map<String,String> layoutParameters = new HashMap<String,String>();
  layoutParameters.put("param1", "a test value");

  try {
    service.createHIT(
        defaultHITTitle + unique,
        defaultHITDescription,
        defaultReward,
        defaultMaxAssignments,
        layoutId,
        layoutParameters);
    fail("createHIT succeeded, despite having an invalid HIT layout ID");
  } catch (ServiceException e) {
    // expected
    assertContains("Cause of createHIT failure was not an invalid HIT layout ID",
        "HITLayout " + layoutId + " does not exist", e.getMessage());
  }
}
项目:java-aws-mturk    文件:MyHIT.java   
public void createMyHIT() {
    try {

        // The createHIT method is called using a convenience static method of
        // RequesterService.getBasicFreeTextQuestion that generates the QAP for
        // the HIT.
        HIT hit = service.createHIT(
                title,
                description,
                reward,
                RequesterService.getBasicFreeTextQuestion(
                    "What is the current temperature now in Seattle, WA?"),
                numAssignments);

        System.out.println("Created HIT: " + hit.getHITId());

        System.out.println("You may see your HIT with HITTypeId '" 
            + hit.getHITTypeId() + "' here: ");
        System.out.println(service.getWebsiteURL() 
            + "/mturk/preview?groupId=" + hit.getHITTypeId());

      } catch (ServiceException e) {
        System.err.println(e.getLocalizedMessage());
      }
}
项目:java-aws-mturk    文件:TestRequesterService.java   
public void testUpdateHITTextAttributes() throws ServiceException {
  HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), 
      defaultMaxAssignments, true);

  String newHITTypeId = service.updateHIT(hit.getHITId(), 
                    hit.getTitle() + " amended", 
      hit.getDescription() + " amended",
      "new, updated, improved, amended", null);

  HIT newHIT = service.getHIT(hit.getHITId());

  assertFalse(newHITTypeId.equals(hit.getHITTypeId()));
  assertEquals(newHITTypeId, newHIT.getHITTypeId());
  assertEquals(hit.getHITId(), newHIT.getHITId());
   assertTrue(newHIT.getTitle().endsWith(" amended"));
  assertTrue(newHIT.getDescription().endsWith(" amended"));
  assertTrue(newHIT.getKeywords().endsWith(" amended"));
  assertEquals(hit.getReward(), newHIT.getReward());
}
项目:java-aws-mturk    文件:TestRequesterService.java   
public void testCreateQualificationType() throws ServiceException {
  QualificationType qualType = service.createQualificationType(
      defaultQualificationName + unique, 
      null, // keywords
      defaultQualificationDescription
    );

  assertNotNull(qualType);  

  // set to inactive to cleanup
  try {
    service.disposeQualificationType(qualType.getQualificationTypeId());
  }
  catch (Exception ex) {
    // ignore since the test checks for creation of qualification type
  }
}
项目:java-aws-mturk    文件:TestBase.java   
protected QualificationType createQualificationType() throws ServiceException {
  QualificationType qualType = service.createQualificationType(
      defaultQualificationName + unique, 
      null, // keywords
      defaultQualificationDescription, QualificationTypeStatus.Active, (long) 0,
      null, // test
      null, // answerKey
      null, // testDurationInSeconds
      null, // autoGranted
      null // autoGrantedValue
    );

  assertNotNull(qualType);

  return qualType;
}
项目:java-aws-mturk    文件:TestRequesterServiceRaw.java   
public void testGetBlockedWorkers() throws ServiceException {
  GetBlockedWorkersResult result = service.getBlockedWorkers(1, 10);
  assertTrue(result.getPageNumber() + " is an invalid page number (expected page 1)",
      result.getPageNumber() != null && result.getPageNumber() == 1);
  assertTrue(result.getNumResults() + " is an invalid number of results per page (expected from 0 to 10)",
      result.getNumResults() != null && result.getNumResults() >= 0 && result.getNumResults() <= 10);
  assertTrue("Total result count " + result.getTotalNumResults()
      + " is smaller than this page's count " + result.getNumResults(),
      result.getTotalNumResults() != null && result.getTotalNumResults() >= result.getNumResults());
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_RegisterHITTypeOperation.html
 */ 
public String registerHITType(Long autoApprovalDelayInSeconds, Long assignmentDurationInSeconds,
    Double reward, String title, String keywords, String description,
    QualificationRequirement[] qualRequirements)
  throws ServiceException {

  RegisterHITTypeRequest request = new RegisterHITTypeRequest();
  if (title != null)        request.setTitle(title);
  if (description != null)  request.setDescription(description);
  if (keywords != null)     request.setKeywords(keywords);

  if (qualRequirements != null)           request.setQualificationRequirement(qualRequirements);
  if (assignmentDurationInSeconds != null)request.setAssignmentDurationInSeconds(assignmentDurationInSeconds);
  if (autoApprovalDelayInSeconds != null) request.setAutoApprovalDelayInSeconds(autoApprovalDelayInSeconds);

  if (reward != null) {
    Price p = new Price();
    p.setAmount(new BigDecimal(reward));
    p.setCurrencyCode("USD");
    request.setReward(p);
  }

  RegisterHITTypeResult result = null;
  result = (RegisterHITTypeResult) executeRequest(request, 
      ResultMatch.RegisterHITType.name(),
      ResultMatch.RegisterHITType.getResultTypeName());

  if (result == null) {
    throw new ServiceException("No response");
  }

  return result.getHITTypeId();
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-06-21/ApiReference_ChangeHITTypeOfHIT.html
 */
public void changeHITTypeOfHIT(String hitId, String newHitTypeId) 
throws ServiceException {

  ChangeHITTypeOfHITRequest request = new ChangeHITTypeOfHITRequest();
  request.setHITId(hitId);
  request.setHITTypeId(newHitTypeId);
  executeRequest(request,
      ResultMatch.ChangeHITTypeOfHIT.name(),
      ResultMatch.ChangeHITTypeOfHIT.getResultTypeName());
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_SetHITTypeNotificationOperation.html
 */ 
public void setHITTypeNotification(String hitTypeId, NotificationSpecification notification, Boolean active)
  throws ServiceException { 

  SetHITTypeNotificationRequest request = new SetHITTypeNotificationRequest();
  if (hitTypeId != null)    request.setHITTypeId(hitTypeId);
  if (notification != null) request.setNotification(notification);
  if (active != null)       request.setActive(active);

  executeRequest(request, ResultMatch.SetHITTypeNotification.name(),
      ResultMatch.SetHITTypeNotification.getResultTypeName());
}
项目:java-aws-mturk    文件:TestRequesterServiceRaw.java   
public void testAssignQualification() throws ServiceException {
  String qualTypeId = getTestQualificationTypeId();

  service.assignQualification(
      qualTypeId, // qualificationTypeId
      luckyWorker, // workerId
      50, // integerValue
      false // sendNotification
    );

}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_DisposeHITOperation.html
 */ 
public void disposeHIT(String hitId) throws ServiceException { 

  DisposeHITRequest request = new DisposeHITRequest();
  if (hitId != null)  request.setHITId(hitId);

  executeRequest(request, ResultMatch.DisposeHIT.name(),
      ResultMatch.DisposeHIT.getResultTypeName());
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_DisableHITOperation.html
 */ 
public void disableHIT(String hitId) throws ServiceException { 

  DisableHITRequest request = new DisableHITRequest();
  if (hitId != null)  request.setHITId(hitId);

  executeRequest(request, ResultMatch.DisableHIT.name(),
      ResultMatch.DisableHIT.getResultTypeName());
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_SetHITAsReviewingOperation.html
 */ 
public void setHITAsReviewing(String hitId, Boolean revert) 
  throws ServiceException { 

  SetHITAsReviewingRequest request = new SetHITAsReviewingRequest();
  if (hitId != null)  request.setHITId(hitId);
  if (revert != null) request.setRevert(revert);

  executeRequest(request, ResultMatch.SetHITAsReviewing.name(),
      ResultMatch.SetHITAsReviewing.getResultTypeName());
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_ApproveAssignmentOperation.html
 */ 
public void approveAssignment(String assignmentId, String requesterFeedback) 
  throws ServiceException { 

  ApproveAssignmentRequest request = new ApproveAssignmentRequest();
  if (assignmentId != null) request.setAssignmentId(assignmentId);

  if (requesterFeedback != null) {
    request.setRequesterFeedback(requesterFeedback);
  }

  executeRequest(request, ResultMatch.ApproveAssignment.name(),
      ResultMatch.ApproveAssignment.getResultTypeName());
}
项目:java-aws-mturk    文件:TestRequesterServiceRaw.java   
public void testNotifyWorkers() throws ServiceException { 

  // This test fails intermittently with AWS.ServiceUnavailable
  //     or with AWS.MechanicalTurk.InvalidTransportEndpoint
  // This appears to be a problem with the MTS API rather than the SDK

  service.notifyWorkers(BOGUS_STR, // subject 
      BOGUS_STR, // messageText
      new String[] { luckyWorker } // workerId
  );
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechTurk/2012-03-25/AWSMturkAPI/ApiReference_GetAssignmentOperation.html
 */
public GetAssignmentResult getAssignment(String assignmentId) {
  GetAssignmentRequest request = new GetAssignmentRequest();
  if (assignmentId != null) request.setAssignmentId(assignmentId);

  GetAssignmentResult result = (GetAssignmentResult) executeRequest(
      request, ResultMatch.GetAssignment.name(),
      ResultMatch.GetAssignment.getResultTypeName());

  if (result == null) {
    throw new ServiceException("No response");
  }
  return result; 
}
项目:java-aws-mturk    文件:TestRequesterService.java   
public void testDeleteQualificationType() throws ServiceException {
  String testQualTypeId = createQualificationType().getQualificationTypeId();
  QualificationType qualType = service.disposeQualificationType(testQualTypeId);
  QualificationTypeStatus qualTypeStatus = qualType.getQualificationTypeStatus();

  assertNotNull(qualType);
  assertNotNull(qualTypeStatus.equals(QualificationTypeStatus.Inactive));
}
项目:java-aws-mturk    文件:RequesterServiceRaw.java   
/**
 * @see http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2007-03-12/ApiReference_CreateQualificationTypeOperation.html
 */ 
public QualificationType createQualificationType(String name, String keywords, String description,
    QualificationTypeStatus status, Long retryDelayInSeconds, String test, String answerKey,
    Long testDurationInSeconds, Boolean autoGranted, Integer autoGrantedValue) 
  throws ServiceException { 

  CreateQualificationTypeRequest request = new CreateQualificationTypeRequest();
  if (name != null)                 request.setName(name);
  if (answerKey != null)            request.setAnswerKey(answerKey);
  if (autoGranted != null)          request.setAutoGranted(autoGranted);
  if (autoGrantedValue != null)     request.setAutoGrantedValue(autoGrantedValue);
  if (description != null)          request.setDescription(description);
  if (keywords != null)             request.setKeywords(keywords);
  if (status != null)               request.setQualificationTypeStatus(status);
  if (test != null)                 request.setTest(test);
  if (retryDelayInSeconds != null)  request.setRetryDelayInSeconds(retryDelayInSeconds);
  if (testDurationInSeconds != null)request.setTestDurationInSeconds(testDurationInSeconds);

  QualificationType result = null;

  result = (QualificationType) executeRequest(request, 
      ResultMatch.CreateQualificationType.name(),
      ResultMatch.CreateQualificationType.getResultTypeName());

  if (result == null) {
    throw new ServiceException("No response");
  }

  return result;
}
项目:java-aws-mturk    文件:TestRequesterServiceRaw.java   
public void testGetAssignment() throws ServiceException {
  try {
    service.getAssignment("INVALIDASSIGNMENTID");
    fail("getAssignment succeeded, despite not having a valid assignment ID");
  } catch (ServiceException e) {
    // expected
    assertContains("Cause of getAssignment failure wasn't an invalid assignment ID.",
        "AWS.MechanicalTurk.AssignmentDoesNotExist", e.getMessage());
  }
}