/** * Creates a HIT asynchronously using the Axis worker thread pool. * It returns an AsyncReply object, which can either be used to * wait for the asynchronous call to complete and to get the result * of the call. Alternatively, a callback handler can be passed * that is notified when the call has completed. * * The work queue is using a pool of daemon threads to process the submitted tasks. * To guarantee that all work submitted to the queue was processed before the JVM * exits, this requires to wait for all future results of the submitted work items. * This can conveniently be done using the getResult() method of the AsyncReply * object returned by this method. A typical usage pattern would be to first submit * all requests to the work queue, store the AsyncReply objects in an array and then * call getResult() for each of the objects in the array. * * @throws ServiceException */ public AsyncReply createHITAsync(String hitTypeId, String title, String description, String keywords, String question, Double reward, Long assignmentDurationInSeconds, Long autoApprovalDelayInSeconds, Long lifetimeInSeconds, Integer maxAssignments, String requesterAnnotation, QualificationRequirement[] qualificationRequirements, String[] responseGroup, String uniqueRequestToken, ReviewPolicy assignmentReviewPolicy, ReviewPolicy hitReviewPolicy, AsyncCallback callback) { CreateHITRequest request = wrapHITParams(hitTypeId, title, description, keywords, question, reward, assignmentDurationInSeconds, autoApprovalDelayInSeconds, lifetimeInSeconds, maxAssignments, requesterAnnotation, qualificationRequirements, responseGroup, uniqueRequestToken, assignmentReviewPolicy, hitReviewPolicy, null, null); return executeAsyncRequest(request, ResultMatch.CreateHIT.name(), ResultMatch.CreateHIT.getResultTypeName(), callback); }
/** * Support for creating HITs using HIT layouts * @see http://docs.amazonwebservices.com/AWSMechTurk/2012-03-25/AWSMturkAPI/ApiReference_HITLayoutArticle.html */ public AsyncReply createHITAsync(String hitTypeId, String title, String description, String keywords, Double reward, Long assignmentDurationInSeconds, Long autoApprovalDelayInSeconds, Long lifetimeInSeconds, Integer maxAssignments, String requesterAnnotation, QualificationRequirement[] qualificationRequirements, String[] responseGroup, String uniqueRequestToken, ReviewPolicy assignmentReviewPolicy, ReviewPolicy hitReviewPolicy, String hitLayoutId, HITLayoutParameter[] hitLayoutParameters, AsyncCallback callback) { CreateHITRequest request = wrapHITParams(hitTypeId, title, description, keywords, null, reward, assignmentDurationInSeconds, autoApprovalDelayInSeconds, lifetimeInSeconds, maxAssignments, requesterAnnotation, qualificationRequirements, responseGroup, uniqueRequestToken, assignmentReviewPolicy, hitReviewPolicy, hitLayoutId, hitLayoutParameters); return executeAsyncRequest(request, ResultMatch.CreateHIT.name(), ResultMatch.CreateHIT.getResultTypeName(), callback); }
private CreateHITRequest wrapHITParams(String hitTypeId, String title, String description, String keywords, String question, Double reward, Long assignmentDurationInSeconds, Long autoApprovalDelayInSeconds, Long lifetimeInSeconds, Integer maxAssignments, String requesterAnnotation, QualificationRequirement[] qualificationRequirements, String[] responseGroup, String uniqueRequestToken, ReviewPolicy assignmentReviewPolicy, ReviewPolicy hitReviewPolicy, String hitLayoutId, HITLayoutParameter[] hitLayoutParameters) { CreateHITRequest request = new CreateHITRequest(); if (question != null) request.setQuestion(question); if (lifetimeInSeconds != null)request.setLifetimeInSeconds(lifetimeInSeconds); if (hitTypeId != null) request.setHITTypeId(hitTypeId); if (title != null) request.setTitle(title); if (description != null) request.setDescription(description); if (keywords != null) request.setKeywords(keywords); if (maxAssignments != null) request.setMaxAssignments(maxAssignments); if (responseGroup != null) request.setResponseGroup(responseGroup); if (hitReviewPolicy != null) request.setHITReviewPolicy(hitReviewPolicy); if (hitLayoutId != null) request.setHITLayoutId(hitLayoutId); if (requesterAnnotation != null) request.setRequesterAnnotation(requesterAnnotation); if (assignmentDurationInSeconds != null)request.setAssignmentDurationInSeconds(assignmentDurationInSeconds); if (autoApprovalDelayInSeconds != null) request.setAutoApprovalDelayInSeconds(autoApprovalDelayInSeconds); if (qualificationRequirements != null) request.setQualificationRequirement(qualificationRequirements); if (assignmentReviewPolicy != null) request.setAssignmentReviewPolicy(assignmentReviewPolicy); if (uniqueRequestToken != null) request.setUniqueRequestToken(uniqueRequestToken); if (hitLayoutParameters != null) request.setHITLayoutParameter(hitLayoutParameters); if (reward != null) { Price p = new Price(); p.setAmount(new BigDecimal(reward)); p.setCurrencyCode("USD"); request.setReward(p); } return request; }
public void testCreateHITWithInvalidReviewPolicy() throws ServiceException { // create a SKA policy that is missing required parameter AnswerKey ReviewPolicy assignmentReviewPolicy = new ReviewPolicy("ScoreMyKnownAnswers/2011-09-01", new PolicyParameter[] {}); try { service.createHIT( null, // hitTypeId defaultHITTitle + unique, defaultHITDescription, null, // keywords RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultReward, defaultAssignmentDurationInSeconds, defaultAutoApprovalDelayInSeconds, defaultLifetimeInSeconds, defaultMaxAssignments, null, // requesterAnnotation null, // qualificationRequirements null, // responseGroup null, // uniqueRequestToken assignmentReviewPolicy, null); // hitReviewPolicy fail("createHIT succeeded, despite having an invalid review policy"); } catch (ServiceException e) { // expected assertTrue("createHIT failed, but not because of an invalid review policy", e.getMessage().contains("The AnswerKey parameter is mandatory.")); } }
public void testCreateHITWithReviewPolicy() throws ServiceException { /* Create some review policies. * The policy details are nonsense and are not asserted on -- this test * just verifies that (1) the act of plugging in a review policy does not * cause createHIT to blow up, and that (2) said review policies appear in * the HIT's review results. */ PolicyParameter[] skaParams = { new PolicyParameter("AnswerKey", null, new ParameterMapEntry[] { new ParameterMapEntry("1", new String[] {"correct answer"}) }) }; ReviewPolicy assignmentReviewPolicy = new ReviewPolicy("ScoreMyKnownAnswers/2011-09-01", skaParams); PolicyParameter[] phrParams = { new PolicyParameter("QuestionIds", new String[] {"1"}, null), new PolicyParameter("QuestionAgreementThreshold", new String[] {"50"}, null), }; ReviewPolicy hitReviewPolicy = new ReviewPolicy("SimplePlurality/2011-09-01", phrParams); // Create the HIT with review policies HIT hit = service.createHIT( null, // hitTypeId defaultHITTitle + unique, defaultHITDescription, null, // keywords RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultReward, defaultAssignmentDurationInSeconds, defaultAutoApprovalDelayInSeconds, defaultLifetimeInSeconds, defaultMaxAssignments, null, // requesterAnnotation null, // qualificationRequirements null, // responseGroup null, // uniqueRequestToken assignmentReviewPolicy, hitReviewPolicy); // Make sure the policies were actually added to the created HIT GetReviewResultsForHITResult results = service.getReviewResultsForHIT( hit.getHITId(), new ReviewPolicyLevel[] {ReviewPolicyLevel.Assignment, ReviewPolicyLevel.HIT}, true, // retrieveActions true, // retrieveResults 1, // pageNumber 1000, // pageSize null); // responseGroup assertEquals("Unexpected assignment policy", results.getAssignmentReviewPolicy().getPolicyName(), "ScoreMyKnownAnswers/2011-09-01"); assertEquals("Unexpected HIT policy", results.getHITReviewPolicy().getPolicyName(), "SimplePlurality/2011-09-01"); }