Ejemplo n.º 1
0
  public Element exec(Element params, ServiceContext context) throws Exception {

    Path harvestingLogoDirectory = Resources.locateHarvesterLogosDir(context);
    Path nodeLogoDirectory = Resources.locateLogosDir(context);

    String file = Util.getParam(params, Params.FNAME);
    String asFavicon = Util.getParam(params, Params.FAVICON, "0");

    if (file.contains("..")) {
      throw new BadParameterEx("Invalid character found in resource name.", file);
    }

    if ("".equals(file)) {
      throw new Exception("Logo name is not defined.");
    }

    SettingManager settingMan = context.getBean(SettingManager.class);
    String nodeUuid = settingMan.getSiteId();

    try {
      Path logoFilePath = harvestingLogoDirectory.resolve(file);
      if (!Files.exists(logoFilePath)) {
        logoFilePath = context.getAppPath().resolve("images/harvesting/" + file);
      }
      try (InputStream inputStream = Files.newInputStream(logoFilePath)) {
        BufferedImage source = ImageIO.read(inputStream);

        if ("1".equals(asFavicon)) {
          createFavicon(source, nodeLogoDirectory.resolve("favicon.png"));
        } else {
          Path logo = nodeLogoDirectory.resolve(nodeUuid + ".png");
          Path defaultLogo = nodeLogoDirectory.resolve("logo.png");

          if (!file.endsWith(".png")) {
            try (OutputStream logoOut = Files.newOutputStream(logo);
                OutputStream defLogoOut = Files.newOutputStream(defaultLogo); ) {
              ImageIO.write(source, "png", logoOut);
              ImageIO.write(source, "png", defLogoOut);
            }
          } else {
            Files.deleteIfExists(logo);
            IO.copyDirectoryOrFile(logoFilePath, logo, false);
            Files.deleteIfExists(defaultLogo);
            IO.copyDirectoryOrFile(logoFilePath, defaultLogo, false);
          }
        }
      }
    } catch (Exception e) {
      throw new Exception(
          "Unable to move uploaded thumbnail to destination directory. Error: " + e.getMessage());
    }

    Element response = new Element("response");
    response.addContent(new Element("status").setText("Logo set."));
    return response;
  }
Ejemplo n.º 2
0
  public GeonetResult align(Set<RecordInfo> records) throws Exception {
    log.info("Start of alignment for : " + params.name);

    // -----------------------------------------------------------------------
    // --- retrieve all local categories and groups
    // --- retrieve harvested uuids for given harvesting node

    localCateg = new CategoryMapper(dbms);
    localGroups = new GroupMapper(dbms);
    localUuids = new UUIDMapper(dbms, params.uuid);
    dbms.commit();

    parseXSLFilter();

    // -----------------------------------------------------------------------
    // --- remove old metadata

    for (String uuid : localUuids.getUUIDs())
      if (!exists(records, uuid)) {
        String id = localUuids.getID(uuid);

        if (log.isDebugEnabled()) log.debug("  - Removing old metadata with id:" + id);
        dataMan.deleteMetadata(context, dbms, id);
        dbms.commit();
        result.locallyRemoved++;
      }

    // -----------------------------------------------------------------------
    // --- insert/update new metadata

    for (RecordInfo ri : records) {
      result.totalMetadata++;

      if (!dataMan.existsSchema(ri.schema)) {
        if (log.isDebugEnabled())
          log.debug(
              "  - Metadata skipped due to unknown schema. uuid:"
                  + ri.uuid
                  + ", schema:"
                  + ri.schema);
        result.unknownSchema++;
      } else {
        String id = dataMan.getMetadataId(dbms, ri.uuid);

        // look up value of localrating/enabled
        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
        SettingManager settingManager = gc.getSettingManager();
        boolean localRating = settingManager.getValueAsBool("system/localrating/enabled", false);

        if (id == null) {
          addMetadata(ri, localRating);
        } else {
          updateMetadata(ri, id, localRating);
        }
      }
    }

    log.info("End of alignment for : " + params.name);

    return result;
  }
Ejemplo n.º 3
0
  public LDAPContext(SettingManager sm) {
    String prefix = "system/ldap";

    use = sm.getValueAsBool(prefix + "/use");
    host = sm.getValue(prefix + "/host");
    port = sm.getValueAsInt(prefix + "/port");
    defProfile = sm.getValue(prefix + "/defaultProfile");
    defGroup = sm.getValue(prefix + "/defaultGroup");
    baseDN = sm.getValue(prefix + "/distinguishedNames/base");
    usersDN = sm.getValue(prefix + "/distinguishedNames/users");
    nameAttr = sm.getValue(prefix + "/userAttribs/name");
    profileAttr = sm.getValue(prefix + "/userAttribs/profile");
    emailAttr = "mail"; // TODO make it configurable
    uidAttr = sm.getValue(prefix + "/uidAttr");
    groupAttr = sm.getValue(prefix + "/userAttribs/group");

    if (profileAttr.trim().length() == 0) profileAttr = null;

    if (groupAttr.trim().length() == 0) groupAttr = null;

    // --- init set of allowed profiles

    profiles.add("Hoofdeditor");
    profiles.add("Editor");
    profiles.add("RegisteredUser");
    profiles.add("UserAdmin");
    profiles.add("Monitor");
    profiles.add("Administrator");
  }
  /**
   * @param xml
   * @param fileIds
   * @param context
   * @param toIndex
   * @return
   * @throws Exception
   */
  private boolean insertTransaction(
      Element xml, List<String> fileIds, ServiceContext context, Set<String> toIndex)
      throws Exception {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    DataManager dataMan = gc.getDataManager();

    String schema = dataMan.autodetectSchema(xml);

    //		String category   = Util.getParam(request, Params.CATEGORY);
    String category = null, source = null, createDate = null, changeDate = null;

    String uuid;
    uuid = dataMan.extractUUID(schema, xml);
    if (uuid.length() == 0) uuid = UUID.randomUUID().toString();

    // -----------------------------------------------------------------------
    // --- insert metadata into the system

    UserSession us = context.getUserSession();

    if (us.getUserId() == null) throw new NoApplicableCodeEx("User not authenticated.");

    String profile = us.getProfile();

    // Only editors and above are allowed to insert metadata
    if (!profile.equals(Geonet.Profile.EDITOR)
        && !profile.equals(Geonet.Profile.REVIEWER)
        && !profile.equals(Geonet.Profile.USER_ADMIN)
        && !profile.equals(Geonet.Profile.ADMINISTRATOR))
      throw new NoApplicableCodeEx("User not allowed to insert metadata.");

    int userId = us.getUserIdAsInt();

    AccessManager am = gc.getAccessManager();
    Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB);

    // Set default group: user first group
    Set<String> userGroups = am.getVisibleGroups(dbms, userId);
    String group;
    if (userGroups.isEmpty()) {
      group = null;
    } else {
      group = (String) userGroups.iterator().next();
    }
    //
    // insert metadata
    //
    String docType = null, title = null, isTemplate = null;
    boolean ufo = true, indexImmediate = false;
    String id =
        dataMan.insertMetadata(
            context,
            dbms,
            schema,
            xml,
            context.getSerialFactory().getSerial(dbms, "Metadata"),
            uuid,
            userId,
            group,
            source,
            isTemplate,
            docType,
            title,
            category,
            createDate,
            changeDate,
            ufo,
            indexImmediate);

    if (id == null) return false;

    // Set metadata as public if setting enabled
    SettingManager sm = gc.getSettingManager();
    boolean metadataPublic = sm.getValueAsBool("system/csw/metadataPublic", false);

    if (metadataPublic) {
      dataMan.setOperation(context, dbms, id, "1", AccessManager.OPER_VIEW);
    }

    dataMan.indexMetadata(dbms, id);

    fileIds.add(uuid);

    dbms.commit();
    toIndex.add(id);
    return true;
  }
Ejemplo n.º 5
0
  private String getSiteId() {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SettingManager sm = gc.getBean(SettingManager.class);

    return sm.getValue("system/site/siteId");
  }