/*
 * Copyright © 2010 Red Hat, Inc.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.redhat.rhevm.api.common.resource;

import java.util.UUID;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import com.redhat.rhevm.api.model.Action;
import com.redhat.rhevm.api.model.Link;
import com.redhat.rhevm.api.resource.ActionResource;

public class BaseActionResource implements ActionResource {

    private Action action;

    BaseActionResource(UriInfo uriInfo, Action action) {
        this.action = action;
        action.setId(UUID.randomUUID().toString());
        addLinks(uriInfo);
    }

    @Override
    public Response get(UriInfo uriInfo) {
        return Response.ok(action).build();
    }

    @Override
    public Action getAction() {
        return action;
    }

    private void addLinks(UriInfo uriInfo) {
        Link self = new Link();
        self.setRel("replay");
        self.setHref(uriInfo.getRequestUri().toString());
        action.getLink().add(self);

        Link replay = new Link();
        replay.setRel("self");
        replay.setHref(uriInfo.getRequestUriBuilder().path(action.getId()).build().toString());
        action.getLink().add(replay);
    }
}

@@ -1589,20 +1589,22 @@
    Link 
-self
+replay
  = new L
@@ -1614,28 +1614,30 @@
 ();%0A        
-self
+replay
 .setRel(%22rep
@@ -1651,20 +1651,22 @@
         
-self
+replay
 .setHref
@@ -1732,20 +1732,22 @@
 k().add(
-self
+replay
 );%0A%0A    
@@ -1747,38 +1747,36 @@
 ;%0A%0A        Link 
-replay
+self
  = new Link();%0A 
@@ -1774,38 +1774,36 @@
 Link();%0A        
-replay
+self
 .setRel(%22self%22);
@@ -1803,38 +1803,36 @@
 self%22);%0A        
-replay
+self
 .setHref(uriInfo
@@ -1926,22 +1926,20 @@
 k().add(
-replay
+self
 );%0A    %7D

Fix link variable names in BaseActionResource