Ejemplo n.º 1
0
 private void doExecuteWorkflow(VitroRequest vreq) {
   String workflowURI = vreq.getParameter("workflowURI");
   String workflowStepURI = vreq.getParameter("workflowStepURI");
   OntModel jenaOntModel = (OntModel) getModel("vitro:jenaOntModel", vreq);
   new JenaIngestWorkflowProcessor(jenaOntModel.getIndividual(workflowURI), getModelMaker(vreq))
       .run(jenaOntModel.getIndividual(workflowStepURI));
 }
Ejemplo n.º 2
0
  private void processCreateModelRequest(
      VitroRequest vreq, ModelMaker maker, WhichService modelType) {
    String modelName = vreq.getParameter("modelName");

    if (modelName != null) {
      try {
        URI graphURI = new URI(modelName);

        if (graphURI.getScheme() == null) {
          String origName = modelName;
          modelName = CREATED_GRAPH_BASE_URI + modelName;
          log.info("The model name has been changed from " + origName + " to " + modelName);
        }

        doCreateModel(modelName, maker);
        showModelList(vreq, maker, modelType);
      } catch (URISyntaxException e) {
        throw new RuntimeException("the model name must be a valid URI");
      }
    } else {
      vreq.setAttribute("modelType", modelType.toString());
      vreq.setAttribute("title", "Create New Model");
      vreq.setAttribute("bodyJsp", CREATE_MODEL_JSP);
    }
  }
