private boolean isEmbargoed(Context context, Item item) throws Exception {
    // if an embargo field isn't configured, then the item can't be embargoed
    String liftDateField = ConfigurationManager.getProperty("embargo.field.lift");
    if (liftDateField == null) {
      return false;
    }

    // if there is no embargo value, the item isn't embargoed
    DCValue[] embargoes = item.getMetadata(liftDateField);
    if (embargoes.length == 0) {
      return false;
    }

    // if the embargo date is in the past, then the item isn't embargoed
    try {
      DCDate embargoDate = EmbargoManager.getEmbargoTermsAsDate(context, item);
      if ((new Date()).getTime() > embargoDate.toDate().getTime()) {
        return false;
      }
    } catch (SQLException e) {
      throw new Exception(e);
    } catch (AuthorizeException e) {
      throw new Exception(e);
    } catch (IOException e) {
      throw new Exception(e);
    }

    return true;
  }
  private List disseminateListInternal(DSpaceObject dso, boolean addSchema)
      throws CrosswalkException, IOException, SQLException, AuthorizeException {
    if (dso.getType() != Constants.ITEM)
      throw new CrosswalkObjectNotSupported(
          "MODSDisseminationCrosswalk can only crosswalk an Item.");
    Item item = (Item) dso;
    initMap();

    MetadataValue[] dc = item.getMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);
    List result = new ArrayList(dc.length);
    for (int i = 0; i < dc.length; i++) {
      // Compose qualified DC name - schema.element[.qualifier]
      // e.g. "dc.title", "dc.subject.lcc", "lom.Classification.Keyword"
      String qdc =
          dc[i].getMetadataField().getSchema()
              + "."
              + ((dc[i].getMetadataField().getQualifier() == null)
                  ? dc[i].getMetadataField().getElement()
                  : (dc[i].getMetadataField().getElement()
                      + "."
                      + dc[i].getMetadataField().getQualifier()));

      modsTriple trip = (modsTriple) modsMap.get(qdc);
      if (trip == null)
        log.warn("WARNING: " + getPluginInstanceName() + ": No MODS mapping for \"" + qdc + "\"");
      else {
        try {
          Element me = (Element) trip.xml.clone();
          if (addSchema) me.setAttribute("schemaLocation", schemaLocation, XSI_NS);
          Iterator ni = trip.xpath.selectNodes(me).iterator();
          if (!ni.hasNext())
            log.warn(
                "XPath \""
                    + trip.xpath.getXPath()
                    + "\" found no elements in \""
                    + outputUgly.outputString(me)
                    + "\", qdc="
                    + qdc);
          while (ni.hasNext()) {
            Object what = ni.next();
            if (what instanceof Element) ((Element) what).setText(dc[i].getValue());
            else if (what instanceof Attribute) ((Attribute) what).setValue(dc[i].getValue());
            else if (what instanceof Text) ((Text) what).setText(dc[i].getValue());
            else log.warn("Got unknown object from XPath, class=" + what.getClass().getName());
          }
          result.add(me);
        } catch (JDOMException je) {
          log.error(
              "Error following XPath in modsTriple: context="
                  + outputUgly.outputString(trip.xml)
                  + ", xpath="
                  + trip.xpath.getXPath()
                  + ", exception="
                  + je.toString());
        }
      }
    }
    return result;
  }
 private boolean isFail(Context context, Item item) {
   String gradeField = ConfigurationManager.getProperty("studentweb", "grade.field");
   DCValue[] dcvs = item.getMetadata(gradeField);
   for (DCValue dcv : dcvs) {
     if ("fail".equals(dcv.value.trim())) {
       return true;
     }
   }
   return false;
 }
 // build DIM expression of Item's metadata.
 private Element getDim(Item item) {
   DCValue[] dc = item.getMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);
   Element dim = new Element("dim", DIM_NS);
   for (int i = 0; i < dc.length; i++) {
     Element field = new Element("field", DIM_NS);
     field.setAttribute("mdschema", dc[i].schema);
     field.setAttribute("element", dc[i].element);
     if (dc[i].qualifier != null) field.setAttribute("qualifier", dc[i].qualifier);
     if (dc[i].language != null) field.setAttribute("lang", dc[i].language);
     if (dc[i].value != null) field.setText(dc[i].value);
     dim.addContent(field);
   }
   return dim;
 }
Example #5
0
  public void addRioxxVersionSection(List upload, Item item) throws WingException {
    String version = item.getMetadata("rioxxterms.version");

    if (StringUtils.isNotBlank(version) && !"NA".equals(version)) {
      try {
        DCInputsReader a = new DCInputsReader();
        java.util.List<String> pairs = a.getPairs("rioxxterms_version");
        int humanReadable = pairs.indexOf(version) - 1;
        version = pairs.get(humanReadable);
      } catch (DCInputsReaderException e) {
        log.error(e.getMessage(), e);
      }
      upload
          .addItem("upload-rioxx-version-warning", "upload-rioxx-version-warning")
          .addContent(T_rioxx_version.parameterize(version));
    }
  }
  /**
   * Utility method to obtain the titles for the Items in the given list.
   *
   * @param List of Items
   * @return array of corresponding titles
   */
  private String[] getItemTitles(List items) {
    String[] titles = new String[items.size()];

    for (int i = 0; i < items.size(); i++) {
      Item item = (Item) items.get(i);

      // FIXME: Should probably check for preferred language?
      MetadataValue[] titlesForThis =
          item.getMetadata(MetadataSchema.DC_SCHEMA, "title", null, Item.ANY);

      // Just use the first title, if any
      if (titlesForThis.length == 0) {
        // No title at all!
        titles[i] = null;
      } else {
        // Use first title
        titles[i] = titlesForThis[0].getValue();
      }
    }

    return titles;
  }
 /**
  * Perform the curation task upon passed DSO
  *
  * @param dso the DSpace object
  * @throws IOException
  */
 @Override
 public int perform(DSpaceObject dso) throws IOException {
   if (dso.getType() == Constants.ITEM) {
     Item item = (Item) dso;
     int count = 0;
     try {
       StringBuilder sb = new StringBuilder();
       String handle = item.getHandle();
       if (handle == null) {
         // we are still in workflow - no handle assigned
         handle = "in workflow";
       }
       sb.append("Item: ").append(handle);
       for (String req : getReqList(item.getOwningCollection().getHandle())) {
         DCValue[] vals = item.getMetadata(req);
         if (vals.length == 0) {
           sb.append(" missing required field: ").append(req);
           count++;
         }
       }
       if (count == 0) {
         sb.append(" has all required fields");
       }
       report(sb.toString());
       setResult(sb.toString());
     } catch (DCInputsReaderException dcrE) {
       throw new IOException(dcrE.getMessage(), dcrE);
     } catch (SQLException sqlE) {
       throw new IOException(sqlE.getMessage(), sqlE);
     }
     return (count == 0) ? Curator.CURATE_SUCCESS : Curator.CURATE_FAIL;
   } else {
     setResult("Object skipped");
     return Curator.CURATE_SKIP;
   }
 }