<commit_before>package org.activiti.cycle.impl.service;

import java.util.HashSet;
import java.util.Set;

import org.activiti.cycle.CycleComponentFactory;
import org.activiti.cycle.RepositoryArtifact;
import org.activiti.cycle.RepositoryArtifactType;
import org.activiti.cycle.RepositoryConnector;
import org.activiti.cycle.action.Action;
import org.activiti.cycle.action.CreateUrlAction;
import org.activiti.cycle.action.DownloadContentAction;
import org.activiti.cycle.action.ParameterizedAction;
import org.activiti.cycle.action.RepositoryArtifactOpenLinkAction;
import org.activiti.cycle.annotations.ExcludesCycleComponents;
import org.activiti.cycle.components.RuntimeConnectorList;
import org.activiti.cycle.context.CycleApplicationContext;
import org.activiti.cycle.context.CycleSessionContext;
import org.activiti.cycle.impl.action.Actions;
import org.activiti.cycle.service.CyclePluginService;

import com.sun.xml.xsom.impl.scd.Axis;

/**
 * Default Implementation of the {@link CyclePluginService}
 * 
 * @author <EMAIL>
 */
public class CyclePluginServiceImpl implements CyclePluginService {

  public Set<ParameterizedAction> getParameterizedActions(RepositoryArtifactType type) {
    return CycleApplicationContext.get(Actions.class).getParameterizedActions(type);
  }

  public Set<CreateUrlAction> getCreateUrlActions(RepositoryArtifactType type) {
    return CycleApplicationContext.get(Actions.class).getCreateUrlActions(type);

  }

  public Set<DownloadContentAction> getDownloadContentActions(RepositoryArtifactType type) {
    return CycleApplicationContext.get(Actions.class).getDownloadContentActions(type);
  }

  public Set<ParameterizedAction> getParameterizedActions(RepositoryArtifact artifact) {
    Set<ParameterizedAction> actions = getParameterizedActions(artifact.getArtifactType());
    removeExcludedActions(actions);
    sortActions(actions, artifact);
    return actions;
  }

  public Set<CreateUrlAction> getCreateUrlActions(RepositoryArtifact artifact) {
    Set<CreateUrlAction> actions = getCreateUrlActions(artifact.getArtifactType());
    removeExcludedActions(actions);
    sortActions(actions, artifact);
    return actions;
  }

  public Set<DownloadContentAction> getDownloadContentActions(RepositoryArtifact artifact) {
    Set<DownloadContentAction> actions = getDownloadContentActions(artifact.getArtifactType());
    removeExcludedActions(actions);
    sortActions(actions, artifact);
    return actions;
  }

  private void sortActions(Set actions, RepositoryArtifact artifact) {
    // TODO
  }

  private void removeExcludedActions(Set actions) {
    CycleComponentFactory.removeExcludedComponents(actions);
  }

  public Set<RepositoryArtifactOpenLinkAction> getArtifactOpenLinkActions(RepositoryArtifact artifact) {
    // TODO: cache this somewhere?
    // TODO: refactor the RepositoryArtifactOpenLinkActions altogether?
    Set<RepositoryArtifactOpenLinkAction> list = new HashSet<RepositoryArtifactOpenLinkAction>();
    RepositoryConnector connector = CycleSessionContext.get(RuntimeConnectorList.class).getConnectorById(artifact.getConnectorId());
    for (CreateUrlAction action : getCreateUrlActions(artifact)) {
      // TODO: Think about id
      RepositoryArtifactOpenLinkAction link = new RepositoryArtifactOpenLinkAction("Open " + action.getId(), action.getUrl(connector, artifact));
      list.add(link);<commit_msg>Activiti Cycle: fixed support for ArtifactAwareParameterizedActions. <commit_after>package org.activiti.cycle.impl.service;

import java.util.HashSet;
import java.util.Set;

import org.activiti.cycle.CycleComponentFactory;
import org.activiti.cycle.RepositoryArtifact;
import org.activiti.cycle.RepositoryArtifactType;
import org.activiti.cycle.RepositoryConnector;
import org.activiti.cycle.action.Action;
import org.activiti.cycle.action.ArtifactAwareParameterizedAction;
import org.activiti.cycle.action.CreateUrlAction;
import org.activiti.cycle.action.DownloadContentAction;
import org.activiti.cycle.action.ParameterizedAction;
import org.activiti.cycle.action.RepositoryArtifactOpenLinkAction;
import org.activiti.cycle.annotations.ExcludesCycleComponents;
import org.activiti.cycle.components.RuntimeConnectorList;
import org.activiti.cycle.context.CycleApplicationContext;
import org.activiti.cycle.context.CycleSessionContext;
import org.activiti.cycle.impl.action.Actions;
import org.activiti.cycle.service.CyclePluginService;

import com.sun.xml.xsom.impl.scd.Axis;

/**
 * Default Implementation of the {@link CyclePluginService}
 * 
 * @author <EMAIL>
 */
public class CyclePluginServiceImpl implements CyclePluginService {

  public Set<ParameterizedAction> getParameterizedActions(RepositoryArtifactType type) {
    return CycleApplicationContext.get(Actions.class).getParameterizedActions(type);
  }

  public Set<CreateUrlAction> getCreateUrlActions(RepositoryArtifactType type) {
    return CycleApplicationContext.get(Actions.class).getCreateUrlActions(type);

  }

  public Set<DownloadContentAction> getDownloadContentActions(RepositoryArtifactType type) {
    return CycleApplicationContext.get(Actions.class).getDownloadContentActions(type);
  }

  public Set<ParameterizedAction> getParameterizedActions(RepositoryArtifact artifact) {
    Set<ParameterizedAction> actions = getParameterizedActions(artifact.getArtifactType());
    removeNonApplicableActions(actions, artifact);
    removeExcludedActions(actions);
    sortActions(actions, artifact);
    return actions;
  }

  public Set<CreateUrlAction> getCreateUrlActions(RepositoryArtifact artifact) {
    Set<CreateUrlAction> actions = getCreateUrlActions(artifact.getArtifactType());
    removeExcludedActions(actions);
    sortActions(actions, artifact);
    return actions;
  }

  public Set<DownloadContentAction> getDownloadContentActions(RepositoryArtifact artifact) {
    Set<DownloadContentAction> actions = getDownloadContentActions(artifact.getArtifactType());
    removeExcludedActions(actions);
    sortActions(actions, artifact);
    return actions;
  }

  private void removeNonApplicableActions(Set<ParameterizedAction> actions, RepositoryArtifact forArtifact) {
    Set<ParameterizedAction> nonApplicableActions = new HashSet<ParameterizedAction>();
    for (ParameterizedAction parameterizedAction : actions) {
      if (parameterizedAction instanceof ArtifactAwareParameterizedAction) {
        ArtifactAwareParameterizedAction artifactAwareAction = (ArtifactAwareParameterizedAction) parameterizedAction;
        if (artifactAwareAction.isApplicable(forArtifact) == false) {
          nonApplicableActions.add(parameterizedAction);
        }
      }
    }
    actions.removeAll(nonApplicableActions);
  }

  private void sortActions(Set actions, RepositoryArtifact artifact) {
    // TODO
  }

  private void removeExcludedActions(Set actions) {
    CycleComponentFactory.removeExcludedComponents(actions);
  }

  public Set<RepositoryArtifactOpenLinkAction> getArtifactOpenLinkActions(RepositoryArtifact artifact) {
    // TODO: cache this somewhere?
    // TODO: refactor the RepositoryArtifactOpenLinkActions altogether?
    Set<RepositoryArtifactOpenLinkAction> list = new HashSet<RepositoryArtifactOpenLinkAction>();
    RepositoryConnector connector = CycleSessionContext.get(RuntimeConnectorList.class).getConnectorById(artifact.getConnectorId());
    for (CreateUrlAction action : getCreateUrlActions(artifact)) {
      // TODO: Think about id
      RepositoryArtifactOpenLinkAction link = new RepositoryArtifactOpenLinkAction("Open " + action.getId(), action.getUrl(connector, artifact));
      list.add(link);
{'fraction_non_alphanumeric': 0.08494411571334648, 'fraction_numerical': 0.0, 'mean_word_length': 6.4060370009737095, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1924191', 'n_tokens_mistral': 2059, 'n_tokens_neox': 1993, 'n_words': 342}