コード例 #1
0
 public Collection<PropertyInstance> getExistingProperties(String entityURI, String propertyURI) {
   Individual ent = getWebappDaoFactory().getIndividualDao().getIndividualByURI(entityURI);
   if (ent == null) return null;
   ent.sortForDisplay();
   List existingPropertyInstances = new ArrayList();
   if (ent.getObjectPropertyList() == null) return existingPropertyInstances;
   Iterator objPropertyIter = ent.getObjectPropertyList().iterator();
   while (objPropertyIter.hasNext()) {
     edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty op =
         (edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty) objPropertyIter.next();
     Iterator objPropertyStmtIter = op.getObjectPropertyStatements().iterator();
     while (objPropertyStmtIter.hasNext()) {
       ObjectPropertyStatement objPropertyStmt =
           (ObjectPropertyStatement) objPropertyStmtIter.next();
       if (propertyURI == null || objPropertyStmt.getPropertyURI().equals(propertyURI)) {
         PropertyInstance pi = new PropertyInstance();
         pi.setSubjectSide(true);
         pi.setSubjectEntURI(ent.getURI());
         pi.setSubjectName(ent.getName());
         if (objPropertyStmt.getObject() != null)
           pi.setObjectName(objPropertyStmt.getObject().getName());
         else pi.setObjectName(objPropertyStmt.getObjectURI());
         pi.setObjectEntURI(objPropertyStmt.getObjectURI());
         pi.setPropertyURI(objPropertyStmt.getPropertyURI());
         if (objPropertyStmt.getProperty() != null) {
           pi.setDomainPublic(
               (objPropertyStmt.getProperty().getDomainPublic() != null)
                   ? objPropertyStmt.getProperty().getDomainPublic()
                   : objPropertyStmt.getProperty().getLocalName());
         } else {
           pi.setDomainPublic(objPropertyStmt.getPropertyURI());
         }
         existingPropertyInstances.add(pi);
       }
     }
   }
   return existingPropertyInstances;
 }
