001package org.kuali.ole.ingest.resolver;
002
003import org.kuali.ole.OLEConstants;
004import org.kuali.ole.ingest.pojo.ProfileTerm;
005import org.kuali.rice.krms.api.engine.TermResolutionException;
006import org.kuali.rice.krms.api.engine.TermResolver;
007
008import java.util.Collections;
009import java.util.Map;
010import java.util.Set;
011
012/**
013 * Created by IntelliJ IDEA.
014 * User: pvsubrah
015 * Date: 3/28/12
016 * Time: 3:09 PM
017 * To change this template use File | Settings | File Templates.
018 */
019public abstract class AbstractProfileTermResolver implements TermResolver<Object> {
020    /**
021     *  This method gets the unique prerequisites based on OleConstant value.
022     * @return  prerequisite.
023     */
024    @Override
025    public Set<String> getPrerequisites() {
026        return Collections.singleton(OLEConstants.ISBN_TERM);
027    }
028
029    /**
030     * This method gets the empty immutable set of parameterNames
031     * @return  parameterNames.
032     */
033    @Override
034    public Set<String> getParameterNames() {
035        return Collections.emptySet();
036    }
037
038    /**
039     * Gets the cost attribute value
040     * @return  1.
041     */
042    @Override
043    public int getCost() {
044        return 1;
045    }
046
047    /**
048     *  Returns the resolved prerequisites as profileTerm object
049     * @param resolvedPrereqs
050     * @param parameters
051     * @return   profileTerm
052     * @throws org.kuali.rice.krms.api.engine.TermResolutionException
053     */
054    @Override
055    public Object resolve(Map<String, Object> resolvedPrereqs,
056                          Map<String, String> parameters) throws TermResolutionException {
057        ProfileTerm profileTerm = (ProfileTerm) resolvedPrereqs.get("ISBN Term");
058        if (profileTerm == null) {
059            throw new TermResolutionException("Failed to locate Patron prereq", this, parameters);
060        }
061        return resolveFromProfileTerm(profileTerm);
062    }
063
064    protected abstract Object resolveFromProfileTerm(ProfileTerm profileTerm);
065}