package org.jmotor.restful.response.status;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Date;

/**
 * Component:
 * Description:
 * Date: 14-4-29
 *
 * @author Andy Ai
 */
public class Created implements Status {
    private String uri;
    private String identity;
    private Date createdAt;

    /**
     * Build response
     *
     * @param parameters [0]: base uri
     *                   [1]: identity
     * @return response entity
     */
    @Override
    public Response build(Object... parameters) {
        Created created = new Created();
        String identity = String.valueOf(parameters[1]);
        String url = String.valueOf(parameters[0]) + "/" + identity;
        created.setUri(url);
        created.setIdentity(identity);
        created.setCreatedAt(new Date());
        return Response.status(Response.Status.CREATED).entity(created).type(MediaType.APPLICATION_JSON_TYPE).build();
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    public String getIdentity() {
        return identity;
    }

    public void setIdentity(String identity) {
        this.identity = identity;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }
}

@@ -442,24 +442,65 @@
 %5D: identity%0A
+     *                   %5B2%5D: created at%0A
      * @retu
@@ -514,24 +514,24 @@
 onse entity%0A
-
      */%0A    
@@ -753,24 +753,195 @@
 + identity;%0A
+        Date createdAt;%0A        if (parameters.length == 3) %7B%0A            createdAt = (Date) parameters%5B2%5D;%0A        %7D else %7B%0A            createdAt = new Date();%0A        %7D%0A
         crea
@@ -1025,26 +1025,25 @@
 eatedAt(
-new Date()
+createdAt
 );%0A     

Add args: created at