ingo@11: package de.intevation.flys.client.server;
ingo@11:
ingo@11: import org.w3c.dom.Document;
ingo@11:
sascha@845: import java.util.ArrayList;
sascha@845: import java.util.List;
sascha@845: import java.util.Map;
sascha@843:
ingo@11: import com.google.gwt.user.server.rpc.RemoteServiceServlet;
ingo@11:
ingo@14: import de.intevation.artifacts.common.utils.ClientProtocolUtils;
sascha@845: import de.intevation.artifacts.common.utils.CreationFilter;
ingo@11:
ingo@14: import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
ingo@14: import de.intevation.artifacts.httpclient.http.HttpClient;
ingo@14: import de.intevation.artifacts.httpclient.http.HttpClientImpl;
ingo@11:
ingo@215: import de.intevation.flys.client.shared.exceptions.ServerException;
ingo@11: import de.intevation.flys.client.shared.model.Artifact;
ingo@11: import de.intevation.flys.client.client.services.ArtifactService;
ingo@11:
sascha@843: import de.intevation.flys.client.shared.model.Recommendation;
ingo@11:
ingo@11: /**
ingo@11: * This interface provides artifact specific services as CREATE, DESCRIBE, FEED,
ingo@11: * ADVANCE and OUT.
ingo@11: *
ingo@11: * @author Ingo Weinzierl
ingo@11: */
ingo@11: public class ArtifactServiceImpl
ingo@11: extends RemoteServiceServlet
ingo@11: implements ArtifactService
ingo@11: {
ingo@215: /** The error message key that is thrown if an error occured while artifact
ingo@215: * creation.*/
ingo@215: public static final String ERROR_CREATE_ARTIFACT = "error_create_artifact";
ingo@215:
ingo@215:
ingo@803: public Artifact create(
sascha@843: String serverUrl,
sascha@843: String locale,
sascha@843: String factory,
sascha@843: Recommendation recommendation
sascha@843: )
ingo@215: throws ServerException
ingo@215: {
ingo@229: System.out.println("ArtifactServiceImpl.create");
ingo@229:
sascha@845: String uuid;
sascha@845: String ids;
sascha@845: CreationFilter filter;
ingo@803:
sascha@845: if (recommendation != null) {
sascha@845: uuid = recommendation.getMasterArtifact();
sascha@845: ids = recommendation.getIDs();
sascha@845: filter = convertFilter(recommendation.getFilter());
ingo@803: }
ingo@803: else {
sascha@845: uuid = null;
sascha@845: ids = null;
sascha@845: filter = null;
ingo@803: }
ingo@803:
sascha@845: Document create = ClientProtocolUtils.newCreateDocument(
sascha@845: factory, uuid, ids, filter);
sascha@845:
ingo@229: HttpClient client = new HttpClientImpl(serverUrl, locale);
ingo@11:
ingo@14: try {
ingo@14: return (Artifact) client.create(create, new FLYSArtifactCreator());
ingo@14: }
ingo@14: catch (ConnectionException ce) {
ingo@14: System.err.println(ce.getLocalizedMessage());
ingo@14: }
ingo@14:
ingo@215: throw new ServerException(ERROR_CREATE_ARTIFACT);
ingo@11: }
sascha@845:
sascha@845: public static CreationFilter convertFilter(Recommendation.Filter filter) {
sascha@845:
sascha@845: if (filter == null) {
sascha@845: return null;
sascha@845: }
sascha@845:
sascha@845: CreationFilter cf = new CreationFilter();
sascha@845:
sascha@845: Map> outs = filter.getOuts();
sascha@845:
sascha@845: for (Map.Entry> entry:
sascha@845: outs.entrySet()) {
sascha@845: List rfs = entry.getValue();
sascha@845: List cfs =
sascha@845: new ArrayList(rfs.size());
sascha@845: for (Recommendation.Facet rf: rfs) {
sascha@845: cfs.add(new CreationFilter.Facet(rf.getName(), rf.getIndex()));
sascha@845: }
sascha@845: cf.add(entry.getKey(), cfs);
sascha@845: }
sascha@845:
sascha@845: return cf;
sascha@845: }
ingo@11: }
ingo@11: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :