<commit_before>package org.jasig.portal.channel;

import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.portal.ChannelCategory;
import org.jasig.portal.ChannelRegistryManager;
import org.jasig.portal.IChannelRegistryStore;
import org.jasig.portal.events.EventPublisherLocator;
import org.jasig.portal.events.support.ModifiedChannelDefinitionPortalEvent;
import org.jasig.portal.events.support.PublishedChannelDefinitionPortalEvent;
import org.jasig.portal.events.support.RemovedChannelDefinitionPortalEvent;
import org.jasig.portal.groups.IEntity;
import org.jasig.portal.groups.IEntityGroup;
import org.jasig.portal.groups.IGroupMember;
import org.jasig.portal.security.IAuthorizationPrincipal;
import org.jasig.portal.security.IPermission;
import org.jasig.portal.security.IPerson;
import org.jasig.portal.security.IUpdatingPermissionManager;
import org.jasig.portal.services.AuthorizationService;
import org.jasig.portal.services.GroupService;

/**
 * Default implementation of IChannelPublishingService.
 * 
 * @author <NAME>, <EMAIL>
 */
public class ChannelPublishingServiceImpl implements IChannelPublishingService {
	
	private IChannelRegistryStore channelRegistryStore;
	
	/**
	 * Set the channel persistence service
	 * 
	 * @param channelRegistryStore
	 */
	public void setChannelRegistryStore(IChannelRegistryStore channelRegistryStore) {
		this.channelRegistryStore = channelRegistryStore;
	}


	private Log log = LogFactory.getLog(ChannelPublishingServiceImpl.class);

	/*
	 * (non-Javadoc)
	 * @see org.jasig.portal.channel.IChannelPublishingService#approveChannelDefinition(org.jasig.portal.channel.IChannelDefinition, org.jasig.portal.security.IPerson)
	 */
	public IChannelDefinition approveChannelDefinition(
			IChannelDefinition channelDefinition, IPerson person) {
		// TODO Auto-generated method stub
        throw new UnsupportedOperationException("Not implemented yet");
	}

	/*
	 * (non-Javadoc)
	 * @see org.jasig.portal.channel.IChannelPublishingService#saveChannelDefinition(org.jasig.portal.channel.IChannelDefinition, org.jasig.portal.security.IPerson, java.lang.String[], org.jasig.portal.groups.IGroupMember[])
	 */
	public IChannelDefinition saveChannelDefinition(IChannelDefinition channelDef, IPerson publisher, String[] categoryIDs, IGroupMember[] groupMembers) {
		boolean newChannel = (channelDef.getId() == 0);
	    channelRegistryStore.saveChannelDefinition(channelDef);
	    channelDef = channelRegistryStore.getChannelDefinition(channelDef.getFName());

	    // Delete existing category memberships for this channel
	    String chanKey = String.valueOf(channelDef.getId());
	    IEntity channelDefEntity = GroupService.getEntity(chanKey, IChannelDefinition.class);
		@SuppressWarnings("unchecked")
	    Iterator iter = channelDefEntity.getAllContainingGroups();
	    while (iter.hasNext()) {
	        IEntityGroup group = (IEntityGroup) iter.next();
	        group.removeMember(channelDefEntity);
	        group.update();
	    }

	    // For each category ID, add channel to category
	    for (int i = 0; i < categoryIDs.length; i++) {
	      categoryIDs[i] = categoryIDs[i].startsWith("cat") ? categoryIDs[i].substring(3) : categoryIDs[i];
	      String iCatID = categoryIDs[i];
	      ChannelCategory category = channelRegistryStore.getChannelCategory(iCatID);
	      channelRegistryStore.addChannelToCategory(channelDef, category);
	    }

	    // Set groups
	    AuthorizationService authService = AuthorizationService.instance();
	    String target = IPermission.CHANNEL_PREFIX + channelDef.getId();
	    IUpdatingPermissionManager upm = authService.newUpdatingPermissionManager(FRAMEWORK_OWNER);
	    IPermission[] permissions = new IPermission[groupMembers.length];
	    for (int i = 0; i < groupMembers.length; i++) {<commit_msg>UP-2439 Adding code to set channel approval and publishing dates and user ids when a channel is saved<commit_after>package org.jasig.portal.channel;

import java.util.Date;
import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.portal.ChannelCategory;
import org.jasig.portal.ChannelRegistryManager;
import org.jasig.portal.IChannelRegistryStore;
import org.jasig.portal.events.EventPublisherLocator;
import org.jasig.portal.events.support.ModifiedChannelDefinitionPortalEvent;
import org.jasig.portal.events.support.PublishedChannelDefinitionPortalEvent;
import org.jasig.portal.events.support.RemovedChannelDefinitionPortalEvent;
import org.jasig.portal.groups.IEntity;
import org.jasig.portal.groups.IEntityGroup;
import org.jasig.portal.groups.IGroupMember;
import org.jasig.portal.security.IAuthorizationPrincipal;
import org.jasig.portal.security.IPermission;
import org.jasig.portal.security.IPerson;
import org.jasig.portal.security.IUpdatingPermissionManager;
import org.jasig.portal.services.AuthorizationService;
import org.jasig.portal.services.GroupService;

/**
 * Default implementation of IChannelPublishingService.
 * 
 * @author <NAME>, <EMAIL>
 */
public class ChannelPublishingServiceImpl implements IChannelPublishingService {
	
	private IChannelRegistryStore channelRegistryStore;
	
	/**
	 * Set the channel persistence service
	 * 
	 * @param channelRegistryStore
	 */
	public void setChannelRegistryStore(IChannelRegistryStore channelRegistryStore) {
		this.channelRegistryStore = channelRegistryStore;
	}


	private Log log = LogFactory.getLog(ChannelPublishingServiceImpl.class);

	/*
	 * (non-Javadoc)
	 * @see org.jasig.portal.channel.IChannelPublishingService#approveChannelDefinition(org.jasig.portal.channel.IChannelDefinition, org.jasig.portal.security.IPerson)
	 */
	public IChannelDefinition approveChannelDefinition(
			IChannelDefinition channelDefinition, IPerson person) {
		// TODO Auto-generated method stub
        throw new UnsupportedOperationException("Not implemented yet");
	}

	/*
	 * (non-Javadoc)
	 * @see org.jasig.portal.channel.IChannelPublishingService#saveChannelDefinition(org.jasig.portal.channel.IChannelDefinition, org.jasig.portal.security.IPerson, java.lang.String[], org.jasig.portal.groups.IGroupMember[])
	 */
	public IChannelDefinition saveChannelDefinition(IChannelDefinition channelDef, IPerson publisher, String[] categoryIDs, IGroupMember[] groupMembers) {
		boolean newChannel = (channelDef.getId() == 0);
		
	    Date now = new Date();
	    channelDef.setPublisherId(publisher.getID());
	    channelDef.setPublishDate(now);
	    channelDef.setApproverId(publisher.getID());
	    channelDef.setApprovalDate(now);
	    channelRegistryStore.saveChannelDefinition(channelDef);
	    channelDef = channelRegistryStore.getChannelDefinition(channelDef.getFName());

	    // Delete existing category memberships for this channel
	    String chanKey = String.valueOf(channelDef.getId());
	    IEntity channelDefEntity = GroupService.getEntity(chanKey, IChannelDefinition.class);
		@SuppressWarnings("unchecked")
	    Iterator iter = channelDefEntity.getAllContainingGroups();
	    while (iter.hasNext()) {
	        IEntityGroup group = (IEntityGroup) iter.next();
	        group.removeMember(channelDefEntity);
	        group.update();
	    }

	    // For each category ID, add channel to category
	    for (int i = 0; i < categoryIDs.length; i++) {
	      categoryIDs[i] = categoryIDs[i].startsWith("cat") ? categoryIDs[i].substring(3) : categoryIDs[i];
	      String iCatID = categoryIDs[i];
	      ChannelCategory category = channelRegistryStore.getChannelCategory(iCatID);
	      channelRegistryStore.addChannelToCategory(channelDef, category);
	    }

	    // Set groups
	    AuthorizationService authService = AuthorizationService.instance();
	    String target = IPermission.CHANNEL_PREFIX + channelDef.getId();
	    IUpdatingPermissionManager upm = authService.newUpdatingPermissionManager(FRAMEWORK_OWNER);
	    IPermission[] permissions = new IPermission[groupMembers.length];
	    for (int i = 0; i < groupMembers.length; i++) {
{'fraction_non_alphanumeric': 0.09838107098381071, 'fraction_numerical': 0.0014943960149439602, 'mean_word_length': 5.2546728971962615, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '7154747', 'n_tokens_mistral': 2323, 'n_tokens_neox': 2231, 'n_words': 409}