Ejemplo n.º 3
0
 private void processRenameBNodesURISelectRequest(VitroRequest vreq, ModelMaker maker) {
   String namespaceEtcStr = vreq.getParameter("namespaceEtcStr");
   String pattern = vreq.getParameter("pattern");
   String concatenate = vreq.getParameter("concatenate");
   String[] sourceModel = vreq.getParameterValues("sourceModelName");
   if (namespaceEtcStr != null) {
     if (namespaceEtcStr.isEmpty()) {
       if ("true".equals(vreq.getParameter("csv2rdf"))) {
         processCsv2rdfRequest(vreq);
         return;
       } else {
         vreq.setAttribute("errorMsg", "Please enter a value.");
         processRenameBNodesRequest(vreq, maker);
         return;
       }
     }
     if (concatenate.equals("integer")) {
       doRenameBNodes(vreq, namespaceEtcStr, false, null, sourceModel);
     } else {
       pattern = pattern.trim();
       doRenameBNodes(vreq, namespaceEtcStr, true, pattern, sourceModel);
     }
     vreq.setAttribute("title", "Ingest Menu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "URI Select");
     vreq.setAttribute("bodyJsp", RENAME_BNODES_URI_SELECT_JSP);
   }
 }
Ejemplo n.º 4
0
 private void processCleanLiteralsRequest(VitroRequest vreq) {
   String modelNameStr = vreq.getParameter("modelName");
   Model model = getModel(modelNameStr, vreq);
   doCleanLiterals(model);
   vreq.setAttribute("title", "Ingest Menu");
   vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
 }
 public AbstractAjaxResponder(HttpServlet servlet, VitroRequest vreq, HttpServletResponse resp) {
   this.servlet = servlet;
   this.vreq = vreq;
   this.resp = resp;
   this.indDao = vreq.getWebappDaoFactory().getIndividualDao();
   this.uaDao = vreq.getWebappDaoFactory().getUserAccountsDao();
 }
Ejemplo n.º 6
0
 private void processOutputModelRequest(VitroRequest vreq, HttpServletResponse response) {
   String modelNameStr = vreq.getParameter("modelName");
   Model model = getModel(modelNameStr, vreq);
   JenaOutputUtils.setNameSpacePrefixes(model, vreq.getWebappDaoFactory());
   model.enterCriticalSection(Lock.READ);
   try {
     OutputStream out = response.getOutputStream();
     response.setContentType("application/x-turtle");
     // out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".getBytes());
     model.write(out, "TTL");
     out.flush();
     out.close();
   } catch (com.hp.hpl.jena.shared.CannotEncodeCharacterException cece) {
     // there's got to be a better way to do this
     byte[] badCharBytes = String.valueOf(cece.getBadChar()).getBytes();
     String errorMsg = "Cannot encode character with byte values: (decimal) ";
     for (int i = 0; i < badCharBytes.length; i++) {
       errorMsg += badCharBytes[i];
     }
     throw new RuntimeException(errorMsg, cece);
   } catch (Exception e) {
     log.error(e, e);
   } finally {
     model.leaveCriticalSection();
   }
 }
  // Prepare for update or non-update
  // Originally included in edit request dispatch controller but moved here due to
  // exceptions such as default add missing individual form
  void prepare(VitroRequest vreq, EditConfigurationVTwo editConfig) {
    // setup the model selectors for query, write and display models on editConfig
    setupModelSelectorsFromVitroRequest(vreq, editConfig);

    OntModel queryModel = vreq.getJenaOntModel(); // (OntModel)vreq.getAttribute("jenaOntModel");

    if (editConfig.getSubjectUri() == null)
      editConfig.setSubjectUri(EditConfigurationUtils.getSubjectUri(vreq));
    if (editConfig.getPredicateUri() == null)
      editConfig.setPredicateUri(EditConfigurationUtils.getPredicateUri(vreq));

    String objectUri = EditConfigurationUtils.getObjectUri(vreq);
    Integer dataKey = EditConfigurationUtils.getDataHash(vreq);
    if (objectUri != null && !objectUri.trim().isEmpty()) {
      // editing existing object
      if (editConfig.getObject() == null)
        editConfig.setObject(EditConfigurationUtils.getObjectUri(vreq));
      editConfig.prepareForObjPropUpdate(queryModel);
    } else if (dataKey != null) { // edit of a data prop statement
      // do nothing since the data prop form generator must take care of it
      editConfig.prepareForDataPropUpdate(
          queryModel, vreq.getWebappDaoFactory().getDataPropertyDao());
    } else {
      // this might be a create new or a form
      editConfig.prepareForNonUpdate(queryModel);
    }
  }
 /**
  * We are just starting the upload process. Record where we came from, so if they hit "cancel" we
  * know where to send them. If we have problems, just clear it.
  */
 private void captureReferringUrl(VitroRequest vreq) {
   String referrer = vreq.getHeader("Referer");
   if (referrer == null) {
     vreq.getSession().removeAttribute(ATTRIBUTE_REFERRING_PAGE);
   } else {
     vreq.getSession().setAttribute(ATTRIBUTE_REFERRING_PAGE, referrer);
   }
 }
  @Override
  protected ResponseValues processRequest(VitroRequest vreq) {
    // get the EditConfiguration
    EditConfigurationVTwo configuration = EditConfigurationUtils.getEditConfiguration(vreq);
    if (configuration == null) throw new Error("No edit configuration found.");

    // get the EditSubmission
    MultiValueEditSubmission submission =
        new MultiValueEditSubmission(vreq.getParameterMap(), configuration);
    EditSubmissionUtils.putEditSubmissionInSession(vreq.getSession(), submission);

    // if errors, return error response
    ResponseValues errorResponse = doValidationErrors(vreq, configuration, submission);
    if (errorResponse != null) return errorResponse;

    // get the models to work with in case the write model and query model are not the defaults
    OntModel queryModel = configuration.getQueryModelSelector().getModel(vreq, getServletContext());
    OntModel writeModel = configuration.getWriteModelSelector().getModel(vreq, getServletContext());

    // If data property check for back button confusion
    boolean isBackButton = checkForBackButtonConfusion(configuration, vreq, queryModel);
    if (isBackButton) {
      // Process back button issues and do a return here
      return doProcessBackButton(configuration, submission, vreq);
    }

    // Otherwise, process as usual

    AdditionsAndRetractions changes;
    try {

      ProcessRdfForm prf =
          new ProcessRdfForm(configuration, new NewURIMakerVitro(vreq.getWebappDaoFactory()));
      changes = prf.process(configuration, submission);

    } catch (Exception e) {
      throw new Error(e);
    }

    if (configuration.isUseDependentResourceDelete())
      changes = ProcessRdfForm.addDependentDeletes(changes, queryModel);

    N3EditUtils.preprocessModels(changes, configuration, vreq);

    ProcessRdfForm.applyChangesToWriteModel(
        changes, queryModel, writeModel, EditN3Utils.getEditorUri(vreq));

    // Here we are trying to get the entity to return to URL,
    // More involved processing for data property apparently
    String entityToReturnTo = N3EditUtils.processEntityToReturnTo(configuration, submission, vreq);

    // For data property processing, need to update edit configuration for back button
    N3EditUtils.updateEditConfigurationForBackButton(configuration, submission, vreq, writeModel);
    PostEditCleanupController.doPostEditCleanup(vreq);
    return PostEditCleanupController.doPostEditRedirect(vreq, entityToReturnTo);
  }
Ejemplo n.º 10
0
 private long doExecuteSparql(VitroRequest vreq) {
   OntModel jenaOntModel = ModelAccess.on(getServletContext()).getOntModel();
   OntModel source = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
   String[] sourceModel = vreq.getParameterValues("sourceModelName");
   for (int i = 0; i < sourceModel.length; i++) {
     Model m = getModel(sourceModel[i], vreq);
     source.addSubModel(m);
   }
   Model destination = getModel(vreq.getParameter("destinationModelName"), vreq);
   String sparqlQueryStr = vreq.getParameter("sparqlQueryStr");
   String savedQueryURIStr = vreq.getParameter("savedQuery");
   String queryStr;
   if (savedQueryURIStr.length() == 0) {
     log.debug("Using entered query");
     queryStr = sparqlQueryStr;
   } else {
     Property queryStrProp = ResourceFactory.createProperty(SPARQL_QUERYSTR_PROP);
     jenaOntModel.enterCriticalSection(Lock.READ);
     try {
       Individual ind = jenaOntModel.getIndividual(savedQueryURIStr);
       log.debug("Using query " + savedQueryURIStr);
       queryStr = ((Literal) ind.getPropertyValue(queryStrProp)).getLexicalForm();
       queryStr =
           StringEscapeUtils.unescapeHtml(
               queryStr); // !!! We need to turn off automatic HTML-escaping for data property
                          // editing.
     } finally {
       jenaOntModel.leaveCriticalSection();
     }
   }
   Model tempModel = ModelFactory.createDefaultModel();
   Query query = SparqlQueryUtils.create(queryStr);
   QueryExecution qexec = QueryExecutionFactory.create(query, source);
   try {
     qexec.execConstruct(tempModel);
   } catch (QueryExecException qee) {
     qexec.execDescribe(tempModel);
   }
   destination.enterCriticalSection(Lock.WRITE);
   try {
     if (destination instanceof OntModel) {
       ((OntModel) destination).getBaseModel().notifyEvent(new EditEvent(null, true));
     } else {
       destination.notifyEvent(new EditEvent(null, true));
     }
     destination.add(tempModel);
   } finally {
     if (destination instanceof OntModel) {
       ((OntModel) destination).getBaseModel().notifyEvent(new EditEvent(null, false));
     } else {
       destination.notifyEvent(new EditEvent(null, false));
     }
     destination.leaveCriticalSection();
   }
   return tempModel.size();
 }
Ejemplo n.º 11
0
 public void doSubtractModels(VitroRequest vreq) {
   String modela = vreq.getParameter("modela");
   String modelb = vreq.getParameter("modelb");
   String destination = vreq.getParameter("destinationModelName");
   Model ma = getModel(modela, vreq);
   Model mb = getModel(modelb, vreq);
   Model destinationModel = getModel(destination, vreq);
   if (!destination.equals(modela)) destinationModel.add(ma.difference(mb));
   else ma.remove(mb);
 }
Ejemplo n.º 12
0
 private void processExecuteWorkflowRequest(VitroRequest vreq) {
   String workflowURIStr = vreq.getParameter("workflowURI");
   String workflowStepURIStr = vreq.getParameter("workflowStepURI");
   if (workflowURIStr != null && workflowStepURIStr != null) {
     doExecuteWorkflow(vreq);
     vreq.setAttribute("title", "IngestMenu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else if (workflowURIStr != null) {
     // Select the workflow step at which to start
     OntModel jenaOntModel = (OntModel) getModel("vitro:jenaOntModel", vreq);
     vreq.setAttribute(
         "workflowSteps",
         new JenaIngestWorkflowProcessor(
                 jenaOntModel.getIndividual(workflowURIStr), getModelMaker(vreq))
             .getWorkflowSteps(null));
     vreq.setAttribute("title", "Choose Workflow Step");
     vreq.setAttribute("bodyJsp", WORKFLOW_STEP_JSP);
   } else {
     OntModel jenaOntModel = ModelAccess.on(getServletContext()).getOntModel();
     jenaOntModel.enterCriticalSection(Lock.READ);
     List<Individual> savedQueryList = new LinkedList<Individual>();
     try {
       Resource workflowClassRes = WorkflowOntology.Workflow;
       savedQueryList.addAll(jenaOntModel.listIndividuals(workflowClassRes).toList());
     } finally {
       jenaOntModel.leaveCriticalSection();
     }
     vreq.setAttribute("workflows", savedQueryList);
     vreq.setAttribute("title", "Execute Workflow");
     vreq.setAttribute("bodyJsp", EXECUTE_WORKFLOW_JSP);
   }
 }
Ejemplo n.º 13
0
 protected void setRequestAttributes(HttpServletRequest request, EditProcessObject epo) {
   VitroRequest vreq = new VitroRequest(request);
   request.setAttribute("epoKey", epo.getKey());
   request.setAttribute("epo", epo);
   request.setAttribute("globalErrorMsg", epo.getAttribute("globalErrorMsg"));
   request.setAttribute(
       "css",
       "<link rel=\"stylesheet\" type=\"text/css\" href=\""
           + vreq.getAppBean().getThemeDir()
           + "css/edit.css\"/>");
 }
Ejemplo n.º 14
0
  @Override
  protected void doRequest(VitroRequest vreq, HttpServletResponse response) {

    String errorMsg = null;
    String rankPredicate = vreq.getParameter(RANK_PREDICATE_PARAMETER_NAME);
    if (rankPredicate == null) {
      errorMsg = "No rank parameter specified";
      log.error(errorMsg);
      doError(response, errorMsg, HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    String[] individualUris = vreq.getParameterValues(INDIVIDUAL_PREDICATE_PARAMETER_NAME);
    if (individualUris == null || individualUris.length == 0) {
      errorMsg = "No individuals specified";
      log.error(errorMsg);
      doError(response, errorMsg, HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    WebappDaoFactory wadf = vreq.getWebappDaoFactory();
    if (vreq.getWebappDaoFactory() == null) {
      errorMsg = "No WebappDaoFactory available";
      log.error(errorMsg);
      doError(response, errorMsg, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    DataPropertyStatementDao dpsDao = wadf.getDataPropertyStatementDao();
    if (dpsDao == null) {
      errorMsg = "No DataPropertyStatementDao available";
      log.error(errorMsg);
      doError(response, errorMsg, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    // check permissions
    // TODO: (bdc34)This is not yet implemented, must check the IDs against the policies for
    // permissons before doing an edit!
    // rjy7 This should be inherited from the superclass
    boolean hasPermission = true;
    if (!hasPermission) {
      // if not okay, send error message
      doError(response, "Insufficent permissions", HttpStatus.SC_UNAUTHORIZED);
      return;
    }

    // This may not be the most efficient way. Should we instead build up a Model of retractions and
    // additions, so
    // we only hit the database once?
    reorderIndividuals(individualUris, vreq, rankPredicate);

    response.setStatus(HttpServletResponse.SC_OK);
  }
Ejemplo n.º 15
0
 private void processGenerateTBoxRequest(VitroRequest vreq) {
   String testParam = vreq.getParameter("sourceModelName");
   if (testParam != null) {
     doGenerateTBox(vreq);
     vreq.setAttribute("title", "Ingest Menu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Generate TBox from Assertions Data");
     vreq.setAttribute("bodyJsp", GENERATE_TBOX_JSP);
   }
 }
Ejemplo n.º 16
0
 public void doGenerateTBox(VitroRequest vreq) {
   OntModel source = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
   String[] sourceModel = vreq.getParameterValues("sourceModelName");
   for (int i = 0; i < sourceModel.length; i++) {
     Model m = getModel(sourceModel[i], vreq);
     source.addSubModel(m);
   }
   String destinationModelStr = vreq.getParameter("destinationModelName");
   Model destination = getModel(destinationModelStr, vreq);
   destination.add((new JenaIngestUtils()).generateTBox(source));
 }
Ejemplo n.º 17
0
 private void processSubtractModelRequest(VitroRequest vreq) {
   String modela = vreq.getParameter("modela");
   if (modela != null) {
     doSubtractModels(vreq);
     vreq.setAttribute("title", "IngestMenu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Subtract Models");
     vreq.setAttribute("bodyJsp", SUBTRACT_MODELS_JSP);
   }
 }
Ejemplo n.º 18
0
 private void processProcessStringsRequest(VitroRequest vreq) {
   String className = vreq.getParameter("className");
   if (className != null) {
     doProcessStrings(vreq);
     vreq.setAttribute("title", "IngestMenu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Process Strings");
     vreq.setAttribute("bodyJsp", PROCESS_STRINGS_JSP);
   }
 }
Ejemplo n.º 19
0
 private void processSplitPropertyValuesRequest(VitroRequest vreq) {
   String splitRegex = vreq.getParameter("splitRegex");
   if (splitRegex != null) {
     doSplitPropertyValues(vreq);
     vreq.setAttribute("title", "IngestMenu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Split PropertyValues");
     vreq.setAttribute("bodyJsp", SPLIT_PROPERTY_VALUES_JSP);
   }
 }
Ejemplo n.º 20
0
 private void processCsv2rdfRequest(VitroRequest vreq) {
   String csvUrl = vreq.getParameter("csvUrl");
   if (csvUrl != null) {
     /*doExecuteCsv2Rdf(vreq);*/
     vreq.setAttribute("title", "IngestMenu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Convert CSV to RDF");
     vreq.setAttribute("bodyJsp", CSV2RDF_JSP);
   }
 }
Ejemplo n.º 21
0
 private void processSmushSingleModelRequest(VitroRequest vreq) {
   String propertyURIStr = vreq.getParameter("propertyURI");
   if (propertyURIStr != null) {
     doSmushSingleModel(vreq);
     vreq.setAttribute("title", "Ingest Menu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Smush Resources");
     vreq.setAttribute("bodyJsp", SMUSH_JSP);
   }
 }
  @Override
  public Map<String, String> generateDataVisualization(
      VitroRequest vitroRequest, Log log, Dataset dataset)
      throws MalformedQueryParametersException {

    String egoURI = vitroRequest.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY);
    String visMode = vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY);

    ModelConstructor constructQueryRunner =
        new CoPIGrantCountConstructQueryRunner(egoURI, dataset, log);
    Model constructedModel = constructQueryRunner.getConstructedModel();

    QueryRunner<CollaborationData> queryManager =
        new CoPIGrantCountQueryRunner(egoURI, constructedModel, log);

    CollaborationData investigatorNodesAndEdges = queryManager.getQueryResult();

    /*
     * We will be using the same visualization package for both sparkline & co-pi
     * flash vis. We will use "VIS_MODE_KEY" as a modifier to differentiate
     * between these two. The default will be to render the co-pi network vis.
     * */
    if (VisualizationFrameworkConstants.COPIS_COUNT_PER_YEAR_VIS_MODE.equalsIgnoreCase(visMode)) {
      /*
       * When the csv file is required - based on which sparkline visualization will
       * be rendered.
       * */
      return prepareCoPIsCountPerYearDataResponse(investigatorNodesAndEdges);

    } else if (VisualizationFrameworkConstants.COPIS_LIST_VIS_MODE.equalsIgnoreCase(visMode)) {
      /*
       * When the csv file is required - based on which sparkline visualization will
       * be rendered.
       * */
      return prepareCoPIsListDataResponse(investigatorNodesAndEdges);

    } else if (VisualizationFrameworkConstants.COPI_NETWORK_DOWNLOAD_VIS_MODE.equalsIgnoreCase(
        visMode)) {
      /*
       * When the csv file is required - based on which sparkline visualization will
       * be rendered.
       * */
      return prepareNetworkDownloadDataResponse(investigatorNodesAndEdges);

    } else {
      /*
       * When the graphML file is required - based on which co-pi network
       * visualization will be rendered.
       * */
      return prepareNetworkStreamDataResponse(investigatorNodesAndEdges);
    }
  }
Ejemplo n.º 23
0
 private void processRenameResourceRequest(VitroRequest vreq) {
   String oldNamespace = vreq.getParameter("oldNamespace");
   String newNamespace = vreq.getParameter("newNamespace");
   String errorMsg = "";
   if (oldNamespace != null) {
     if (oldNamespace.isEmpty() && !newNamespace.isEmpty()) {
       errorMsg = "Please enter the old namespace to be changed.";
     } else if (!oldNamespace.isEmpty() && newNamespace.isEmpty()) {
       errorMsg = "Please enter the new namespace.";
     } else if (oldNamespace.isEmpty() && newNamespace.isEmpty()) {
       errorMsg = "Please enter the namespaces.";
     } else if (oldNamespace.equals(newNamespace)) {
       errorMsg = "Please enter two different namespaces.";
     }
     if (!errorMsg.isEmpty()) {
       vreq.setAttribute("errorMsg", errorMsg);
       vreq.setAttribute("oldNamespace", oldNamespace);
       vreq.setAttribute("newNamespace", newNamespace);
       vreq.setAttribute("title", "Rename Resource");
       vreq.setAttribute("bodyJsp", RENAME_RESOURCE);
     } else {
       String result = doRename(oldNamespace, newNamespace);
       vreq.setAttribute("result", result);
       vreq.setAttribute("title", "Rename Resources");
       vreq.setAttribute("bodyJsp", RENAME_RESULT);
     }
   } else {
     vreq.setAttribute("title", "Rename Resource");
     vreq.setAttribute("bodyJsp", RENAME_RESOURCE);
   }
 }
  /** We need to be talking about an actual Individual here. */
  private Individual validateEntityUri(VitroRequest vreq) throws UserMistakeException {
    String entityUri = vreq.getParameter(PARAMETER_ENTITY_URI);
    if (entityUri == null) {
      throw new UserMistakeException("No entity URI was provided");
    }

    Individual entity =
        vreq.getFullWebappDaoFactory().getIndividualDao().getIndividualByURI(entityUri);
    if (entity == null) {
      throw new UserMistakeException(
          "This URI is not recognized as belonging to anyone: '" + entityUri + "'");
    }
    return entity;
  }
Ejemplo n.º 25
0
 /** Get the model type from the request, or from the session. */
 protected WhichService getModelType(VitroRequest vreq) {
   String modelType = vreq.getParameter("modelType");
   if (modelType != null) {
     if (modelType.equals(CONFIGURATION.toString())) {
       return CONFIGURATION;
     } else {
       return CONTENT;
     }
   }
   if (vreq.getSession().getAttribute(WHICH_MODEL_MAKER) == CONFIGURATION) {
     return CONFIGURATION;
   } else {
     return CONTENT;
   }
 }
  /**
   * Handle the different actions. If not specified, the default action is to show the intro screen.
   */
  private ResponseValues buildTheResponse(VitroRequest vreq) {
    String action = vreq.getParameter(PARAMETER_ACTION);

    try {
      Individual entity = validateEntityUri(vreq);
      if (ACTION_UPLOAD.equals(action)) {
        return doUploadImage(vreq, entity);
      } else if (ACTION_SAVE.equals(action)) {
        return doCreateThumbnail(vreq, entity);
      } else if (ACTION_DELETE.equals(action)) {
        captureReferringUrl(vreq);
        return doDeleteImage(vreq, entity);
      } else if (ACTION_DELETE_EDIT.equals(action)) {
        return doDeleteThenEdit(vreq, entity);
      } else {
        captureReferringUrl(vreq);
        return doIntroScreen(vreq, entity);
      }
    } catch (UserMistakeException e) {
      // Can't find the entity? Complain.
      return showAddImagePageWithError(vreq, null, e.getMessage());
    } catch (Exception e) {
      // We weren't expecting this - log it, and apologize to the user.
      return new ExceptionResponseValues(e);
    }
  }
Ejemplo n.º 27
0
  public List<Option> getSortedList(
      HashMap<String, Option> hashMap, List<Option> optionList, VitroRequest vreq) {

    class ListComparator implements Comparator<String> {

      Collator collator;

      public ListComparator(Collator collator) {
        this.collator = collator;
      }

      @Override
      public int compare(String str1, String str2) {
        return collator.compare(str1, str2);
      }
    }

    List<String> bodyVal = new ArrayList<String>();
    List<Option> options = new ArrayList<Option>();
    Iterator<Option> itr = optionList.iterator();
    while (itr.hasNext()) {
      Option option = itr.next();
      hashMap.put(option.getBody(), option);
      bodyVal.add(option.getBody());
    }

    Collections.sort(bodyVal, new ListComparator(vreq.getCollator()));
    ListIterator<String> itrStr = bodyVal.listIterator();
    while (itrStr.hasNext()) {
      options.add(hashMap.get(itrStr.next()));
    }
    return options;
  }
Ejemplo n.º 28
0
  @Override
  protected void doRequest(VitroRequest vreq, HttpServletResponse resp)
      throws ServletException, IOException {
    DeveloperSettings settings = DeveloperSettings.getBean(vreq);

    /*
     * Are they allowed to control the panel?
     */
    if (isAuthorized(vreq)) {
      // Update the settings.
      settings.updateFromRequest(vreq.getParameterMap());
    } else {
      log.debug("Not authorized to update settings.");
    }

    /*
     * Build the response.
     */
    try {
      Map<String, Object> bodyMap = buildBodyMap(isAuthorized(vreq), settings);
      String rendered = renderTemplate(vreq, bodyMap);
      resp.getWriter().write(rendered);
    } catch (Exception e) {
      doError(resp, e.toString(), 500);
    }
  }
Ejemplo n.º 29
0
 private void processDetachModelRequest(
     VitroRequest vreq, ModelMaker maker, WhichService modelType) {
   String modelName = vreq.getParameter("modelName");
   if (modelName != null) {
     doDetachModel(modelName);
   }
   showModelList(vreq, maker, modelType);
 }
  /** Delete the main image and the thumbnail, and go to the "add image" screen. */
  private ResponseValues doDeleteThenEdit(VitroRequest vreq, Individual entity) {
    ImageUploadHelper helper =
        new ImageUploadHelper(fileStorage, vreq.getFullWebappDaoFactory(), getServletContext());

    helper.removeExistingImage(entity);

    return showAddImagePage(vreq, entity);
  }