@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); }
private Object getApplicationName() { String name = ""; try { WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory(); ApplicationBean app = wadf.getApplicationDao().getApplicationBean(); name = app.getApplicationName(); } catch (Exception e) { // deal with problems below } if ((name != null) && (!name.isEmpty())) { return name; } else { return getContextPath(); } }
public void init(FilterConfig filterConfig) throws ServletException { try { log.info("init() of filter"); filterConfig.getServletContext().setAttribute(PortalPickerFilter.class.getName(), this); this.filterConfig = filterConfig; this.prefix2portalid = new HashMap<String, Integer>(); String defaultIndex = (String) filterConfig.getInitParameter("default"); if (defaultIndex != null) this.defaultIndex = defaultIndex; protectedPrefixes = new HashSet<String>(); for (String dir : protectedPrefixV) { protectedPrefixes.add(dir); } WebappDaoFactory fac = (WebappDaoFactory) filterConfig.getServletContext().getAttribute("webappDaoFactory"); setupPortalMappings(fac.getPortalDao().getAllPortals()); log.debug("init() done"); } catch (Throwable t) { t.printStackTrace(); } }
// Check for "back button" confusion specifically for data property editing although need to check // if this applies to object property editing? // TODO: Check if only applicable to data property editing private boolean checkForBackButtonConfusion( EditConfigurationVTwo editConfig, VitroRequest vreq, Model model) { // back button confusion limited to data property if (EditConfigurationUtils.isObjectProperty(editConfig.getPredicateUri(), vreq)) { return false; } WebappDaoFactory wdf = vreq.getWebappDaoFactory(); if (!editConfig.isDataPropertyUpdate()) return false; Integer dpropHash = editConfig.getDatapropKey(); DataPropertyStatement dps = RdfLiteralHash.getPropertyStmtByHash( editConfig.getSubjectUri(), editConfig.getPredicateUri(), dpropHash, model); if (dps != null) return false; DataProperty dp = wdf.getDataPropertyDao().getDataPropertyByURI(editConfig.getPredicateUri()); if (dp != null) { if (dp.getDisplayLimit() == 1 /* || dp.isFunctional() */) return false; else return true; } return false; }
@Override public Map<String, String> getOptions( EditConfigurationVTwo editConfig, String fieldName, WebappDaoFactory wDaoFact) throws Exception { // now create an empty HashMap to populate and return HashMap<String, String> optionsMap = new LinkedHashMap<String, String>(); // for debugging, keep a count of the number of options populated int optionsCount = 0; if (vclassUri == null || vclassUri.equals("")) { throw new Exception( "no vclassUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified"); } else { // first test to see whether there's a default "leave blank" value specified with the literal // options if (defaultOptionLabel != null) { optionsMap.put(LEFT_BLANK, defaultOptionLabel); } // now populate the options VClassDao vclassDao = wDaoFact.getVClassDao(); List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri); if (subClassList == null || subClassList.size() == 0) { log.debug( "No subclasses of " + vclassUri + " found in the model so only default value from field's literalOptions will be used"); } else { for (String subClassUri : subClassList) { VClass subClass = vclassDao.getVClassByURI(subClassUri); if (subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) { optionsMap.put(subClassUri, subClass.getName().trim()); ++optionsCount; } } } } log.debug("added " + optionsCount + " options for field \"" + fieldName + "\""); return optionsMap; }
private String addVClassDataToResultsList( WebappDaoFactory wadf, VClass vcw, int position, String ontologyUri, int counter) { String tempString = ""; if (ontologyUri == null || ((vcw.getNamespace() != null) && (vcw.getNamespace().equals(ontologyUri)))) { // first if statement ensures that the first class begins with correct format if (counter < 1 && position < 1) { tempString += "{ \"name\": "; } else if (position == previous_posn) { tempString += "}, { \"name\": "; } else if (position > previous_posn) { tempString += " { \"name\": "; } else if (position < previous_posn) { tempString += "}, { \"name\": "; } try { tempString += JSONUtils.quote( "<a href='vclassEdit?uri=" + URLEncoder.encode(vcw.getURI(), "UTF-8") + "'>" + vcw.getPickListName() + "</a>") + ", "; } catch (Exception e) { tempString += JSONUtils.quote(((vcw.getPickListName() == null) ? "" : vcw.getPickListName())) + ", "; } String shortDef = ((vcw.getShortDef() == null) ? "" : vcw.getShortDef()); tempString += "\"data\": { \"shortDef\": " + JSONUtils.quote(shortDef) + ", "; // Get group name if it exists VClassGroupDao groupDao = wadf.getVClassGroupDao(); String groupURI = vcw.getGroupURI(); String groupName = null; VClassGroup classGroup = null; if (groupURI != null) { classGroup = groupDao.getGroupByURI(groupURI); if (classGroup != null) { groupName = classGroup.getPublicName(); } } tempString += "\"classGroup\": " + JSONUtils.quote((groupName == null) ? "" : groupName) + ", "; // Get ontology name OntologyDao ontDao = wadf.getOntologyDao(); String ontName = vcw.getNamespace(); Ontology ont = ontDao.getOntologyByURI(ontName); if (ont != null && ont.getName() != null) { ontName = ont.getName(); } tempString += "\"ontology\": " + JSONUtils.quote((ontName == null) ? "" : ontName) + "}, \"children\": ["; previous_posn = position; } return tempString; }
public void contextInitialized(ServletContextEvent sce) { try { ServletContext ctx = sce.getServletContext(); // If the DATA_DIR directory doesn't exist no migration check will be done. // This is a normal situation for Vitro. File updateDirectory = new File(ctx.getRealPath(DATA_DIR)); if (!updateDirectory.exists()) { log.debug( "Directory " + ctx.getRealPath(DATA_DIR) + " does not exist, no migration check will be attempted."); return; } String logFileName = DATA_DIR + LOG_DIR + timestampedFileName("knowledgeBaseUpdate", "log"); String errorLogFileName = DATA_DIR + LOG_DIR + timestampedFileName("knowledgeBaseUpdate.error", "log"); UpdateSettings settings = new UpdateSettings(); settings.setAskUpdatedQueryFile(getAskUpdatedQueryPath(ctx)); settings.setDataDir(ctx.getRealPath(DATA_DIR)); settings.setSparqlConstructAdditionsDir(ctx.getRealPath(SPARQL_CONSTRUCT_ADDITIONS_DIR)); settings.setSparqlConstructDeletionsDir(ctx.getRealPath(SPARQL_CONSTRUCT_DELETIONS_DIR)); settings.setDiffFile(ctx.getRealPath(DIFF_FILE)); settings.setSuccessAssertionsFile(ctx.getRealPath(SUCCESS_ASSERTIONS_FILE)); settings.setSuccessRDFFormat(SUCCESS_RDF_FORMAT); settings.setLogFile(ctx.getRealPath(logFileName)); settings.setErrorLogFile(ctx.getRealPath(errorLogFileName)); settings.setAddedDataFile(ctx.getRealPath(ADDED_DATA_FILE)); settings.setRemovedDataFile(ctx.getRealPath(REMOVED_DATA_FILE)); WebappDaoFactory wadf = (WebappDaoFactory) ctx.getAttribute("webappDaoFactory"); settings.setDefaultNamespace(wadf.getDefaultNamespace()); settings.setAssertionOntModelSelector(ModelContext.getBaseOntModelSelector(ctx)); settings.setInferenceOntModelSelector(ModelContext.getInferenceOntModelSelector(ctx)); settings.setUnionOntModelSelector(ModelContext.getUnionOntModelSelector(ctx)); boolean tryMigrateDisplay = true; try { settings.setDisplayModel(ModelContext.getDisplayModel(ctx)); OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_MODEL_DIR)); settings.setOldTBoxModel(oldTBoxModel); OntModel newTBoxModel = loadModelFromDirectory(ctx.getRealPath(NEW_TBOX_MODEL_DIR)); settings.setNewTBoxModel(newTBoxModel); OntModel oldTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_ANNOTATIONS_DIR)); settings.setOldTBoxAnnotationsModel(oldTBoxAnnotationsModel); OntModel newTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(NEW_TBOX_ANNOTATIONS_DIR)); settings.setNewTBoxAnnotationsModel(newTBoxAnnotationsModel); // Display model tbox and display metadata // old display model tbox model OntModel oldDisplayModelTboxModel = loadModelFromFile(ctx.getRealPath(OLD_DISPLAYMODEL_TBOX_PATH)); settings.setOldDisplayModelTboxModel(oldDisplayModelTboxModel); // new display model tbox model OntModel newDisplayModelTboxModel = loadModelFromFile(ctx.getRealPath(NEW_DISPLAYMODEL_TBOX_PATH)); settings.setNewDisplayModelTboxModel(newDisplayModelTboxModel); // old display model display model metadata OntModel oldDisplayModelDisplayMetadataModel = loadModelFromFile(ctx.getRealPath(OLD_DISPLAYMODEL_DISPLAYMETADATA_PATH)); settings.setOldDisplayModelDisplayMetadataModel(oldDisplayModelDisplayMetadataModel); // new display model display model metadata OntModel newDisplayModelDisplayMetadataModel = loadModelFromFile(ctx.getRealPath(NEW_DISPLAYMODEL_DISPLAYMETADATA_PATH)); settings.setNewDisplayModelDisplayMetadataModel(newDisplayModelDisplayMetadataModel); // Get new display model OntModel newDisplayModelFromFile = loadModelFromFile(ctx.getRealPath(NEW_DISPLAYMODEL_PATH)); settings.setNewDisplayModelFromFile(newDisplayModelFromFile); OntModel loadedAtStartupFiles = loadModelFromDirectory(ctx.getRealPath(LOADED_STARTUPT_DISPLAYMODEL_DIR)); settings.setLoadedAtStartupDisplayModel(loadedAtStartupFiles); OntModel oldDisplayModelVivoListView = loadModelFromFile(ctx.getRealPath(OLD_DISPLAYMODEL_VIVOLISTVIEW_PATH)); settings.setVivoListViewConfigDisplayModel(oldDisplayModelVivoListView); } catch (Exception e) { log.info( "unable to read display model migration files, display model not migrated. " + e.getMessage()); tryMigrateDisplay = false; } try { KnowledgeBaseUpdater ontologyUpdater = new KnowledgeBaseUpdater(settings); try { if (ontologyUpdater.updateRequired(ctx)) { ctx.setAttribute(KBM_REQURIED_AT_STARTUP, Boolean.TRUE); ontologyUpdater.update(ctx); if (tryMigrateDisplay) { try { migrateDisplayModel(settings); log.info("Migrated display model"); } catch (Exception e) { log.warn("unable to successfully update display model: " + e.getMessage()); } } } } catch (Exception ioe) { String errMsg = "Exception updating knowledge base " + "for ontology changes: "; // Tomcat doesn't always seem to print exceptions thrown from // context listeners System.out.println(errMsg); ioe.printStackTrace(); throw new RuntimeException(errMsg, ioe); } } catch (Throwable t) { log.warn("warning", t); } } catch (Throwable t) { t.printStackTrace(); } }
public PropertyListConfig( ObjectPropertyTemplateModel optm, TemplateLoader templateLoader, VitroRequest vreq, ObjectProperty op, boolean editing) throws InvalidConfigurationException { this.optm = optm; this.vreq = vreq; WebappDaoFactory wadf = vreq.getWebappDaoFactory(); this.templateLoader = templateLoader; // Get the custom config filename String configFileName = wadf.getObjectPropertyDao().getCustomListViewConfigFileName(op); if (configFileName == null) { // no custom config; use default config configFileName = DEFAULT_CONFIG_FILE_NAME; } log.debug( "Using list view config file " + configFileName + " for object property " + op.getURI()); String configFilePath = getConfigFilePath(configFileName); try { File config = new File(configFilePath); if (!isDefaultConfig(configFileName) && !config.exists()) { log.warn( "Can't find config file " + configFilePath + " for object property " + op.getURI() + "\n" + ". Using default config file instead."); configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE_NAME); // Should we test for the existence of the default, and throw an error if it doesn't exist? } setValuesFromConfigFile(configFilePath, wadf, editing); } catch (Exception e) { log.error( "Error processing config file " + configFilePath + " for object property " + op.getURI(), e); // What should we do here? } if (!isDefaultConfig(configFileName)) { ConfigError configError = checkConfiguration(); if (configError != null) { // the configuration contains an error // If this is a collated property, throw an error: this results in creating an // UncollatedPropertyTemplateModel instead. if (optm instanceof CollatedObjectPropertyTemplateModel) { throw new InvalidConfigurationException(configError.getMessage()); } // Otherwise, switch to the default config log.warn( "Invalid list view config for object property " + op.getURI() + " in " + configFilePath + ":\n" + configError + " Using default config instead."); configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE_NAME); setValuesFromConfigFile(configFilePath, wadf, editing); } } isDefaultConfig = isDefaultConfig(configFileName); }