コード例 #2
0
  public void doPost(HttpServletRequest request, HttpServletResponse response) {
    final int NUM_COLS = 17;

    if (!checkLoginStatus(request, response)) return;

    try {
      super.doGet(request, response);
    } catch (Exception e) {
      log.error("PropertyEditController caught exception calling doGet()");
    }

    VitroRequest vreq = new VitroRequest(request);
    Portal portal = vreq.getPortal();

    ObjectPropertyDao propDao = vreq.getFullWebappDaoFactory().getObjectPropertyDao();
    VClassDao vcDao = vreq.getFullWebappDaoFactory().getVClassDao();
    PropertyGroupDao pgDao = vreq.getFullWebappDaoFactory().getPropertyGroupDao();
    ObjectProperty p = (ObjectProperty) propDao.getObjectPropertyByURI(request.getParameter("uri"));
    request.setAttribute("property", p);

    ArrayList<String> results = new ArrayList<String>();
    results.add("Property"); // column 1
    results.add("parent property"); // column 2
    results.add("domain"); // column 3
    results.add("range"); // column 4
    results.add("display name"); // column 5
    results.add("group"); // column 6
    results.add("display tier"); // column 7
    results.add("example"); // column 8
    results.add("description"); // column 9
    results.add("public description"); // column 10
    results.add("display level"); // column 11
    results.add("update level"); // column 12
    results.add("custom entry form"); // column 13
    results.add("select from existing"); // column 14
    results.add("offer create new option"); // column 15
    results.add("force stub object deletion"); // column 16
    results.add("URI"); // column 17

    String displayName = (p.getDomainPublic() == null) ? p.getLocalName() : p.getDomainPublic();
    try {
      results.add(
          "<a href=\"propertyEdit?uri="
              + URLEncoder.encode(p.getURI(), "UTF-8")
              + "\">"
              + displayName
              + "</a> <em>"
              + p.getLocalNameWithPrefix()
              + "</em>"); // column 1
    } catch (UnsupportedEncodingException e) {
      log.error(
          "Could not encode URI for property (domain public: "
              + p.getDomainPublic()
              + ", local name with prefix: "
              + p.getLocalNameWithPrefix()
              + ", URI: "
              + p.getURI()
              + ").");
      results.add(displayName + "<em>" + p.getLocalNameWithPrefix() + "</em>"); // column 1
    }

    String parentPropertyStr = "";
    if (p.getParentURI() != null) {
      ObjectProperty parent = propDao.getObjectPropertyByURI(p.getParentURI());
      if (parent != null && parent.getURI() != null) {
        try {
          parentPropertyStr =
              "<a href=\"propertyEdit?uri="
                  + URLEncoder.encode(parent.getURI(), "UTF-8")
                  + "&amp;home="
                  + portal.getPortalId()
                  + "\">"
                  + parent.getLocalNameWithPrefix()
                  + "</a>";
        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }
      }
    }
    results.add(parentPropertyStr); // column 2

    String domainStr = "";
    if (p.getDomainVClassURI() != null) {
      VClass domainClass = vcDao.getVClassByURI(p.getDomainVClassURI());
      if (domainClass != null
          && domainClass.getURI() != null
          && domainClass.getLocalNameWithPrefix() != null) {
        try {
          if (domainClass.isAnonymous()) {
            domainStr = domainClass.getLocalNameWithPrefix();
          } else {
            domainStr =
                "<a href=\"vclassEdit?uri="
                    + URLEncoder.encode(domainClass.getURI(), "UTF-8")
                    + "&amp;home="
                    + portal.getPortalId()
                    + "\">"
                    + domainClass.getLocalNameWithPrefix()
                    + "</a>";
          }
        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }
      }
    }
    results.add(domainStr); // column 3

    String rangeStr = "";
    if (p.getRangeVClassURI() != null) {
      VClass rangeClass = vcDao.getVClassByURI(p.getRangeVClassURI());
      if (rangeClass != null
          && rangeClass.getURI() != null
          && rangeClass.getLocalNameWithPrefix() != null) {
        try {
          if (rangeClass.isAnonymous()) {
            rangeStr = rangeClass.getLocalNameWithPrefix();
          } else {
            rangeStr =
                "<a href=\"vclassEdit?uri="
                    + URLEncoder.encode(rangeClass.getURI(), "UTF-8")
                    + "&amp;home="
                    + portal.getPortalId()
                    + "\">"
                    + rangeClass.getLocalNameWithPrefix()
                    + "</a>";
          }
        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }
      }
    }
    results.add(rangeStr); // column 4

    results.add(p.getDomainPublic() == null ? "" : p.getDomainPublic()); // column 5
    if (p.getGroupURI() != null) {
      PropertyGroup pGroup = pgDao.getGroupByURI(p.getGroupURI());
      if (pGroup != null) {
        results.add(pGroup.getName()); // column 6
      } else {
        results.add("unnamed group"); // column 6
      }
    } else {
      results.add("unspecified"); // column 6
    }
    results.add(
        "domain: " + p.getDomainDisplayTier() + ", range: " + p.getRangeDisplayTier()); // column 7
    String exampleStr = (p.getExample() == null) ? "" : p.getExample();
    results.add(exampleStr); // column 8
    String descriptionStr = (p.getDescription() == null) ? "" : p.getDescription();
    results.add(descriptionStr); // column 9
    String publicDescriptionStr =
        (p.getPublicDescription() == null) ? "" : p.getPublicDescription();
    results.add(publicDescriptionStr); // column 10

    results.add(
        p.getHiddenFromDisplayBelowRoleLevel() == null
            ? "unspecified"
            : p.getHiddenFromDisplayBelowRoleLevel().getLabel()); // column 11
    results.add(
        p.getProhibitedFromUpdateBelowRoleLevel() == null
            ? "unspecified"
            : p.getProhibitedFromUpdateBelowRoleLevel().getLabel()); // column 12

    results.add(
        p.getCustomEntryForm() == null ? "unspecified" : p.getCustomEntryForm()); // column 13
    results.add(p.getSelectFromExisting() ? "true" : "false"); // column 14
    results.add(p.getOfferCreateNewOption() ? "true" : "false"); // column 15
    results.add(p.getStubObjectRelation() ? "true" : "false"); // column 16
    results.add(p.getURI()); // column 17
    request.setAttribute("results", results);
    request.setAttribute("columncount", NUM_COLS);
    request.setAttribute("suppressquery", "true");

    boolean FORCE_NEW = true;

    EditProcessObject epo = super.createEpo(request, FORCE_NEW);
    FormObject foo = new FormObject();
    HashMap OptionMap = new HashMap();
    foo.setOptionLists(OptionMap);
    epo.setFormObject(foo);

    // superproperties and subproperties

    ObjectPropertyDao opDao;
    if (vreq.getAssertionsWebappDaoFactory() != null) {
      opDao = vreq.getAssertionsWebappDaoFactory().getObjectPropertyDao();
    } else {
      opDao = vreq.getFullWebappDaoFactory().getObjectPropertyDao();
    }
    List superURIs = opDao.getSuperPropertyURIs(p.getURI(), false);
    List superProperties = new ArrayList();
    Iterator superURIit = superURIs.iterator();
    while (superURIit.hasNext()) {
      String superURI = (String) superURIit.next();
      if (superURI != null) {
        ObjectProperty superProperty = opDao.getObjectPropertyByURI(superURI);
        if (superProperty != null) {
          superProperties.add(superProperty);
        }
      }
    }
    request.setAttribute("superproperties", superProperties);

    List subURIs = opDao.getSubPropertyURIs(p.getURI());
    List subProperties = new ArrayList();
    Iterator subURIit = subURIs.iterator();
    while (subURIit.hasNext()) {
      String subURI = (String) subURIit.next();
      ObjectProperty subProperty = opDao.getObjectPropertyByURI(subURI);
      if (subProperty != null) {
        subProperties.add(subProperty);
      }
    }
    request.setAttribute("subproperties", subProperties);

    List eqURIs = opDao.getEquivalentPropertyURIs(p.getURI());
    List eqProperties = new ArrayList();
    Iterator eqURIit = eqURIs.iterator();
    while (eqURIit.hasNext()) {
      String eqURI = (String) eqURIit.next();
      ObjectProperty eqProperty = opDao.getObjectPropertyByURI(eqURI);
      if (eqProperty != null) {
        eqProperties.add(eqProperty);
      }
    }
    request.setAttribute("equivalentProperties", eqProperties);

    RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
    request.setAttribute("epoKey", epo.getKey());
    request.setAttribute("propertyWebapp", p);
    request.setAttribute("bodyJsp", "/templates/edit/specific/props_edit.jsp");
    request.setAttribute("portalBean", portal);
    request.setAttribute("title", "Object Property Control Panel");
    request.setAttribute(
        "css",
        "<link rel=\"stylesheet\" type=\"text/css\" href=\""
            + portal.getThemeDir()
            + "css/edit.css\"/>");

    try {
      rd.forward(request, response);
    } catch (Exception e) {
      log.error("PropertyEditController could not forward to view.");
      log.error(e.getMessage());
      log.error(e.getStackTrace());
    }
  }
コード例 #3
0
  private void tryRestriction(
      OntClass theClass,
      VClassDao vcDao,
      ObjectPropertyDao opDao,
      IndividualDao iDao,
      ArrayList results,
      String vClassURI) {
    if (theClass.isRestriction()) {
      Restriction rest = (Restriction) theClass.as(Restriction.class);
      try {
        results.add("XX");
        Property onProperty = rest.getOnProperty();
        ObjectProperty op = opDao.getObjectPropertyByURI(onProperty.getURI());
        results.add(op.getLocalNameWithPrefix());
        if (rest.isAllValuesFromRestriction()) {
          results.add("all values from");
          AllValuesFromRestriction avfrest =
              (AllValuesFromRestriction) rest.as(AllValuesFromRestriction.class);
          Resource allValuesFrom = avfrest.getAllValuesFrom();
          results.add(printAsClass(vcDao, allValuesFrom));
        } else if (rest.isSomeValuesFromRestriction()) {
          results.add("some values from");
          SomeValuesFromRestriction svfrest =
              (SomeValuesFromRestriction) rest.as(SomeValuesFromRestriction.class);
          Resource someValuesFrom = svfrest.getSomeValuesFrom();
          results.add(printAsClass(vcDao, someValuesFrom));
        } else if (rest.isHasValueRestriction()) {
          results.add("has value");
          HasValueRestriction hvrest = (HasValueRestriction) rest.as(HasValueRestriction.class);
          RDFNode hasValue = hvrest.getHasValue();
          if (hasValue.isResource()) {
            Resource hasValueRes = (Resource) hasValue.as(Resource.class);
            try {
              if (hasValueRes.getURI() != null) {
                Individual ind = iDao.getIndividualByURI(hasValueRes.getURI());
                if (ind.getName() != null) {
                  results.add(ind.getName());
                }
              }
            } catch (Exception e) {
              results.add("???");
            }
          }

        } else if (rest.isMinCardinalityRestriction()) {
          MinCardinalityRestriction crest =
              (MinCardinalityRestriction) rest.as(MinCardinalityRestriction.class);
          results.add("at least " + crest.getMinCardinality());
          results.add(LAMBDA);
        } else if (rest.isMaxCardinalityRestriction()) {
          MaxCardinalityRestriction crest =
              (MaxCardinalityRestriction) rest.as(MaxCardinalityRestriction.class);
          results.add("at most " + crest.getMaxCardinality());
          results.add(LAMBDA);
        } else if (rest.isCardinalityRestriction()) {
          CardinalityRestriction crest =
              (CardinalityRestriction) rest.as(CardinalityRestriction.class);
          results.add("exactly " + crest.getCardinality());
          results.add(LAMBDA);
        }

        results.add(
            "<form action=\"addRestriction\" method=\"post\">"
                + "<input type=\"hidden\" name=\"_action\" value=\"delete\"/>"
                + "<input type=\"submit\" value=\"Delete\"/>"
                + "<input type=\"hidden\" name=\"_epoKey\" value=\""
                + epo.getKey()
                + "\"/>"
                + "<input type=\"hidden\" name=\"classUri\" value=\""
                + vClassURI
                + "\"/>"
                + "<input type=\"hidden\" name=\"restrictionId\" value=\""
                + ((rest.getId() != null) ? rest.getId() : rest.getURI())
                + "\"/>"
                + "</form>");

      } catch (Exception e) {
        e.printStackTrace(); // results.add("unknown property");
      }
    }
  }
コード例 #4
0
  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);
  }