001package org.kuali.ole.ingest.function;
002
003import org.apache.log4j.Logger;
004import org.kuali.ole.OLEConstants;
005import org.kuali.rice.krms.framework.engine.Function;
006
007import java.util.ArrayList;
008import java.util.List;
009
010/**
011 * OleContainsComparison is used for checking an argument contains in another argument.
012 */
013public class OleContainsComparison implements Function {
014    private static final Logger LOG = Logger.getLogger(OleContainsComparison.class);
015    /**
016     * This method takes the request and invoke the methods  for checking an argument contains in another argument.
017     * @param arguments
018     * @return  Object
019     */
020    @Override
021    public Object invoke(Object... arguments) {
022        LOG.debug(" --------- Inside OleContainsComparison ------------");
023        boolean result = true;
024        if(arguments!=null && arguments.length==2){
025            String operatorsCirculationLocations =arguments[0]!=null?(String) arguments[0]:"";
026            String itemLocation = arguments[1]!=null?(String) arguments[1]:"";
027            String[] splitOperatorLocationTerm = operatorsCirculationLocations.split(OLEConstants.DELIMITER_HASH);
028            String[] splitLocationTerm = itemLocation.split(OLEConstants.DELIMITER_HASH);
029            for(String itemLocationTerm: splitLocationTerm){
030                for(String location: splitOperatorLocationTerm){
031                    result = true;
032                    String[] splitTerm = itemLocationTerm.split("/");
033                    for(String term:splitTerm){
034                        result &= location.contains(term);
035                    }
036                    if(result){
037                        return result;
038                    }
039                }
040            }
041        }
042       return result;
043    }
044
045}