<commit_before>package org.sagebionetworks.web.shared.provenance;

import java.util.Iterator;
import java.util.Set;

import org.sagebionetworks.repo.model.provenance.Activity;
import org.sagebionetworks.repo.model.provenance.UsedEntity;

public class ActivityTypeUtil {

	public static ActivityType get(Activity activity) {
		if(activity == null) return ActivityType.UNDEFINED;
		
		Set<UsedEntity> used = activity.getUsed();
		if(used == null || used.size() == 0) return ActivityType.UNDEFINED;

		// look for executed
		boolean isManual = true;
		Iterator<UsedEntity> itr = used.iterator();
		while(itr.hasNext()) {
			UsedEntity ue = itr.next();
			if(ue != null && ue.getWasExecuted() != null && ue.getWasExecuted()) {
				isManual = false;
				break;
			}
		}
		
		return isManual ? ActivityType.MANUAL : ActivityType.CODE_EXECUTION;
	}
	
	/**
	 * Returns the first executed entity in the used list
	 * @param activity
	 * @return null if no executed entities are found
	 */
	public static UsedEntity getExecuted(Activity activity) {<commit_msg>Only use Undefined for truly not created activities<commit_after>package org.sagebionetworks.web.shared.provenance;

import java.util.Iterator;
import java.util.Set;

import org.sagebionetworks.repo.model.provenance.Activity;
import org.sagebionetworks.repo.model.provenance.UsedEntity;

public class ActivityTypeUtil {

	public static ActivityType get(Activity activity) {
		if(activity == null || activity.getCreatedBy() == null) return ActivityType.UNDEFINED;
		
		Set<UsedEntity> used = activity.getUsed();
		if(used == null) return ActivityType.MANUAL;

		// look for executed
		boolean isManual = true;
		Iterator<UsedEntity> itr = used.iterator();
		while(itr.hasNext()) {
			UsedEntity ue = itr.next();
			if(ue != null && ue.getWasExecuted() != null && ue.getWasExecuted()) {
				isManual = false;
				break;
			}
		}
		
		return isManual ? ActivityType.MANUAL : ActivityType.CODE_EXECUTION;
	}
	
	/**
	 * Returns the first executed entity in the used list
	 * @param activity
	 * @return null if no executed entities are found
	 */
	public static UsedEntity getExecuted(Activity activity) {
{'fraction_non_alphanumeric': 0.11069767441860465, 'fraction_numerical': 0.00046511627906976747, 'mean_word_length': 4.246341463414634, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4335756', 'n_tokens_mistral': 740, 'n_tokens_neox': 665, 'n_words': 167}