<commit_before>package controllers;

import java.util.UUID;

import com.avaje.ebean.Ebean;

import models.Organisation;
import models.Target;
import models.User;
import play.Logger;
import play.mvc.Result;
import play.mvc.Security;
import uk.bl.Const;
import views.html.*;

/**
 * Look up the URL of interest. This gives a status check, and allows the user to decide 
 * whether they need to create an entry for this item. This page allows the user to look 
 * up a URL in a way that is compatible with a bookmarklet or other RESTful services.
 *
 * From here, they can find out:
 *
 *   If the URI, or a closely related URI (e.g. same domain), already has an entry in ACT.
 *   If the URI has been crawled (hook into Monitrix).
 *   If the URI is available from any of the Wayback instances (i.e. hooks to Wayback API).
 *   If the URI falls in scope for crawling, or whether additional permissions will be needed.
 *   If the URI is held in other archives, a la http://www.webarchive.org.uk/mementos/search/http://www.bbc.co.uk/news/
 *
 */
@Security.Authenticated(Secured.class)
public class LookUp extends AbstractController {
  
    /**
     * Display the targets.
     */
    public static Result index() {
        return ok(
            lookup.render(
                "LookUp", User.find.byId(request().username()), models.Target.findInvolving(), User.findAll(), ""
            )
        );
    }

    /**
     * This method enables searching for given URL and redirection in order to add new entry
     * if required.
     * @return
     */
    public static Result filterUrl() {
    	Result res = null;
        String addentry = getFormParam("addentry");
        String search = getFormParam("search");
        String url = getFormParam(Const.URL);
//        Logger.info("addentry: " + addentry + ", search: " + search + ", url: " + url);
        if (addentry != null) {
//	        res = redirect(routes.WebSite.addEntry(url)); 
//        	Target target = new Target();
//        	target.title = url;
//            UUID id = UUID.randomUUID();
//            Logger.info("id: " + id.toString());
//            target.nid = id.getMostSignificantBits();
//            target.url = Const.ACT_URL + target.nid;
//	        res = redirect(routes.TargetEdit.addEntry(target)); 
	        res = redirect(routes.TargetEdit.addEntry(url));
        } else {
            res = ok(
	            lookup.render(
	                "LookUp", User.find.byId(request().username()), models.Target.filterUrl(url), User.findAll(), url
                )
            );
        }
        return res;
    }
	<commit_msg>+ issue #7: do not add target with empty title.<commit_after>package controllers;

import java.util.UUID;

import com.avaje.ebean.Ebean;

import models.Organisation;
import models.Target;
import models.User;
import play.Logger;
import play.mvc.Result;
import play.mvc.Security;
import uk.bl.Const;
import views.html.*;

/**
 * Look up the URL of interest. This gives a status check, and allows the user to decide 
 * whether they need to create an entry for this item. This page allows the user to look 
 * up a URL in a way that is compatible with a bookmarklet or other RESTful services.
 *
 * From here, they can find out:
 *
 *   If the URI, or a closely related URI (e.g. same domain), already has an entry in ACT.
 *   If the URI has been crawled (hook into Monitrix).
 *   If the URI is available from any of the Wayback instances (i.e. hooks to Wayback API).
 *   If the URI falls in scope for crawling, or whether additional permissions will be needed.
 *   If the URI is held in other archives, a la http://www.webarchive.org.uk/mementos/search/http://www.bbc.co.uk/news/
 *
 */
@Security.Authenticated(Secured.class)
public class LookUp extends AbstractController {
  
    /**
     * Display the targets.
     */
    public static Result index() {
        return ok(
            lookup.render(
                "LookUp", User.find.byId(request().username()), models.Target.findInvolving(), User.findAll(), ""
            )
        );
    }

    /**
     * This method enables searching for given URL and redirection in order to add new entry
     * if required.
     * @return
     */
    public static Result filterUrl() {
    	Result res = null;
        String addentry = getFormParam("addentry");
        String search = getFormParam("search");
        String url = getFormParam(Const.URL);
//        Logger.info("addentry: " + addentry + ", search: " + search + ", url: " + url);
        if (addentry != null) {
//	        res = redirect(routes.WebSite.addEntry(url)); 
//        	Target target = new Target();
//        	target.title = url;
//            UUID id = UUID.randomUUID();
//            Logger.info("id: " + id.toString());
//            target.nid = id.getMostSignificantBits();
//            target.url = Const.ACT_URL + target.nid;
//	        res = redirect(routes.TargetEdit.addEntry(target)); 
        	if (url != null && url.length() > 0) {
        		res = redirect(routes.TargetEdit.addEntry(url));
        	} else {
        		Logger.info("Target title is empty. Please write title in search window.");
//                res = ok();
                res = ok(
        	            lookup.render(
        	                "LookUp", User.find.byId(request().username()), models.Target.filterUrl(url), User.findAll(), ""
                        )
                    );
        	}
        } else {
            res = ok(
	            lookup.render(
	                "LookUp", User.find.byId(request().username()), models.Target.filterUrl(url), User.findAll(), url
                )
            );
        }
        return res;
    }
	
{'fraction_non_alphanumeric': 0.1188416033904291, 'fraction_numerical': 0.0003531696980399082, 'mean_word_length': 2.1624790619765495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2731408', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1606, 'n_words': 518}