コード例 #1
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");
      }
    }
  }
コード例 #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());
    }
  }