<commit_before>/**
 * 
 */
package com.github.podd.resources;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.openrdf.OpenRDFException;
import org.openrdf.model.URI;
import org.openrdf.repository.RepositoryConnection;
import org.restlet.data.MediaType;
import org.restlet.data.Status;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
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.PoddArtifact;
import com.github.podd.utils.PoddWebConstants;
import com.github.podd.utils.SparqlQueryHelper;

/**
 * 
 * Resource which allows listing artifacts in PODD.
 * 
 * This is only a simple implementation which lists all project URIs
 * TODO: list based on authorization, group projects. list project title, description, PI and lead institution
 * 
 * @author kutila
 * 
 */
public class ListArtifactsResourceImpl extends AbstractPoddResourceImpl
{
    
    private static final String LIST_PAGE_TITLE_TEXT = "PODD Project Listing";
    
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    
    /**
     * Handle http GET request to serve the list artifacts page.
     */
    @Get("html")
    public Representation getlistArtifactsPage(final Representation entity) throws ResourceException
    {
        this.checkAuthentication(PoddAction.UNPUBLISHED_ARTIFACT_READ, Collections.<URI> emptySet());
        
        this.log.info("@Get listArtifacts Page");
        
        final Map<String, Object> dataModel = RestletUtils.getBaseDataModel(this.getRequest());
        dataModel.put("contentTemplate", "projects.html.ftl");
        dataModel.put("pageTitle", ListArtifactsResourceImpl.LIST_PAGE_TITLE_TEXT);
        
        try
        {
            this.populateDataModelWithArtifactLists(dataModel);
        }
        catch(final OpenRDFException e)
        {
            throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Failed to populate data model");
        }
        
        // 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());
    }<commit_msg>Add partial implementation of Get(rdf) to ListArtifactsResourceImpl<commit_after>/**
 * 
 */
package com.github.podd.resources;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.openrdf.OpenRDFException;
import org.openrdf.model.URI;
import org.openrdf.repository.RepositoryConnection;
import org.restlet.data.MediaType;
import org.restlet.data.Status;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
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.InferredOWLOntologyID;
import com.github.podd.utils.PoddArtifact;
import com.github.podd.utils.PoddWebConstants;
import com.github.podd.utils.SparqlQueryHelper;

/**
 * 
 * Resource which allows listing artifacts in PODD.
 * 
 * This is only a simple implementation which lists all project URIs TODO: list based on
 * authorization, group projects. list project title, description, PI and lead institution
 * 
 * @author kutila
 * 
 */
public class ListArtifactsResourceImpl extends AbstractPoddResourceImpl
{
    
    private static final String LIST_PAGE_TITLE_TEXT = "PODD Project Listing";
    
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    
    /**
     * Handle http GET request to serve the list artifacts page.
     */
    @Get("html")
    public Representation getListArtifactsPage(final Representation entity) throws ResourceException
    {
        this.checkAuthentication(PoddAction.UNPUBLISHED_ARTIFACT_READ, Collections.<URI> emptySet());
        
        this.log.info("@Get listArtifacts Page");
        
        final Map<String, Object> dataModel = RestletUtils.getBaseDataModel(this.getRequest());
        dataModel.put("contentTemplate", "projects.html.ftl");
        dataModel.put("pageTitle", ListArtifactsResourceImpl.LIST_PAGE_TITLE_TEXT);
        
        try
        {
            this.populateDataModelWithArtifactLists(dataModel);
        }
        catch(final OpenRDFException e)
        {
            throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Failed to populate data model");
        }
        
        // 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());
    }
    
    @Get("rdf|rj|ttl")
    public Representation getListArtifactsRdf(final Representation entity) throws ResourceException
    {
        final String publishedString = this.getQuery().getFirstValue(PoddWebConstants.KEY_PUBLISHED);
        final String unpublishedString = this.getQuery().getFirstValue(PoddWebConstants.KEY_UNPUBLISHED);
        
        // default to both published and unpublished to start with
        boolean published = true;
        boolean unpublished = true;
        
        if(publishedString != null)
        {
            published = Boolean.parseBoolean(publishedString);
        }
        
        if(unpublishedString != null)
        {
            unpublished = Boolean.parseBoolean(unpublishedString);
        }
        
        // If they are not authenticated always set unpublished to false
        if(!this.getClientInfo().isAuthenticated())
        {
            unpublished = false;
        }
        
        if(published)
        {
            final Collection<InferredOWLOntologyID> publishedArtifacts =
                    this.getPoddApplication().getPoddArtifactManager().listPublishedArtifacts();
            
            for(final InferredOWLOntologyID nextPublishedArtifact : publishedArtifacts)
            {
                try
                {
                    this.checkAuthentication(PoddAction.PUBLISHED_ARTIFACT_READ,
                            Arrays.asList(nextPublishedArtifact.getOntologyIRI().toOpenRDFURI()));
                }
                catch(final ResourceException e)
                {
                    if(!e.getStatus().equals(Status.CLIENT_ERROR_FORBIDDEN))
                    {
                        throw e;
                    }
                    else
                    {
                        this.log.warn("Could not access published artifact: {}", nextPublishedArtifact);
                    }
                }
            }
        }
        
        if(unpublished)
        {
            final Collection<InferredOWLOntologyID> unpublishedArtifacts =
                    this.getPoddApplication().getPoddArtifactManager().listUnpublishedArtifacts();
        }
        
        throw new ResourceException(Status.SERVER_ERROR_NOT_IMPLEMENTED, "TODO: Implement listing of artifacts");
    }
{'fraction_non_alphanumeric': 0.08256029684601113, 'fraction_numerical': 0.0005300821627352239, 'mean_word_length': 2.784854563691073, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4157523', 'n_tokens_mistral': 2072, 'n_tokens_neox': 2005, 'n_words': 438}