public QualificationRequirement[] getQualificationRequirements() { List<QualificationRequirement> quals = new ArrayList<QualificationRequirement>(); for (int i = 0; i < MAX_NUM_QUALIFICATIONS_SUPPORTED; i++) { if (qualificationType[i] != null && !qualificationType[i].equals("")) { // There's a qualification type here QualificationRequirement thisQual = new QualificationRequirement(getQualificationType(i), getQualificationComparator(i), getQualificationIntegerValue(i), getQualificationLocaleValue(i), getQualificationPrivate(i)); quals.add(thisQual); } } // Return the array of qualifications return quals.toArray(new QualificationRequirement[quals.size()]); }
/** * 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); }
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; }
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; }
/** * Backwards compatibility for programs that don't specify review policies */ public HIT createHIT(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) throws ServiceException { return createHIT(hitTypeId, title, description, keywords, question, reward, assignmentDurationInSeconds, autoApprovalDelayInSeconds, lifetimeInSeconds, maxAssignments, requesterAnnotation, qualificationRequirements, responseGroup, null, null, null); }
/** * @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(); }
/** * Creates the simple survey. * */ public void createSimpleSurvey() { try { // This is an example of creating a qualification. // This is a built-in qualification -- user must be based in the US QualificationRequirement qualReq = new QualificationRequirement(); qualReq.setQualificationTypeId(RequesterService.LOCALE_QUALIFICATION_TYPE_ID); qualReq.setComparator(Comparator.EqualTo); Locale country = new Locale(); country.setCountry("US"); qualReq.setLocaleValue(country); // The create HIT method takes in an array of QualificationRequirements // since a HIT can have multiple qualifications. QualificationRequirement[] qualReqs = null; qualReqs = new QualificationRequirement[] { qualReq }; // Loading the question (QAP) file. HITQuestion is a helper class that // contains the QAP of the HIT defined in the external file. This feature // allows you to write the entire QAP externally as a file and be able to // modify it without recompiling your code. HITQuestion question = new HITQuestion(questionFile); //Creating the HIT and loading it into Mechanical Turk HIT hit = service.createHIT(null, // HITTypeId title, description, keywords, question.getQuestion(), reward, assignmentDurationInSeconds, autoApprovalDelayInSeconds, lifetimeInSeconds, numAssignments, requesterAnnotation, qualReqs, null // responseGroup ); 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()); //Demonstrates how a HIT can be retrieved if you know its HIT ID HIT hit2 = service.getHIT(hit.getHITId()); System.out.println("Retrieved HIT: " + hit2.getHITId()); if (!hit.getHITId().equals(hit2.getHITId())) { System.err.println("The HIT Ids should match: " + hit.getHITId() + ", " + hit2.getHITId()); } } catch (Exception e) { System.err.println(e.getLocalizedMessage()); } }