예제 #1
0
파일: MappingMeta.java 프로젝트: cnopens/BA
  public void saveRep(Repository rep, ObjectId id_transformation, ObjectId id_step)
      throws KettleException {
    rep.saveStepAttribute(
        id_transformation,
        id_step,
        "specification_method",
        specificationMethod == null ? null : specificationMethod.getCode());
    rep.saveStepAttribute(
        id_transformation,
        id_step,
        "trans_object_id",
        transObjectId == null ? null : transObjectId.toString());
    rep.saveStepAttribute(id_transformation, id_step, "filename", fileName); // $NON-NLS-1$
    rep.saveStepAttribute(id_transformation, id_step, "trans_name", transName); // $NON-NLS-1$
    rep.saveStepAttribute(
        id_transformation, id_step, "directory_path", directoryPath); // $NON-NLS-1$

    for (int i = 0; i < inputMappings.size(); i++) {
      inputMappings.get(i).saveRep(rep, id_transformation, id_step, "input_", i);
    }

    for (int i = 0; i < outputMappings.size(); i++) {
      outputMappings.get(i).saveRep(rep, id_transformation, id_step, "output_", i);
    }

    // save the mapping parameters too
    //
    mappingParameters.saveRep(rep, id_transformation, id_step);

    rep.saveStepAttribute(
        id_transformation, id_step, 0, "allow_multiple_input", allowingMultipleInputs);
    rep.saveStepAttribute(
        id_transformation, id_step, 0, "allow_multiple_output", allowingMultipleOutputs);
  }
예제 #2
0
파일: MappingMeta.java 프로젝트: cnopens/BA
  public String getXML() {
    StringBuffer retval = new StringBuffer(300);

    retval
        .append("    ")
        .append(
            XMLHandler.addTagValue(
                "specification_method",
                specificationMethod == null ? null : specificationMethod.getCode()));
    retval
        .append("    ")
        .append(
            XMLHandler.addTagValue(
                "trans_object_id", transObjectId == null ? null : transObjectId.toString()));
    // Export a little bit of extra information regarding the reference since it doesn't really
    // matter outside the same repository.
    //
    if (repository != null && transObjectId != null) {
      try {
        RepositoryObject objectInformation =
            repository.getObjectInformation(transObjectId, RepositoryObjectType.TRANSFORMATION);
        if (objectInformation != null) {
          transName = objectInformation.getName();
          directoryPath = objectInformation.getRepositoryDirectory().getPath();
        }
      } catch (KettleException e) {
        // Ignore object reference problems.  It simply means that the reference is no longer valid.
      }
    }
    retval.append("    ").append(XMLHandler.addTagValue("trans_name", transName)); // $NON-NLS-1$
    retval.append("    ").append(XMLHandler.addTagValue("filename", fileName)); // $NON-NLS-1$
    retval
        .append("    ")
        .append(XMLHandler.addTagValue("directory_path", directoryPath)); // $NON-NLS-1$

    retval
        .append("    ")
        .append(XMLHandler.openTag("mappings"))
        .append(Const.CR); // $NON-NLS-1$ $NON-NLS-2$

    retval
        .append("      ")
        .append(XMLHandler.openTag("input"))
        .append(Const.CR); // $NON-NLS-1$ $NON-NLS-2$
    for (int i = 0; i < inputMappings.size(); i++) {
      retval.append(inputMappings.get(i).getXML());
    }
    retval
        .append("      ")
        .append(XMLHandler.closeTag("input"))
        .append(Const.CR); // $NON-NLS-1$ $NON-NLS-2$

    retval
        .append("      ")
        .append(XMLHandler.openTag("output"))
        .append(Const.CR); // $NON-NLS-1$ $NON-NLS-2$
    for (int i = 0; i < outputMappings.size(); i++) {
      retval.append(outputMappings.get(i).getXML());
    }
    retval
        .append("      ")
        .append(XMLHandler.closeTag("output"))
        .append(Const.CR); // $NON-NLS-1$ $NON-NLS-2$

    // Add the mapping parameters too
    //
    retval.append("      ").append(mappingParameters.getXML()).append(Const.CR); // $NON-NLS-1$

    retval
        .append("    ")
        .append(XMLHandler.closeTag("mappings"))
        .append(Const.CR); // $NON-NLS-1$ $NON-NLS-2$

    retval
        .append("    ")
        .append(
            XMLHandler.addTagValue("allow_multiple_input", allowingMultipleInputs)); // $NON-NLS-1$
    retval
        .append("    ")
        .append(
            XMLHandler.addTagValue(
                "allow_multiple_output", allowingMultipleOutputs)); // $NON-NLS-1$

    return retval.toString();
  }
예제 #3
0
파일: MappingMeta.java 프로젝트: cnopens/BA
  public void readRep(
      Repository rep, ObjectId id_step, List<DatabaseMeta> databases, Map<String, Counter> counters)
      throws KettleException {
    String method = rep.getStepAttributeString(id_step, "specification_method");
    specificationMethod = ObjectLocationSpecificationMethod.getSpecificationMethodByCode(method);
    String transId = rep.getStepAttributeString(id_step, "trans_object_id");
    transObjectId = Const.isEmpty(transId) ? null : new StringObjectId(transId);
    transName = rep.getStepAttributeString(id_step, "trans_name"); // $NON-NLS-1$
    fileName = rep.getStepAttributeString(id_step, "filename"); // $NON-NLS-1$
    directoryPath = rep.getStepAttributeString(id_step, "directory_path"); // $NON-NLS-1$

    // Backward compatibility check for object specification
    //
    checkObjectLocationSpecificationMethod();
    inputMappings.clear();
    outputMappings.clear();

    int nrInput = rep.countNrStepAttributes(id_step, "input_field"); // $NON-NLS-1$
    int nrOutput = rep.countNrStepAttributes(id_step, "output_field"); // $NON-NLS-1$

    // Backward compatibility...
    //
    if (nrInput > 0 || nrOutput > 0) {
      MappingIODefinition inputMappingDefinition = new MappingIODefinition();
      inputMappingDefinition.setMainDataPath(true);

      for (int i = 0; i < nrInput; i++) {
        String inputField = rep.getStepAttributeString(id_step, i, "input_field"); // $NON-NLS-1$
        String inputMapping =
            rep.getStepAttributeString(id_step, i, "input_mapping"); // $NON-NLS-1$
        inputMappingDefinition
            .getValueRenames()
            .add(new MappingValueRename(inputField, inputMapping));
      }

      MappingIODefinition outputMappingDefinition = new MappingIODefinition();
      outputMappingDefinition.setMainDataPath(true);

      for (int i = 0; i < nrOutput; i++) {
        String outputField = rep.getStepAttributeString(id_step, i, "output_field"); // $NON-NLS-1$
        String outputMapping =
            rep.getStepAttributeString(id_step, i, "output_mapping"); // $NON-NLS-1$
        outputMappingDefinition
            .getValueRenames()
            .add(new MappingValueRename(outputMapping, outputField));
      }

      // Don't forget to add these to the input and output mapping
      // definitions...
      //
      inputMappings.add(inputMappingDefinition);
      outputMappings.add(outputMappingDefinition);

      // The default is to have no mapping parameters: the concept didn't exist
      // before.
      mappingParameters = new MappingParameters();
    } else {
      nrInput = rep.countNrStepAttributes(id_step, "input_main_path"); // $NON-NLS-1$
      nrOutput = rep.countNrStepAttributes(id_step, "output_main_path"); // $NON-NLS-1$

      for (int i = 0; i < nrInput; i++) {
        inputMappings.add(new MappingIODefinition(rep, id_step, "input_", i));
      }

      for (int i = 0; i < nrOutput; i++) {
        outputMappings.add(new MappingIODefinition(rep, id_step, "output_", i));
      }

      mappingParameters = new MappingParameters(rep, id_step);
    }

    allowingMultipleInputs =
        rep.getStepAttributeBoolean(id_step, 0, "allow_multiple_input", inputMappings.size() > 1);
    allowingMultipleOutputs =
        rep.getStepAttributeBoolean(id_step, 0, "allow_multiple_output", outputMappings.size() > 1);
  }
예제 #4
0
파일: MappingMeta.java 프로젝트: cnopens/BA
  public void loadXML(Node stepnode, List<DatabaseMeta> databases, Map<String, Counter> counters)
      throws KettleXMLException {
    try {
      String method = XMLHandler.getTagValue(stepnode, "specification_method");
      specificationMethod = ObjectLocationSpecificationMethod.getSpecificationMethodByCode(method);
      String transId = XMLHandler.getTagValue(stepnode, "trans_object_id");
      transObjectId = Const.isEmpty(transId) ? null : new StringObjectId(transId);

      transName = XMLHandler.getTagValue(stepnode, "trans_name"); // $NON-NLS-1$
      fileName = XMLHandler.getTagValue(stepnode, "filename"); // $NON-NLS-1$
      directoryPath = XMLHandler.getTagValue(stepnode, "directory_path"); // $NON-NLS-1$

      // Backward compatibility check for object specification
      //
      checkObjectLocationSpecificationMethod();

      Node mappingsNode = XMLHandler.getSubNode(stepnode, "mappings"); // $NON-NLS-1$
      inputMappings.clear();
      outputMappings.clear();

      if (mappingsNode != null) {
        // Read all the input mapping definitions...
        //
        Node inputNode = XMLHandler.getSubNode(mappingsNode, "input"); // $NON-NLS-1$
        int nrInputMappings =
            XMLHandler.countNodes(inputNode, MappingIODefinition.XML_TAG); // $NON-NLS-1$
        for (int i = 0; i < nrInputMappings; i++) {
          Node mappingNode = XMLHandler.getSubNodeByNr(inputNode, MappingIODefinition.XML_TAG, i);
          MappingIODefinition inputMappingDefinition = new MappingIODefinition(mappingNode);
          inputMappings.add(inputMappingDefinition);
        }
        Node outputNode = XMLHandler.getSubNode(mappingsNode, "output"); // $NON-NLS-1$
        int nrOutputMappings =
            XMLHandler.countNodes(outputNode, MappingIODefinition.XML_TAG); // $NON-NLS-1$
        for (int i = 0; i < nrOutputMappings; i++) {
          Node mappingNode = XMLHandler.getSubNodeByNr(outputNode, MappingIODefinition.XML_TAG, i);
          MappingIODefinition outputMappingDefinition = new MappingIODefinition(mappingNode);
          outputMappings.add(outputMappingDefinition);
        }

        // Load the mapping parameters too..
        //
        Node mappingParametersNode = XMLHandler.getSubNode(mappingsNode, MappingParameters.XML_TAG);
        mappingParameters = new MappingParameters(mappingParametersNode);
      } else {
        // backward compatibility...
        //
        Node inputNode = XMLHandler.getSubNode(stepnode, "input"); // $NON-NLS-1$
        Node outputNode = XMLHandler.getSubNode(stepnode, "output"); // $NON-NLS-1$

        int nrInput = XMLHandler.countNodes(inputNode, "connector"); // $NON-NLS-1$
        int nrOutput = XMLHandler.countNodes(outputNode, "connector"); // $NON-NLS-1$

        // null means: auto-detect
        //
        MappingIODefinition inputMappingDefinition = new MappingIODefinition();
        inputMappingDefinition.setMainDataPath(true);

        for (int i = 0; i < nrInput; i++) {
          Node inputConnector = XMLHandler.getSubNodeByNr(inputNode, "connector", i); // $NON-NLS-1$
          String inputField = XMLHandler.getTagValue(inputConnector, "field"); // $NON-NLS-1$
          String inputMapping = XMLHandler.getTagValue(inputConnector, "mapping"); // $NON-NLS-1$
          inputMappingDefinition
              .getValueRenames()
              .add(new MappingValueRename(inputField, inputMapping));
        }

        // null means: auto-detect
        //
        MappingIODefinition outputMappingDefinition = new MappingIODefinition();
        outputMappingDefinition.setMainDataPath(true);

        for (int i = 0; i < nrOutput; i++) {
          Node outputConnector =
              XMLHandler.getSubNodeByNr(outputNode, "connector", i); // $NON-NLS-1$
          String outputField = XMLHandler.getTagValue(outputConnector, "field"); // $NON-NLS-1$
          String outputMapping = XMLHandler.getTagValue(outputConnector, "mapping"); // $NON-NLS-1$
          outputMappingDefinition
              .getValueRenames()
              .add(new MappingValueRename(outputMapping, outputField));
        }

        // Don't forget to add these to the input and output mapping
        // definitions...
        //
        inputMappings.add(inputMappingDefinition);
        outputMappings.add(outputMappingDefinition);

        // The default is to have no mapping parameters: the concept didn't
        // exist before.
        //
        mappingParameters = new MappingParameters();
      }

      String multiInput = XMLHandler.getTagValue(stepnode, "allow_multiple_input");
      allowingMultipleInputs =
          Const.isEmpty(multiInput) ? inputMappings.size() > 1 : "Y".equalsIgnoreCase(multiInput);
      String multiOutput = XMLHandler.getTagValue(stepnode, "allow_multiple_output");
      allowingMultipleOutputs =
          Const.isEmpty(multiOutput)
              ? outputMappings.size() > 1
              : "Y".equalsIgnoreCase(multiOutput);

    } catch (Exception e) {
      throw new KettleXMLException(
          BaseMessages.getString(
              PKG, "MappingMeta.Exception.ErrorLoadingTransformationStepFromXML"),
          e); //$NON-NLS-1$
    }
  }