sascha@262: package de.intevation.flys.client.server; sascha@262: sascha@276: import org.w3c.dom.Document; sascha@276: import org.w3c.dom.Element; sascha@262: ingo@1367: import org.apache.log4j.Logger; ingo@1367: sascha@262: import com.google.gwt.user.server.rpc.RemoteServiceServlet; sascha@262: sascha@276: import de.intevation.artifacts.common.ArtifactNamespaceContext; sascha@276: sascha@276: import de.intevation.artifacts.common.utils.XMLUtils; sascha@276: sascha@262: import de.intevation.flys.client.shared.exceptions.ServerException; sascha@262: sascha@262: import de.intevation.flys.client.client.services.MetaDataService; sascha@262: sascha@276: import de.intevation.artifacts.httpclient.exceptions.ConnectionException; sascha@276: sascha@276: import de.intevation.artifacts.httpclient.http.HttpClient; sascha@276: import de.intevation.artifacts.httpclient.http.HttpClientImpl; sascha@276: sascha@278: import de.intevation.flys.client.shared.model.DataCageTree; sascha@278: sascha@286: import de.intevation.flys.client.server.meta.Converter; sascha@286: felix@3346: /** felix@3346: * Service that returns certain meta-data from the backends data, polished to felix@3346: * inclusion into current project. felix@3346: */ sascha@262: public class MetaDataServiceImpl sascha@262: extends RemoteServiceServlet sascha@262: implements MetaDataService sascha@262: { felix@3346: /** Our very own logger. */ ingo@1367: private static final Logger logger = ingo@1367: Logger.getLogger(MetaDataServiceImpl.class); ingo@1367: sascha@276: public static final String ERROR_NO_META_DATA_FOUND = sascha@276: "error_no_meta_data_found"; sascha@276: felix@3346: felix@3346: /** felix@3346: * @param locale needed for i18n. felix@3346: * @param artifactId ID of masterartifact (can be null) felix@3346: * @param userId can be null felix@3346: * @param outs can be null felix@4870: * @param parameters can be null or parameters like "load-system:true;key:value" felix@3346: */ sascha@827: @Override sascha@811: public DataCageTree getMetaData( sascha@811: String locale, sascha@811: String artifactId, sascha@827: String userId, ingo@916: String outs, ingo@916: String parameters sascha@811: ) throws ServerException sascha@262: { ingo@1367: logger.info("MetaDataService.getMetaData"); sascha@276: felix@1442: // Create the query document. raimund@1425: String url = getServletContext().getInitParameter("server-url"); raimund@1425: sascha@276: Document doc = XMLUtils.newDocument(); sascha@276: sascha@276: XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( sascha@276: doc, sascha@276: ArtifactNamespaceContext.NAMESPACE_URI, sascha@276: ArtifactNamespaceContext.NAMESPACE_PREFIX); sascha@276: sascha@812: Element meta = ec.create("meta"); sascha@276: sascha@811: if (artifactId != null) { sascha@811: Element artifactEl = ec.create("artifact-id"); sascha@811: artifactEl.setAttribute("value", artifactId); sascha@812: meta.appendChild(artifactEl); sascha@811: } sascha@276: sascha@811: if (userId != null) { sascha@811: Element userEl = ec.create("user-id"); sascha@811: userEl.setAttribute("value", userId); sascha@812: meta.appendChild(userEl); sascha@811: } sascha@276: sascha@827: if (outs != null) { sascha@827: Element outsEl = ec.create("outs"); sascha@827: outsEl.setAttribute("value", outs); sascha@827: meta.appendChild(outsEl); sascha@827: } sascha@827: ingo@916: if (parameters != null) { ingo@916: Element paramsEl = ec.create("parameters"); ingo@916: paramsEl.setAttribute("value", parameters); ingo@916: meta.appendChild(paramsEl); ingo@916: } ingo@916: sascha@812: doc.appendChild(meta); sascha@812: felix@1442: // Fire. sascha@276: HttpClient client = new HttpClientImpl(url, locale); sascha@276: sascha@276: try { sascha@286: Converter converter = new Converter(); sascha@286: return converter.convert(client.callService(url, "metadata", doc)); sascha@276: } sascha@276: catch (ConnectionException ce) { sascha@812: ce.printStackTrace(); sascha@276: } sascha@276: sascha@276: throw new ServerException(ERROR_NO_META_DATA_FOUND); sascha@262: } sascha@262: } sascha@262: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :