<commit_before>package uk.ac.edukapp.service;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import javax.servlet.ServletContext;

import org.apache.log4j.Logger;

import uk.ac.edukapp.cache.Cache;
import uk.ac.edukapp.model.Activity;
import uk.ac.edukapp.model.Tag;
import uk.ac.edukapp.model.WidgetDescription;
import uk.ac.edukapp.model.Widgetprofile;
import uk.ac.edukapp.renderer.SearchResults;
import uk.ac.edukapp.repository.SolrConnector;
import uk.ac.edukapp.repository.Widget;
import uk.ac.edukapp.util.Message;
import uk.ac.edukapp.service.WidgetService;

/*
 *  (c) 2012 University of Bolton
 *  
 *  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.
 */

/**
 * Services for Widget Profiles
 * 
 * @author <EMAIL>
 */
public class WidgetProfileService extends AbstractService {

	static Logger logger = Logger.getLogger(WidgetProfileService.class
			.getName());

	public WidgetProfileService(ServletContext ctx) {
		super(ctx);
	}

	public List<Widgetprofile> findWidgetProfilesForTag(Tag tag) {
		return tag.getWidgetprofiles();
	}

	public List<Widgetprofile> findWidgetProfilesForActivity(Activity activity) {<commit_msg>Added a Create Widget Profile  factory method in widget profile service<commit_after>package uk.ac.edukapp.service;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import javax.servlet.ServletContext;

import org.apache.log4j.Logger;

import uk.ac.edukapp.cache.Cache;
import uk.ac.edukapp.model.Activity;
import uk.ac.edukapp.model.Tag;
import uk.ac.edukapp.model.WidgetDescription;
import uk.ac.edukapp.model.Widgetprofile;
import uk.ac.edukapp.renderer.SearchResults;
import uk.ac.edukapp.repository.SolrConnector;
import uk.ac.edukapp.repository.Widget;
import uk.ac.edukapp.util.Message;
import uk.ac.edukapp.service.WidgetService;

/*
 *  (c) 2012 University of Bolton
 *  
 *  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.
 */

/**
 * Services for Widget Profiles
 * 
 * @author <EMAIL>
 */
public class WidgetProfileService extends AbstractService {

	static Logger logger = Logger.getLogger(WidgetProfileService.class
			.getName());

	public WidgetProfileService(ServletContext ctx) {
		super(ctx);
	}
	
	/**
	 * Create a widget profile and save it
	 * @param uri
	 * @param name
	 * @param description
	 * @return the widget profile 
	 */
	public Widgetprofile createWidgetProfile(String uri, String name, String description){
		
		EntityManager em = getEntityManagerFactory().createEntityManager();
		em.getTransaction().begin();
		Widgetprofile widgetprofile = new Widgetprofile();
		widgetprofile.setName(name);
		byte zero = 0;
		widgetprofile.setW3cOrOs(zero);
		widgetprofile.setWidId(uri);
		em.persist(widgetprofile);

		WidgetDescription wd = new WidgetDescription();
		wd.setDescription(description);
		wd.setWid_id(widgetprofile.getId());
		em.persist(wd);				
		em.getTransaction().commit();
		em.close();
		
		return widgetprofile;
		
	}

	public List<Widgetprofile> findWidgetProfilesForTag(Tag tag) {
		return tag.getWidgetprofiles();
	}

	public List<Widgetprofile> findWidgetProfilesForActivity(Activity activity) {
{'fraction_non_alphanumeric': 0.09595029912563277, 'fraction_numerical': 0.004601932811780948, 'mean_word_length': 4.623544631306598, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2495242', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1272, 'n_words': 359}