ingo@905: package de.intevation.flys.client.server;
ingo@905:
felix@913: import java.util.ArrayList;
felix@913:
ingo@905: import de.intevation.flys.client.shared.exceptions.ServerException;
ingo@905: import de.intevation.flys.client.shared.model.Artifact;
ingo@905: import de.intevation.flys.client.shared.model.Collection;
ingo@905: import de.intevation.flys.client.shared.model.Recommendation;
ingo@905:
ingo@905: import de.intevation.flys.client.client.services.LoadArtifactService;
ingo@905:
ingo@905: /**
ingo@905: * This service creates a new Artifact based on a given Recommendation and puts
ingo@905: * this new artifact into a specified Collection.
ingo@905: *
ingo@905: * @author Ingo Weinzierl
ingo@905: */
ingo@905: public class LoadArtifactServiceImpl
ingo@905: extends ArtifactServiceImpl
ingo@905: implements LoadArtifactService
ingo@905: {
ingo@905: public static final String ERROR_LOAD_ARTIFACT = "error_load_artifact";
ingo@905:
ingo@905: public Artifact load(
ingo@905: Collection parent,
ingo@905: Recommendation recom,
ingo@905: String factory,
ingo@905: String url,
ingo@905: String locale
ingo@905: )
ingo@905: throws ServerException {
ingo@905: System.out.println(
ingo@905: "LoadArtifactServiceImpl.load: " + recom.getMasterArtifact());
ingo@905:
ingo@905: // 1) Clone the Artifact specified in >>recom<<
ingo@905: Artifact clone = ArtifactHelper.createArtifact(
ingo@905: url, locale, factory, recom);
ingo@905:
ingo@905: if (clone != null) {
ingo@905: System.out.println("Successfully create Artifact Clone. Add now!");
ingo@905: Collection c = CollectionHelper.addArtifact(
ingo@905: parent, clone, url, locale);
ingo@905:
ingo@905: if (c != null) {
ingo@905: System.out.println("Successfully added Clone to Collection.");
ingo@905:
ingo@905: return clone;
ingo@905: }
ingo@905: }
ingo@905:
ingo@905: throw new ServerException(ERROR_LOAD_ARTIFACT);
ingo@905: }
felix@913:
felix@1272:
felix@1272: /**
felix@1272: * Clone one or more artifacts and add it to a collection.
felix@1272: *
felix@1272: * @param parent Collection where clones will be added to.
felix@1272: * @param recommendations definitions of source of clone.
felix@1272: * @param factory name of factory to use when cloning artifacts.
felix@1272: */
felix@913: public Artifact[] loadMany(
felix@1272: Collection parent,
felix@913: Recommendation[] recoms,
felix@1272: String factory,
felix@1272: String url,
felix@1272: String locale
felix@913: )
felix@913: throws ServerException {
felix@1272: System.out.println("LoadArtifactServiceImpl.loadMany: "
felix@1272: + recoms[0].getMasterArtifact());
felix@913: ArrayList artifacts = new ArrayList();
felix@913:
felix@1272: // TODO Respect the index of what to clone.
felix@1272:
felix@913: // 1) Clone the Artifacts specified in >>recom<<
felix@913: for (Recommendation recom : recoms) {
felix@913: Artifact clone = ArtifactHelper.createArtifact(
felix@913: url, locale, factory, recom);
felix@913:
felix@913: if (clone != null) {
felix@913: System.out.println("Successfully create Artifact Clone. Add now!");
felix@913: Collection c = CollectionHelper.addArtifact(
felix@913: parent, clone, url, locale);
felix@913:
felix@913: if (c != null) {
felix@913: System.out.println("Successfully added Clone to Collection.");
felix@913:
felix@913: artifacts.add(clone);
felix@913: }
felix@913: }
felix@913: }
felix@913: return artifacts.toArray(new Artifact[artifacts.size()]);
felix@913:
felix@913: //throw new ServerException(ERROR_LOAD_ARTIFACT);
felix@913: }
ingo@905: }
ingo@905: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :