/**
 * 
 */
package com.github.podd.resources;

import java.util.HashMap;
import java.util.Map;

import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import org.restlet.security.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.podd.restlet.PoddAction;
import com.github.podd.restlet.RestletUtils;
import com.github.podd.utils.PoddWebConstants;

/**
 * 
 * TODO: Empty class with logic not implemented
 * 
 * Delete an artifact from PODD. 
 * 
 * @author kutila
 * 
 */
public class DeleteArtifactResourceImpl extends AbstractPoddResourceImpl
{
    
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    
    @Get
    public Representation editArtifactPageHtml(final Representation entity) throws ResourceException
    {
        this.checkAuthentication(PoddAction.ARTIFACT_CREATE, null);
        
        this.log.info("deleteArtifactHtml");
        final User user = this.getRequest().getClientInfo().getUser();
        
        this.log.info("authenticated user: {}", user);
        
        final Map<String, Object> dataModel = RestletUtils.getBaseDataModel(this.getRequest());
        dataModel.put("contentTemplate", "index.html.ftl");
        dataModel.put("pageTitle", "TODO: Delete Artifact");
        
        final Map<String, Object> artifactDataMap = this.getRequestedArtifact();
        dataModel.put("requestedArtifact", artifactDataMap);
        
        // Output the base template, with contentTemplate from the dataModel defining the
        // template to use for the content in the body of the page
        return RestletUtils.getHtmlRepresentation(PoddWebConstants.PROPERTY_TEMPLATE_BASE, dataModel,
                MediaType.TEXT_HTML, this.getPoddApplication().getTemplateConfiguration());
    }
    
    // FIXME: populating dummy info for test
    private Map<String, Object> getRequestedArtifact()
    {
        final Map<String, Object> testArtifactMap = new HashMap<String, Object>();
        testArtifactMap.put("TODO: ", "Implement DeleteArtifactResourceImpl");
        
        final Map<String, String> roleMap = new HashMap<String, String>();
        roleMap.put("description", "A dummy user account for testing");
        testArtifactMap.put("repositoryRole", roleMap);
            
        return testArtifactMap;
    }
    
}

@@ -148,37 +148,105 @@
 let.
-representation.Representation
+data.Status;%0Aimport org.restlet.representation.Representation;%0Aimport org.restlet.resource.Delete
 ;%0Aim
@@ -353,24 +353,75 @@
 urity.User;%0A
+import org.semanticweb.owlapi.model.OWLOntologyID;%0A
 import org.s
@@ -694,17 +694,16 @@
 om PODD.
- 
 %0A * %0A * 
@@ -2000,24 +2000,504 @@
 %0A    %7D%0A    %0A
+    @Delete%0A    public void deleteArtifact(final Representation entity) throws ResourceException%0A    %7B%0A        boolean result = this.getPoddApplication().getPoddArtifactManager().deleteArtifact(new OWLOntologyID());%0A        %0A        if(result)%0A        %7B%0A            this.getResponse().setStatus(Status.SUCCESS_NO_CONTENT);%0A        %7D%0A        else%0A        %7B%0A            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, %22Could not delete artifact%22);%0A        %7D%0A    %7D%0A    %0A
     // FIXME
@@ -2968,28 +2968,24 @@
 p);%0A        
-    
 %0A        ret

add deleteArtifact to DeleteArtifactResourceImpl