<commit_before>/**
 * $Id: GraphStructure.java,v 1.3 2012/11/21 14:16:01 mate Exp $
 * Copyright (c) 2012, JGraph Ltd
 */
package br.ufrj.cos.expline.analysis;

import java.util.ArrayList;
import java.util.Arrays;

import br.ufrj.cos.expline.model.Activity;
import br.ufrj.cos.expline.model.Edge;
import br.ufrj.cos.expline.model.Port;

import com.mxgraph.analysis.mxAnalysisGraph;
import com.mxgraph.analysis.mxGraphStructure;
import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxGraphModel;
import com.mxgraph.model.mxIGraphModel;
import com.mxgraph.view.mxGraph;

public class GraphStructure extends mxGraphStructure
{

	
	public static boolean makesCycle(mxAnalysisGraph aGraph, mxCell source, mxCell target)
	{

		mxGraph graph = aGraph.getGraph();
		mxIGraphModel model = graph.getModel();
		
//		if (source instanceof Activity) {
//			return false;
//		}
		
		//Workaround to add the request edge in the clone graph to verify that makes cycle
		//TODO: Criar uma conexo a porta de sada e no com a entrada. (Vai funcionar s com atividades com uma porta de entrada e sada.) (No vai funcionar... Tem que fazer pra todas atividades)
		Object parent = graph.getDefaultParent();
		Object edge = graph.createEdge(parent, null, "", source, target, "");

		Object[] cells = model.cloneCells(aGraph.getChildCells(graph.getDefaultParent(), true, true), true);
		
		for (int i = 0; i < cells.length; i++) {
			mxCell temp = (mxCell)cells[i];
			if(temp.getId().equals(source.getId())){
				((mxCell)edge).setSource(temp);
				break;
			}
		}
		
		for (int i = 0; i < cells.length; i++) {
			mxCell temp = (mxCell)cells[i];
			if(temp.getId().equals(target.getId())){
				((mxCell)edge).setTarget(temp);
				break;
			}
		}
		
		
		ArrayList<Object> cellList = new ArrayList<Object>(Arrays.asList(cells));
		cellList.add(edge);
		
		
		for (int i = 0; i < cells.length; i++) {
			mxCell temp = (mxCell)cells[i];
			
			if(temp instanceof Edge){
				Edge edge_temp = (Edge) temp;
				
				Port port1 = (Port) edge_temp.getSource();
				Port port2 = (Port) edge_temp.getTarget();
				
				Activity actv1 = (Activity) port1.getParent();
				Activity actv2 = (Activity) port2.getParent();
				
				Object new_edge = graph.createEdge(parent, null, "", actv1, actv2, "");
				
				((mxCell)new_edge).setSource(actv1);
				((mxCell)new_edge).setTarget(actv2);
				
				cellList.add(new_edge);
			}
			
		}
		<commit_msg>Fixed the method that verifies that the workflow has loops.<commit_after>/**
 * $Id: GraphStructure.java,v 1.3 2012/11/21 14:16:01 mate Exp $
 * Copyright (c) 2012, JGraph Ltd
 */
package br.ufrj.cos.expline.analysis;

import java.util.ArrayList;
import java.util.Arrays;

import br.ufrj.cos.expline.model.Activity;
import br.ufrj.cos.expline.model.Edge;
import br.ufrj.cos.expline.model.Port;

import com.mxgraph.analysis.mxAnalysisGraph;
import com.mxgraph.analysis.mxGraphStructure;
import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxGraphModel;
import com.mxgraph.model.mxIGraphModel;
import com.mxgraph.view.mxGraph;

public class GraphStructure extends mxGraphStructure
{

	
	public static boolean makesCycle(mxAnalysisGraph aGraph, mxCell source, mxCell target)
	{

		mxGraph graph = aGraph.getGraph();
		mxIGraphModel model = graph.getModel();
		
//		if (source instanceof Activity) {
//			return false;
//		}
		
		//Workaround to add the request edge in the clone graph to verify that makes cycle
		//TODO: Criar uma conexo a porta de sada e no com a entrada. (Vai funcionar s com atividades com uma porta de entrada e sada.) (No vai funcionar... Tem que fazer pra todas atividades)
		Object parent = graph.getDefaultParent();
		Object edge = graph.createEdge(parent, null, "", source, target, "");

		Object[] cells = model.cloneCells(aGraph.getChildCells(graph.getDefaultParent(), true, true), true);
		
		for (int i = 0; i < cells.length; i++) {
			mxCell temp = (mxCell)cells[i];
			if(temp.getId().equals(source.getId())){
				((mxCell)edge).setSource(temp);
				break;
			}
		}
		
		for (int i = 0; i < cells.length; i++) {
			mxCell temp = (mxCell)cells[i];
			if(temp.getId().equals(target.getId())){
				((mxCell)edge).setTarget(temp);
				break;
			}
		}
		
		
		ArrayList<Object> cellList = new ArrayList<Object>(Arrays.asList(cells));
		cellList.add(edge);
		
		
		for (int i = 0; i < cells.length; i++) {
			mxCell temp = (mxCell)cells[i];
			
			if(temp instanceof Edge){
				Edge edge_temp = (Edge) temp;
				
				if(!(edge_temp.getSource() instanceof Activity) && !(edge_temp.getTarget() instanceof Activity)){
				
					Port port1 = (Port) edge_temp.getSource();
					Port port2 = (Port) edge_temp.getTarget();
					
					Activity actv1 = (Activity) port1.getParent();
					Activity actv2 = (Activity) port2.getParent();
					
					Object new_edge = graph.createEdge(parent, null, "", actv1, actv2, "");
					
					((mxCell)new_edge).setSource(actv1);
					((mxCell)new_edge).setTarget(actv2);
					
					cellList.add(new_edge);
				}
			}
			
		}
		
{'fraction_non_alphanumeric': 0.136627325465093, 'fraction_numerical': 0.013202640528105622, 'mean_word_length': 3.5955882352941178, 'pattern_counts': {'":': 0, '<': 13, '<?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': '6535965', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1693, 'n_words': 415}