示例#1
0
  public boolean checkName(String newname) {
    boolean exists = false;
    try {
      Organization org = user.getOrganization();
      for (Mapping m : DB.getMappingDAO().findByOrganization(org)) {
        if (m.getName().equalsIgnoreCase(newname)) {
          exists = true;
          break;
        }
      }

    } catch (Exception ex) {
      log.debug(" ERROR GETTING MAPPINGS:" + ex.getMessage());
    }
    return exists;
  }
示例#2
0
  @Action(value = "NewMapping")
  public String execute() throws Exception {
    if (selaction == null) {
      selaction = "";
    }
    Organization o;
    if (user.organization == null) {
      o = DB.getDatasetDAO().findById(uploadId, false).getOrganization();
      this.orgId = o.getDbID();

    } else {
      o = user.organization;
      this.orgId = user.getOrganization().getDbID();
    }
    findSchemas();
    if ("createschemanew".equals(selaction)) {
      if (mapName == null || mapName.length() == 0) {

        addActionError("Specify a mapping name!");
        return ERROR;
      }

      if (getSchemaSel() <= 0) {

        addActionError("No schema specified!");
        return ERROR;
      }

      Mapping mp = new Mapping();
      mp.setCreationDate(new java.util.Date());
      if (checkName(mapName) == true) {

        addActionError("Mapping name already exists!");
        return ERROR;
      }
      mp.setName(mapName);
      mp.setOrganization(o);
      // mp.setOrganization(user.getOrganization());
      if (getSchemaSel() > 0) {
        long schemaId = getSchemaSel();
        XmlSchema schema = DB.getXmlSchemaDAO().getById(schemaId, false);
        mp.setTargetSchema(schema);
        mp.setJsonString(schema.getJsonTemplate());
      }

      Dataset ds = DB.getDatasetDAO().findById(uploadId, false);

      // apply automatic mappings from schema configuration
      try {
        mp.applyConfigurationAutomaticMappings(ds);
      } catch (Exception e) {
        e.printStackTrace();
      }

      // if automatic mappings are enabled, try to apply them
      if (this.getAutomatic()) {
        try {
          mp.applyAutomaticMappings(ds);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      // if id mappings are required check if schema supports and map them
      if (this.getIdMappings()) {
        try {
          log.debug("Apply id mappings");
          mp.applyConfigurationAutomaticMappings(ds);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      // save mapping name to db and commit

      DB.getMappingDAO().makePersistent(mp);
      DB.commit();
      this.setSelectedMapping(mp.getDbID());
      this.url +=
          "?selectedMapping="
              + this.selectedMapping
              + "&uploadId="
              + this.uploadId
              + "&orgId="
              + this.orgId
              + "&userId="
              + this.user.getDbID()
              + "&selaction="
              + this.getSelaction();

      return "success";
    } else if ("uploadmapping".equals(selaction)) {
      if (this.upfile == null || upfile.length() == 0) {

        addActionError("Please upload a file first!");
        return ERROR;
      }
      if (mapName == null || mapName.length() == 0) {

        addActionError("Specify a mapping name!");
        return ERROR;
      }

      if (getSchemaSel() <= 0) {

        addActionError("No schema specified!");
        return ERROR;
      }

      Mapping mp = new Mapping();
      mp.setCreationDate(new java.util.Date());
      if (checkName(mapName) == true) {

        addActionError("Mapping name already exists!");
        return ERROR;
      }
      mp.setName(mapName);

      mp.setOrganization(o);

      String convertedMapping = null;
      if (upfile != null) {
        try {
          String dir = System.getProperty("java.io.tmpdir") + File.separator;
          File newmapping = new File(dir + upfile);
          StringBuffer contents = StringUtils.fileContents(newmapping);
          Mappings mappings = new Mappings(contents.toString());
          MappingConverter.upgradeToLatest(mappings);
        } catch (Exception e) { // Catch exception if any
          e.printStackTrace();

          System.err.println("Error importing file: " + e.getMessage());
          addActionError("Mappings import failed: " + e.getMessage());
          return ERROR;
        }
      }
      if (getSchemaSel() > 0) {
        long schemaId = getSchemaSel();
        XmlSchema schema = DB.getXmlSchemaDAO().getById(schemaId, false);
        mp.setTargetSchema(schema);

        if (convertedMapping != null) {
          mp.setJsonString(convertedMapping);
        } else {
          mp.setJsonString(schema.getJsonTemplate());
        }
      }

      // save mapping name to db and commit?

      DB.getMappingDAO().makePersistent(mp);
      DB.commit();
      this.setSelectedMapping(mp.getDbID());
      this.url +=
          "?selectedMapping="
              + this.selectedMapping
              + "&uploadId="
              + this.uploadId
              + "&orgId="
              + this.orgId
              + "&userId="
              + this.user.getDbID()
              + "&selaction="
              + this.getSelaction();

      return "success";
    } else if ("uploadxsl".equals(selaction)) {
      if (this.upfile == null || upfile.length() == 0) {

        addActionError("Please upload a file first!");
        return ERROR;
      }
      if (mapName == null || mapName.length() == 0) {

        addActionError("Specify a mapping name!");
        return ERROR;
      }

      Mapping mp = new Mapping();
      mp.setCreationDate(new java.util.Date());
      if (checkName(mapName) == true) {

        addActionError("Mapping name already exists!");
        return ERROR;
      }
      mp.setName(mapName);

      mp.setOrganization(o);

      String xsl = null;

      if (upfile != null) {
        try {
          String dir = System.getProperty("java.io.tmpdir") + File.separator;
          File newmapping = new File(dir + upfile);
          StringBuffer contents = StringUtils.fileContents(newmapping, true);
          xsl = contents.toString();
        } catch (Exception e) { // Catch exception if any
          e.printStackTrace();

          System.err.println("Error importing file: " + e.getMessage());
          addActionError("Mappings import failed: " + e.getMessage());
          return ERROR;
        }
      }

      if (getSchemaSel() > 0) {
        long schemaId = getSchemaSel();
        XmlSchema schema = DB.getXmlSchemaDAO().getById(schemaId, false);
        mp.setTargetSchema(schema);
      }

      if (xsl != null) {
        mp.setXsl(xsl);
      } else {
        System.err.println("Error importing xsl: xsl is null");
        addActionError("Mappings import failed: xsl is null");
        return ERROR;
      }

      // save mapping name to db and commit?

      DB.getMappingDAO().makePersistent(mp);
      DB.commit();
      this.setSelectedMapping(mp.getDbID());
      this.url =
          "successxsl?selectedMapping="
              + this.selectedMapping
              + "&uploadId="
              + this.uploadId
              + "&orgId="
              + this.orgId
              + "&userId="
              + this.user.getDbID()
              + "&selaction="
              + this.getSelaction();

      return "successxsl";
    } else {
      log.error("Unknown action");
      addActionError("Specify a mapping action!");

      return ERROR;
    }
  }
示例#3
0
 public void setSelectedMapping(long selectedMapping) {
   this.selectedMapping = selectedMapping;
   this.selmapping = DB.getMappingDAO().findById(this.selectedMapping, false);
 }