Ejemplo n.º 1
0
  private void updateMetadata(
      RecordInfo ri, String id, Element md, Element info, boolean localRating) throws Exception {
    String date = localUuids.getChangeDate(ri.uuid);

    // validate it here if requested
    if (params.validate) {
      if (!dataMan.validate(md)) {
        log.info("Ignoring invalid metadata");
        result.doesNotValidate++;
        return;
      }
    }

    if (!ri.isMoreRecentThan(date)) {
      if (log.isDebugEnabled())
        log.debug("  - XML not changed for local metadata with uuid:" + ri.uuid);
      result.unchangedMetadata++;
    } else {
      md = processMetadata(ri, md);

      // update metadata
      if (log.isDebugEnabled()) log.debug("  - Updating local metadata with id=" + id);

      boolean validate = false;
      boolean ufo = params.mefFormatFull;
      boolean index = false;
      String language = context.getLanguage();
      dataMan.updateMetadata(
          context, dbms, id, md, validate, ufo, index, language, ri.changeDate, false);

      result.updatedMetadata++;
    }

    Element general = info.getChild("general");

    String popularity = general.getChildText("popularity");

    if (!localRating) {
      String rating = general.getChildText("rating");
      if (rating != null)
        dbms.execute(
            "UPDATE Metadata SET rating=? WHERE id=?", new Integer(rating), new Integer(id));
    }

    if (popularity != null)
      dbms.execute(
          "UPDATE Metadata SET popularity=? WHERE id=?", new Integer(popularity), new Integer(id));

    dbms.execute("DELETE FROM MetadataCateg WHERE metadataId=?", Integer.parseInt(id));
    addCategories(id);
    if (params.createRemoteCategory) {
      Element categs = info.getChild("categories");
      if (categs != null) {
        Importer.addCategories(context, dataMan, dbms, id, categs);
      }
    }

    dbms.execute("DELETE FROM OperationAllowed WHERE metadataId=?", Integer.parseInt(id));
    addPrivileges(id, info.getChild("privileges"));

    dbms.commit();
    dataMan.indexMetadataGroup(dbms, id);
  }
Ejemplo n.º 2
0
  private String addMetadata(RecordInfo ri, Element md, Element info, boolean localRating)
      throws Exception {
    Element general = info.getChild("general");

    String createDate = general.getChildText("createDate");
    String changeDate = general.getChildText("changeDate");
    String isTemplate = general.getChildText("isTemplate");
    String siteId = general.getChildText("siteId");
    String popularity = general.getChildText("popularity");

    if ("true".equals(isTemplate)) isTemplate = "y";
    else isTemplate = "n";

    if (log.isDebugEnabled()) log.debug("  - Adding metadata with remote uuid:" + ri.uuid);

    // validate it here if requested
    if (params.validate) {
      if (!dataMan.validate(md)) {
        log.info("Ignoring invalid metadata");
        result.doesNotValidate++;
        return null;
      }
    }

    md = processMetadata(ri, md);

    // insert metadata
    int userid = 1;
    String group = null, docType = null, title = null, category = null;
    // If MEF format is full, private file links needs to be updated
    boolean ufo = params.mefFormatFull;
    boolean indexImmediate = false;
    String id =
        dataMan.insertMetadata(
            context,
            dbms,
            ri.schema,
            md,
            context.getSerialFactory().getSerial(dbms, "Metadata"),
            ri.uuid,
            userid,
            group,
            siteId,
            isTemplate,
            docType,
            title,
            category,
            createDate,
            changeDate,
            ufo,
            indexImmediate);

    int iId = Integer.parseInt(id);

    dataMan.setTemplateExt(dbms, iId, isTemplate, null);
    dataMan.setHarvestedExt(dbms, iId, params.uuid);

    if (!localRating) {
      String rating = general.getChildText("rating");
      if (rating != null)
        dbms.execute("UPDATE Metadata SET rating=? WHERE id=?", new Integer(rating), iId);
    }

    if (popularity != null)
      dbms.execute("UPDATE Metadata SET popularity=? WHERE id=?", new Integer(popularity), iId);

    String pubDir = Lib.resource.getDir(context, "public", id);
    String priDir = Lib.resource.getDir(context, "private", id);

    new File(pubDir).mkdirs();
    new File(priDir).mkdirs();

    addCategories(id);
    if (params.createRemoteCategory) {
      Element categs = info.getChild("categories");
      if (categs != null) {
        Importer.addCategories(context, dataMan, dbms, id, categs);
      }
    }
    addPrivileges(id, info.getChild("privileges"));

    dbms.commit();
    dataMan.indexMetadataGroup(dbms, id);
    result.addedMetadata++;

    return id;
  }