src/main/java/org/willian/owb2infa/helper/infa/INFAMapTarget.java
private void createLKPforTarget(MetadataOperator targetOP, Folder folder,
			Mapping mapping, MetadataMapping owbMapping,
			HashMap<String, RowSet> expInputSetHM)
			throws InvalidTransformationException {

		String tgtName = targetOP.getName();

		tgtName = INFAUtils.toCamelCase(tgtName);

		String tgtBoundName = targetOP.getBoundName();

		if (tgtBoundName == null) {
			tgtBoundName = targetOP.getName();
		}
		HelperBase.printSplitLine(logger);
		logger.debug("Ready to construct the connected lookup transform for target "
				+ tgtName);
		HelperBase.printSplitLine(logger);

		String transName = INFAPropConstants.getINFATransPrefix("LOOKUP")
				+ tgtName;

		logger.debug("Get business keys");
		MetadataGroup group = targetOP.getGroups().get(0);

		ArrayList<MetadataField> bizFields = group.getBusinessKeyList();

		ArrayList<InputSet> allInputSets = new ArrayList<InputSet>();

		StringBuffer condition = new StringBuffer();

		String dummyExpr1 = INFAPropConstants.getINFATransPrefix("EXPRESSION")
				+ tgtName;

		RowSet expRS = INFAUtils.getExpRowSet(expInputSetHM, dummyExpr1);

		logger.debug("Get rowset of dummy expression 1 ");

		ArrayList<Field> includeFields = new ArrayList<Field>();
		java.util.Hashtable<Field, Object> link = new java.util.Hashtable<Field, Object>();

		for (MetadataField mField : bizFields) {

			if (expRS != null) {

				Field iField = expRS.getField(mField.getName());

				logger.debug("Get upward field " + iField.getName());

				// Use the same sourcing field
				Field tField = INFAUtils.convertToField(mField,
						FieldType.TRANSFORM);

				logger.debug("Get target field " + tField.getName());

				String bizKeyName = tField.getName();
				// Rename incoming fields
				tField.setName("IN_" + bizKeyName);

				if (iField != null && tField != null) {
					link.put(iField, tField);
					includeFields.add(iField);

					logger.debug("Link upward field " + iField.getName()
							+ " to target field " + tField.getName());

				}

				String clause = iField.getName() + " = " + tField.getName();

				if (condition.length() > 0) {
					condition.append(" AND " + clause);
				} else {
					condition.append(clause);

				}
				logger.debug("...Add biz key " + bizKeyName + " as "
						+ tField.getName());

			} else {
				logger.error("Can't find the export RowSet for dummy expression 1 ");
			}

		}

		logger.debug("Construct the lookup condition as : "
				+ condition.toString());

		if (expRS != null) {
			PortPropagationContext linkPropContext = PortPropagationContextFactory
					.getContextForIncludeCols(includeFields);
			PortLinkContext linkContext = PortLinkContextFactory
					.getPortLinkContextByMap(link);

			InputSet inSet = new InputSet(expRS, linkPropContext, linkContext);

			allInputSets.add(inSet);

			logger.debug("Construct the allInputSets for lookup transform");

			String checkName = INFAPropConstants.getINFATransPrefix("TARGET")
					+ tgtBoundName;

			ShortCut scTgt = INFAUtils.getShortCutFromFolder(folder, checkName,
					RepositoryObjectConstants.OBJTYPE_TARGET);
			SourceTarget lookupTable = null;
			if (scTgt == null) {

				scTgt = INFAUtils.getShortCutFromFolder(folder, checkName,
						RepositoryObjectConstants.OBJTYPE_SOURCE);

				if (scTgt == null) {
					lookupTable = folder.getTarget(tgtBoundName);

					if (lookupTable != null) {
						logger.debug("Get target from folder");
					}
				} else {

					lookupTable = (Source) scTgt.getRefObject();

					logger.debug("Get source table from shortcut");

				}
			} else {
				lookupTable = (Target) scTgt.getRefObject();

				logger.debug("Get target table from shortcut");
			}

			logger.debug("To get primary key");

			TransformHelper helper = new TransformHelper(mapping);

			OutputSet lkpOutputSet = helper.lookup(allInputSets, lookupTable,
					condition.toString(), transName);

			RowSet lookupRS = (RowSet) lkpOutputSet.getRowSets().get(0);

			INFAUtils.addToExpRowSetHM(expInputSetHM, transName, lookupRS);

			logger.debug("The connected lookup transform has been added into mapping");

		} else {
			logger.error("Can't find the rowset for dummy expression 1 ");
		}
	}
/*
	 * The connected lookup transformation is to identify whether the record is
	 * existed in target and hence determine insert or update
	 */
The connected lookup transformation is to identify whether the record is
existed in target and hence determine insert or update
The connected lookup transformation is to identify whether the record is existed in target and hence determine insert or update
private void createLKPforTarget(MetadataOperator targetOP, Folder folder,
			Mapping mapping, MetadataMapping owbMapping,
			HashMap<String, RowSet> expInputSetHM)
			throws InvalidTransformationException {
		String tgtName = targetOP.getName();
		tgtName = INFAUtils.toCamelCase(tgtName);
		String tgtBoundName = targetOP.getBoundName();
		if (tgtBoundName == null) {
			tgtBoundName = targetOP.getName();
		}
		HelperBase.printSplitLine(logger);
		logger.debug("Ready to construct the connected lookup transform for target "
				+ tgtName);
		HelperBase.printSplitLine(logger);
		String transName = INFAPropConstants.getINFATransPrefix("LOOKUP")
				+ tgtName;
		logger.debug("Get business keys");
		MetadataGroup group = targetOP.getGroups().get(0);
		ArrayList<MetadataField> bizFields = group.getBusinessKeyList();
		ArrayList<InputSet> allInputSets = new ArrayList<InputSet>();
		StringBuffer condition = new StringBuffer();
		String dummyExpr1 = INFAPropConstants.getINFATransPrefix("EXPRESSION")
				+ tgtName;
		RowSet expRS = INFAUtils.getExpRowSet(expInputSetHM, dummyExpr1);
		logger.debug("Get rowset of dummy expression 1 ");
		ArrayList<Field> includeFields = new ArrayList<Field>();
		java.util.Hashtable<Field, Object> link = new java.util.Hashtable<Field, Object>();
		for (MetadataField mField : bizFields) {
			if (expRS != null) {
				Field iField = expRS.getField(mField.getName());
				logger.debug("Get upward field " + iField.getName());
				Field tField = INFAUtils.convertToField(mField,
						FieldType.TRANSFORM);
				logger.debug("Get target field " + tField.getName());
				String bizKeyName = tField.getName();
				tField.setName("IN_" + bizKeyName);
				if (iField != null && tField != null) {
					link.put(iField, tField);
					includeFields.add(iField);
					logger.debug("Link upward field " + iField.getName()
							+ " to target field " + tField.getName());
				}
				String clause = iField.getName() + " = " + tField.getName();
				if (condition.length() > 0) {
					condition.append(" AND " + clause);
				} else {
					condition.append(clause);
				}
				logger.debug("...Add biz key " + bizKeyName + " as "
						+ tField.getName());
			} else {
				logger.error("Can't find the export RowSet for dummy expression 1 ");
			}
		}
		logger.debug("Construct the lookup condition as : "
				+ condition.toString());
		if (expRS != null) {
			PortPropagationContext linkPropContext = PortPropagationContextFactory
					.getContextForIncludeCols(includeFields);
			PortLinkContext linkContext = PortLinkContextFactory
					.getPortLinkContextByMap(link);
			InputSet inSet = new InputSet(expRS, linkPropContext, linkContext);
			allInputSets.add(inSet);
			logger.debug("Construct the allInputSets for lookup transform");
			String checkName = INFAPropConstants.getINFATransPrefix("TARGET")
					+ tgtBoundName;
			ShortCut scTgt = INFAUtils.getShortCutFromFolder(folder, checkName,
					RepositoryObjectConstants.OBJTYPE_TARGET);
			SourceTarget lookupTable = null;
			if (scTgt == null) {
				scTgt = INFAUtils.getShortCutFromFolder(folder, checkName,
						RepositoryObjectConstants.OBJTYPE_SOURCE);
				if (scTgt == null) {
					lookupTable = folder.getTarget(tgtBoundName);
					if (lookupTable != null) {
						logger.debug("Get target from folder");
					}
				} else {
					lookupTable = (Source) scTgt.getRefObject();
					logger.debug("Get source table from shortcut");
				}
			} else {
				lookupTable = (Target) scTgt.getRefObject();
				logger.debug("Get target table from shortcut");
			}
			logger.debug("To get primary key");
			TransformHelper helper = new TransformHelper(mapping);
			OutputSet lkpOutputSet = helper.lookup(allInputSets, lookupTable,
					condition.toString(), transName);
			RowSet lookupRS = (RowSet) lkpOutputSet.getRowSets().get(0);
			INFAUtils.addToExpRowSetHM(expInputSetHM, transName, lookupRS);
			logger.debug("The connected lookup transform has been added into mapping");
		} else {
			logger.error("Can't find the rowset for dummy expression 1 ");
		}
	}
private void createLKPforTarget ( MetadataOperator targetOP , Folder folder , Mapping mapping , MetadataMapping owbMapping , HashMap < String , RowSet > expInputSetHM ) throws InvalidTransformationException { String tgtName = targetOP . getName ( ) ; tgtName = INFAUtils . toCamelCase ( tgtName ) ; String tgtBoundName = targetOP . getBoundName ( ) ; if ( tgtBoundName == null ) { tgtBoundName = targetOP . getName ( ) ; } HelperBase . printSplitLine ( logger ) ; logger . debug ( "Ready to construct the connected lookup transform for target " + tgtName ) ; HelperBase . printSplitLine ( logger ) ; String transName = INFAPropConstants . getINFATransPrefix ( "LOOKUP" ) + tgtName ; logger . debug ( "Get business keys" ) ; MetadataGroup group = targetOP . getGroups ( ) . get ( 0 ) ; ArrayList < MetadataField > bizFields = group . getBusinessKeyList ( ) ; ArrayList < InputSet > allInputSets = new ArrayList < InputSet > ( ) ; StringBuffer condition = new StringBuffer ( ) ; String dummyExpr1 = INFAPropConstants . getINFATransPrefix ( "EXPRESSION" ) + tgtName ; RowSet expRS = INFAUtils . getExpRowSet ( expInputSetHM , dummyExpr1 ) ; logger . debug ( "Get rowset of dummy expression 1 " ) ; ArrayList < Field > includeFields = new ArrayList < Field > ( ) ; java . util . Hashtable < Field , Object > link = new java . util . Hashtable < Field , Object > ( ) ; for ( MetadataField mField : bizFields ) { if ( expRS != null ) { Field iField = expRS . getField ( mField . getName ( ) ) ; logger . debug ( "Get upward field " + iField . getName ( ) ) ; Field tField = INFAUtils . convertToField ( mField , FieldType . TRANSFORM ) ; logger . debug ( "Get target field " + tField . getName ( ) ) ; String bizKeyName = tField . getName ( ) ; tField . setName ( "IN_" + bizKeyName ) ; if ( iField != null && tField != null ) { link . put ( iField , tField ) ; includeFields . add ( iField ) ; logger . debug ( "Link upward field " + iField . getName ( ) + " to target field " + tField . getName ( ) ) ; } String clause = iField . getName ( ) + " = " + tField . getName ( ) ; if ( condition . length ( ) > 0 ) { condition . append ( " AND " + clause ) ; } else { condition . append ( clause ) ; } logger . debug ( "...Add biz key " + bizKeyName + " as " + tField . getName ( ) ) ; } else { logger . error ( "Can't find the export RowSet for dummy expression 1 " ) ; } } logger . debug ( "Construct the lookup condition as : " + condition . toString ( ) ) ; if ( expRS != null ) { PortPropagationContext linkPropContext = PortPropagationContextFactory . getContextForIncludeCols ( includeFields ) ; PortLinkContext linkContext = PortLinkContextFactory . getPortLinkContextByMap ( link ) ; InputSet inSet = new InputSet ( expRS , linkPropContext , linkContext ) ; allInputSets . add ( inSet ) ; logger . debug ( "Construct the allInputSets for lookup transform" ) ; String checkName = INFAPropConstants . getINFATransPrefix ( "TARGET" ) + tgtBoundName ; ShortCut scTgt = INFAUtils . getShortCutFromFolder ( folder , checkName , RepositoryObjectConstants . OBJTYPE_TARGET ) ; SourceTarget lookupTable = null ; if ( scTgt == null ) { scTgt = INFAUtils . getShortCutFromFolder ( folder , checkName , RepositoryObjectConstants . OBJTYPE_SOURCE ) ; if ( scTgt == null ) { lookupTable = folder . getTarget ( tgtBoundName ) ; if ( lookupTable != null ) { logger . debug ( "Get target from folder" ) ; } } else { lookupTable = ( Source ) scTgt . getRefObject ( ) ; logger . debug ( "Get source table from shortcut" ) ; } } else { lookupTable = ( Target ) scTgt . getRefObject ( ) ; logger . debug ( "Get target table from shortcut" ) ; } logger . debug ( "To get primary key" ) ; TransformHelper helper = new TransformHelper ( mapping ) ; OutputSet lkpOutputSet = helper . lookup ( allInputSets , lookupTable , condition . toString ( ) , transName ) ; RowSet lookupRS = ( RowSet ) lkpOutputSet . getRowSets ( ) . get ( 0 ) ; INFAUtils . addToExpRowSetHM ( expInputSetHM , transName , lookupRS ) ; logger . debug ( "The connected lookup transform has been added into mapping" ) ; } else { logger . error ( "Can't find the rowset for dummy expression 1 " ) ; } }
The connected lookup transformation is to identify whether the record is
 existed in target and hence determine insert or update
The connected lookup transformation is to identify whether the record is existed in target and hence determine insert or update
// Use the same sourcing field
 // Rename incoming fields
