/**
  * Creates an integration datum for the current user.
  *
  * @param userDetails information about the authenticated user.
  * @return the integration datum.
  */
 private IntegrationDatum createIntegrationDatum(UserDetails userDetails) {
   IntegrationDatum integrationDatum = new IntegrationDatum();
   integrationDatum.setIntegratorEmail(userDetails.getEmail());
   integrationDatum.setIntegratorName(
       userDetails.getFirstName() + " " + userDetails.getLastName());
   return integrationDatum;
 }
 /**
  * Verifies that the user owns the analysis that is being edited.
  *
  * @param analysis the analysis.
  * @param userDetails details about the authenticated user.
  * @throws AnalysisOwnershipException if the user does not own the analysis.
  */
 private void verifyUserOwnership(TransformationActivity analysis, UserDetails userDetails) {
   String integratorEmail = analysis.getIntegrationDatum().getIntegratorEmail();
   String authenticatedEmail = userDetails.getEmail();
   if (!StringUtils.equals(integratorEmail, authenticatedEmail)) {
     throw new AnalysisOwnershipException(userDetails.getShortUsername(), analysis.getId());
   }
 }
 /**
  * Converts the app to a copy for the given analysis identifier and user info.
  *
  * @param analysis the app to convert.
  * @param userDetails information about the current user.
  * @return the app as a copy.
  */
 private JSONObject convertAnalysisToCopy(
     JSONObject analysis, String newId, UserDetails userDetails) {
   TitoIntegrationDatumMashaller marshaller = new TitoIntegrationDatumMashaller();
   try {
     analysis.put("id", newId);
     analysis.put("tito", newId);
     analysis.put("name", "Copy of " + analysis.getString("name"));
     analysis.put("implementation", marshaller.toJson(createIntegrationDatum(userDetails)));
     analysis.put("user", userDetails.getShortUsername());
     analysis.put("full_username", userDetails.getUsername());
   } catch (JSONException e) {
     throw new WorkflowException("unable to convert analysis", e);
   }
   return analysis;
 }