<commit_before>/*
 * Copyright 2012 hbz NRW (http://www.hbz-nrw.de/)
 *
 * 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 de.nrw.hbz.regal.api;

import java.io.IOException;
import java.net.URISyntaxException;

import javax.ws.rs.DELETE;
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.core.CacheControl;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;

import de.nrw.hbz.regal.api.helper.Actions;
import de.nrw.hbz.regal.api.helper.HttpArchiveException;
import de.nrw.hbz.regal.datatypes.Node;
import de.nrw.hbz.regal.exceptions.ArchiveException;

/**
 * @author <NAME> <EMAIL>
 * 
 */
@Path("/utils")
public class Utils {
    Actions actions = new Actions();

    /**
     * @throws IOException
     *             if properties cannot be loaded
     * 
     */
    public Utils() throws IOException {

	actions = new Actions();
    }

    /**
     * @param namespace
     *            the namespace to delete.
     * @return A message or an ArchiveException
     */
    @DELETE
    @Path("/deleteNamespace/{namespace}")
    @Produces({ "application/json", "application/xml" })
    public String deleteNamespace(@PathParam("namespace") String namespace) {

	return actions.deleteNamespace(namespace);

    }

    /**
     * @param pid
     *            the pid of the object, that must be published in a oai set.
     * @return a message
     */
    @POST
    @Path("/makeOaiSet/{pid}")
    @Produces({ "application/json", "application/xml" })
    public String makeOaiSet(@PathParam("pid") String pid) {
	try {
	    return actions.makeOAISet(pid);
	} catch (RuntimeException e) {
	    throw new HttpArchiveException(500, e);
	}

    }

    /**
     * @param pid
     *            the pid to be indexed
     * @param namespace
     *            the namespace of the resource
     * @return a message
     */
    @POST
    @Path("/index/{namespace}:{pid}")
    @Produces({ "application/json", "application/xml" })
    public String index(@PathParam("pid") String pid,
	    @PathParam("namespace") String namespace) {
	try {
	    return actions.index(pid, namespace);
	} catch (Exception e) {

	    throw new HttpArchiveException(
		    Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
	}
    }

    /**
     * @param pid
     *            the pid that must be enriched with lobid data
     * @return a message
     */
    @POST
    @Path("/lobidify/{pid}")
    @Produces({ "application/json", "application/xml" })
    public String lobidify(@PathParam("pid") String pid) {
	try {
	    return actions.lobidify(pid);
	} catch (ArchiveException e) {
	    throw new HttpArchiveException(
		    Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
	}
    }

    /**
     * @param pid
     *            the metadata of the identified resource will be transformed to
     *            oaidc
     * @return the oai_dc xml
     */
    @GET
    @Path("/oaidc/{pid}")
    @Produces({ "application/xml" })
    public String oaidc(@PathParam("pid") String pid) {
	try {
	    return actions.oaidc(pid);
	} catch (ArchiveException e) {<commit_msg>removes error handling<commit_after>/*
 * Copyright 2012 hbz NRW (http://www.hbz-nrw.de/)
 *
 * 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 de.nrw.hbz.regal.api;

import java.io.IOException;
import java.net.URISyntaxException;

import javax.ws.rs.DELETE;
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.core.CacheControl;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;

import de.nrw.hbz.regal.api.helper.Actions;
import de.nrw.hbz.regal.api.helper.HttpArchiveException;
import de.nrw.hbz.regal.datatypes.Node;
import de.nrw.hbz.regal.exceptions.ArchiveException;

/**
 * @author <NAME> <EMAIL>
 * 
 */
@Path("/utils")
public class Utils {
    Actions actions = new Actions();

    /**
     * @throws IOException
     *             if properties cannot be loaded
     * 
     */
    public Utils() throws IOException {

	actions = new Actions();
    }

    /**
     * @param namespace
     *            the namespace to delete.
     * @return A message or an ArchiveException
     */
    @DELETE
    @Path("/deleteNamespace/{namespace}")
    @Produces({ "application/json", "application/xml" })
    public String deleteNamespace(@PathParam("namespace") String namespace) {

	return actions.deleteNamespace(namespace);

    }

    /**
     * @param pid
     *            the pid of the object, that must be published in a oai set.
     * @return a message
     */
    @POST
    @Path("/makeOaiSet/{pid}")
    @Produces({ "application/json", "application/xml" })
    public String makeOaiSet(@PathParam("pid") String pid) {
	try {
	    return actions.makeOAISet(pid);
	} catch (RuntimeException e) {
	    throw new HttpArchiveException(500, e);
	}

    }

    /**
     * @param pid
     *            the pid to be indexed
     * @param namespace
     *            the namespace of the resource
     * @return a message
     */
    @POST
    @Path("/index/{namespace}:{pid}")
    @Produces({ "application/json", "application/xml" })
    public String index(@PathParam("pid") String pid,
	    @PathParam("namespace") String namespace) {
	try {
	    return actions.index(pid, namespace);
	} catch (Exception e) {

	    throw new HttpArchiveException(
		    Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
	}
    }

    /**
     * @param pid
     *            the pid that must be enriched with lobid data
     * @return a message
     */
    @POST
    @Path("/lobidify/{pid}")
    @Produces({ "application/json", "application/xml" })
    public String lobidify(@PathParam("pid") String pid) {
	return actions.lobidify(pid);
    }

    /**
     * @param pid
     *            the metadata of the identified resource will be transformed to
     *            oaidc
     * @return the oai_dc xml
     */
    @GET
    @Path("/oaidc/{pid}")
    @Produces({ "application/xml" })
    public String oaidc(@PathParam("pid") String pid) {
	try {
	    return actions.oaidc(pid);
	} catch (ArchiveException e) {
{'fraction_non_alphanumeric': 0.12324410283593958, 'fraction_numerical': 0.0029154518950437317, 'mean_word_length': 2.7735, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 12}, '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': '5208082', 'n_tokens_mistral': 2373, 'n_tokens_neox': 2301, 'n_words': 635}