ingo@937: package de.intevation.flys.artifacts; ingo@937: ingo@937: import java.util.HashMap; ingo@937: import java.util.List; ingo@937: import java.util.Map; ingo@937: ingo@937: import javax.xml.xpath.XPathConstants; ingo@937: ingo@937: import org.apache.log4j.Logger; ingo@937: ingo@937: import org.w3c.dom.Document; ingo@937: import org.w3c.dom.Element; ingo@937: import org.w3c.dom.Node; ingo@937: ingo@937: import de.intevation.artifacts.Artifact; ingo@937: import de.intevation.artifacts.ArtifactNamespaceContext; ingo@937: import de.intevation.artifacts.CallContext; ingo@937: import de.intevation.artifacts.Hook; ingo@937: ingo@937: import de.intevation.artifacts.common.utils.XMLUtils; ingo@940: import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; ingo@937: ingo@964: import de.intevation.artifactdatabase.state.Output; ingo@964: ingo@964: import de.intevation.flys.artifacts.services.meta.DataCage; ingo@964: ingo@937: ingo@937: public class CollectionMonitor implements Hook { ingo@937: ingo@940: public static final String XPATH_RESULT = "/art:result"; ingo@937: ingo@937: ingo@937: private static final Logger logger = ingo@937: Logger.getLogger(CollectionMonitor.class); ingo@937: ingo@937: ingo@937: @Override ingo@937: public void setup(Node cfg) { ingo@937: } ingo@937: ingo@937: ingo@937: @Override ingo@940: public void execute(Artifact artifact, CallContext context, Document doc) { ingo@937: FLYSArtifact flys = (FLYSArtifact) artifact; ingo@937: ingo@940: Element result = (Element) XMLUtils.xpath( ingo@940: doc, ingo@940: XPATH_RESULT, ingo@940: XPathConstants.NODE, ingo@940: ArtifactNamespaceContext.INSTANCE); ingo@937: ingo@940: ElementCreator creator = new ElementCreator( ingo@940: doc, ingo@940: ArtifactNamespaceContext.NAMESPACE_URI, ingo@940: ArtifactNamespaceContext.NAMESPACE_PREFIX); ingo@937: ingo@940: Element recommended = creator.create("recommended-artifacts"); ingo@964: result.appendChild(recommended); ingo@937: ingo@964: String[] outs = extractOutputNames(flys, context); ingo@964: Map params = getDataCageParameters(flys, context); ingo@940: ingo@964: DataCage dc = DataCage.getInstance(); ingo@964: dc.recommend(flys, outs, params, recommended); ingo@964: } ingo@964: ingo@964: ingo@964: public static String[] extractOutputNames( ingo@964: FLYSArtifact flys, ingo@964: CallContext context) ingo@964: { ingo@965: List outs = flys.getCurrentOutputs(context); ingo@964: String[] names = new String[outs.size()]; ingo@964: ingo@964: for (int i = 0, num = outs != null ? outs.size() : 0; i < num; i++) { ingo@964: names[i] = outs.get(i).getName(); ingo@937: } ingo@937: ingo@964: return names; ingo@964: } ingo@964: ingo@964: ingo@964: protected Map getDataCageParameters( ingo@964: FLYSArtifact flys, ingo@964: CallContext context) ingo@964: { ingo@964: Map params = new HashMap(1); ingo@964: params.put("recommended", "true"); ingo@964: ingo@964: return params; ingo@937: } ingo@937: } ingo@937: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :