<commit_before>package edu.harvard.iq.dataverse.engine.command;

import edu.harvard.iq.dataverse.DvObject;
import edu.harvard.iq.dataverse.authorization.users.User;
import java.util.HashMap;
import java.util.Map;

/**
 * Convenience class for implementing the {@link Command} interface.
 * @author michael
 * @param <R> The result type of the command.
 */
public abstract class AbstractCommand<R> implements Command<R> {
	
	private final Map<String,DvObject> affectedDataverses;
	private final User user;
	
	static protected class DvNamePair {
		final String name;
		final DvObject dvObject;

		public DvNamePair(String name, DvObject dv) {
			this.name = name;
			this.dvObject = dv;
		}
	}
	
	/**
	 * Convenience method to name affected dataverses.
	 * @param s the name
	 * @param d the dataverse
	 * @return the named pair
	 */
	protected static DvNamePair dv( String s, DvObject d ) {
		return new DvNamePair(s,d);
	}
	
	public AbstractCommand(User aUser, DvObject anAffectedDvObject) {
		this( aUser, dv("",anAffectedDvObject));
	}
	
	public AbstractCommand(User aUser, DvNamePair dvp, DvNamePair... more ) {
		user = aUser;
		affectedDataverses = new HashMap<>();
		affectedDataverses.put( dvp.name, dvp.dvObject );
		for ( DvNamePair p : more ) {
			affectedDataverses.put( p.name, p.dvObject );
		}
	}
	
	public AbstractCommand( User aUser, Map<String, DvObject> someAffectedDvObjects ) {
		user = aUser;
		affectedDataverses = someAffectedDvObjects;
	}
	
	@Override
	public Map<String,DvObject> getAffectedDvObjects() {
		return affectedDataverses;
	}
	
	@Override
	public User getUser() {
		return user;
	}
	
}
<commit_msg>add permissionRequired method to the Commands, so we can define dynamic permissions<commit_after>package edu.harvard.iq.dataverse.engine.command;

import edu.harvard.iq.dataverse.DvObject;
import edu.harvard.iq.dataverse.authorization.Permission;
import edu.harvard.iq.dataverse.authorization.users.User;
import static edu.harvard.iq.dataverse.engine.command.CommandHelper.CH;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Convenience class for implementing the {@link Command} interface.
 *
 * @author michael
 * @param <R> The result type of the command.
 */
public abstract class AbstractCommand<R> implements Command<R> {

    private final Map<String, DvObject> affectedDataverses;
    private final User user;

    static protected class DvNamePair {

        final String name;
        final DvObject dvObject;

        public DvNamePair(String name, DvObject dv) {
            this.name = name;
            this.dvObject = dv;
        }
    }

    /**
     * Convenience method to name affected dataverses.
     *
     * @param s the name
     * @param d the dataverse
     * @return the named pair
     */
    protected static DvNamePair dv(String s, DvObject d) {
        return new DvNamePair(s, d);
    }

    public AbstractCommand(User aUser, DvObject anAffectedDvObject) {
        this(aUser, dv("", anAffectedDvObject));
    }

    public AbstractCommand(User aUser, DvNamePair dvp, DvNamePair... more) {
        user = aUser;
        affectedDataverses = new HashMap<>();
        affectedDataverses.put(dvp.name, dvp.dvObject);
        for (DvNamePair p : more) {
            affectedDataverses.put(p.name, p.dvObject);
        }
    }

    public AbstractCommand(User aUser, Map<String, DvObject> someAffectedDvObjects) {
        user = aUser;
        affectedDataverses = someAffectedDvObjects;
    }

    @Override
    public Map<String, DvObject> getAffectedDvObjects() {
        return affectedDataverses;
    }

    @Override
    public User getUser() {
        return user;
    }

    @Override
    public Map<String, Set<Permission>> getRequiredPermissions() {
        return CH.permissionsRequired(getClass());
    }

}

{'fraction_non_alphanumeric': 0.09811122770199371, 'fraction_numerical': 0.0, 'mean_word_length': 3.3280363223609535, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '19014', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1201, 'n_words': 310}