/** 
 * (C) Copyright 2012 Chiral Behaviors, LLC. All Rights Reserved
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *     
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
package com.chiralbehaviors.CoRE.access.resource;

import java.util.UUID;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.chiralbehaviors.CoRE.meta.Model;
import com.chiralbehaviors.CoRE.meta.models.ModelImpl;
import com.chiralbehaviors.CoRE.network.Aspect;
import com.chiralbehaviors.CoRE.network.Relationship;
import com.chiralbehaviors.CoRE.object.WorkspaceLoader;
import com.chiralbehaviors.CoRE.product.Product;
import com.chiralbehaviors.CoRE.workspace.Workspace;

/**
 * @author hparry
 * 
 */
@Path("/v{version : \\d+}/services/data/workspace")
public class WorkspaceResource {

    EntityManager em;
    Model         model;

    /**
     * @param emf
     */
    public WorkspaceResource(EntityManagerFactory emf) {
        em = emf.createEntityManager();
        model = new ModelImpl(em);
    }

    @GET
    @Path("/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public Workspace get(@PathParam("id") UUID productId,
                         @QueryParam("relId") UUID relId) {
        Product p = new Product();
        p.setId(productId);

        Relationship r = new Relationship();
        r.setId(relId);

        WorkspaceLoader loader = new WorkspaceLoader(p, r, model);
        return loader.getWorkspace();
    }

    //TODO hparry this returns an Aspect 
    @POST
    public Aspect<Product> importWorkspace(Workspace workspace) {
        return model.getWorkspaceModel().importWorkspace(workspace);
    }

}
@@ -1100,56 +1100,8 @@
 pl;%0A
-import com.chiralbehaviors.CoRE.network.Aspect;%0A
 impo
@@ -1307,16 +1307,77 @@
 rkspace;
+%0Aimport com.chiralbehaviors.CoRE.workspace.WorkspaceSnapshot;
 %0A%0A/**%0A *
@@ -2144,50 +2144,12 @@
   %7D%0A
-%0A
     
-//TODO hparry this returns an Aspect 
 %0A   
@@ -2170,23 +2170,12 @@
 lic 
-Aspect%3CProduct%3E
+void
  imp
@@ -2186,16 +2186,24 @@
 orkspace
+Snapshot
 (Workspa
@@ -2204,16 +2204,24 @@
 orkspace
+Snapshot
  workspa
@@ -2228,76 +2228,167 @@
 ce) 
-%7B%0A        return model.getWorkspaceModel().importWorkspace(workspace
+throws IllegalArgumentException, IllegalAccessException %7B%0A        em.getTransaction().begin();%0A        workspace.merge(em);%0A        em.getTransaction().commit(
 );%0A 

Add WorkspaceSnapshot import to WorkspaceResource