<commit_before>#need to add removal of documentation field
#CREATOR: <NAME>


from java.lang import *
from com.nomagic.magicdraw.core import Application
from com.nomagic.uml2.ext.jmi.helpers import StereotypesHelper
from com.nomagic.magicdraw.openapi.uml import SessionManager
from com.nomagic.magicdraw.openapi.uml import ModelElementsManager
from com.nomagic.uml2.ext.jmi.helpers import ModelHelper
from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import *
from com.nomagic.uml2.ext.magicdraw.classes.mdinterfaces import Interface
from com.nomagic.uml2.ext.magicdraw.mdprofiles import Stereotype

#from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import Property
#from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import Package
#from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import AggregationKindEnum
#from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import Enumeration
#from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import Constraint
from com.nomagic.uml2.ext.magicdraw.compositestructures.mdports import Port
from com.nomagic.uml2.ext.magicdraw.classes.mdassociationclasses import AssociationClass
from com.nomagic.magicdraw.copypaste import CopyPasteManager
from com.nomagic.uml2.ext.magicdraw.activities.mdfundamentalactivities import Activity

from javax.swing import JOptionPane


from com.nomagic.magicdraw.teamwork.application import TeamworkUtils
import sys
import traceback
import os

gl = Application.getInstance().getGUILog()
project = Application.getInstance().getProject()
proxyMan = project.getProxyManager()
ef = project.getElementsFactory()
mem = ModelElementsManager.getInstance()
sm = SessionManager.getInstance()
disposeOrphanProxy=False
#CSAF=StereotypesHelper.getProfile(project,"Mission Service Architecture Framework")

fileStereoMap=open('GoodStereo.csv','r')
filePortMap=open('GoodPort.csv','r')
filePropMap=open('GoodProp.csv','r')
#fileRead=fileStereoMap.read()
#map=json.load(fileRead)
StereoCollect={}
PortCollect={}
PropCollect={}

def ProxyFinish(proxyMan, fileStereoMap):
    for line in fileStereoMap:
        #gl.log(str(line))
        try:
            [proxyID,stereoID]=line.split(',')
            stereoID=stereoID.split()
            stereoID=stereoID[0]
            StereoCollect[proxyID]=stereoID
        except:
            pass
        
    proxies=proxyMan.getProxies() #returns all registered proxies
    count=0
#    StereoCollect=[]
    listPort={}
    listProp={}
#    StereoMap = open("StereoMap.dat","w")
    #GoodStereo=csv.writer(open("GoodStereo.csv","w"),delimiter=',',quoting=csv.QUOTE_ALL)
    proxies=StereotypesHelper.filterByProfile(proxies,profile)
    for proxy in proxies:
        #first need to check if orphan proxy
        if True==proxyMan.isGhostProxy(proxy):
            disposeOrphanProxy=False
            #(need to build in cases here of things we want to dispose)
            ids=proxy.getID()
            elementProxy=project.getElementByID(ids)
            #gl.log("what up what up the id of the proxy is===>"+str(ids))
            if isinstance(proxy,NamedElement):
               # gl.log("What did we get from the orphan proxy thing====>"+proxy.getName())
            if isinstance(proxy,Generalization):  #this works
                count+=1
                disposeOrphanProxy=True
                #gl.log("Removing orphan generalizations")
            if isinstance(proxy,Stereotype):
                proxyId=proxy.getID()
                ####the name of the proxy gotten by element
                #gl.log("Name of proxy gotten by element ID====>"+elementProxy.getQualifiedName())
                #gl.log("The name of the orphaned stereotype=====>"+proxy.getQualifiedName())
                elemSt=StereotypesHelper.getExtendedElements(proxy)
                #stereos=
                #get control service framework
                #CSAF=StereotypesHelper.getProfile(project,"Control Service Framework")
                #stereo=MDUtils.getUserSelections([Stereotype], CSAF, False,'Select Stereotype to Replace Orphan Stereotype==>'+proxy.getName(),[Stereotype,Package])
                for elem in elemSt:
                    stereo=None
                    if proxyId in StereoCollect:
                        #Need to see what StereoCollect[proxyID] is giving us
                        #gl.log("This is the stereocollect ID====>"+StereoCollect[proxyId])
                        stereo=project.getElementByID(StereoCollect[proxyId])
                    if stereo is not None:
                        #StereoCollect[proxyID]=stereo.getID()
                        gl.log("***************************")
                        gl.log("This element is using an orphaned stereotype====>"+elem.getQualifiedName()+ "  and will be replaced with selected Stereotype===>"+stereo.getQualifiedName())
                        StereotypesHelper.removeStereotype(elem,proxy)<commit_msg>fixed small bug where there was nested if's<commit_after>#need to add removal of documentation field
#CREATOR: <NAME>


from java.lang import *
from com.nomagic.magicdraw.core import Application
from com.nomagic.uml2.ext.jmi.helpers import StereotypesHelper
from com.nomagic.magicdraw.openapi.uml import SessionManager
from com.nomagic.magicdraw.openapi.uml import ModelElementsManager
from com.nomagic.uml2.ext.jmi.helpers import ModelHelper
from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import *
from com.nomagic.uml2.ext.magicdraw.classes.mdinterfaces import Interface
from com.nomagic.uml2.ext.magicdraw.mdprofiles import Stereotype

#from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import Property
#from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import Package
#from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import AggregationKindEnum
#from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import Enumeration
#from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import Constraint
from com.nomagic.uml2.ext.magicdraw.compositestructures.mdports import Port
from com.nomagic.uml2.ext.magicdraw.classes.mdassociationclasses import AssociationClass
from com.nomagic.magicdraw.copypaste import CopyPasteManager
from com.nomagic.uml2.ext.magicdraw.activities.mdfundamentalactivities import Activity

from javax.swing import JOptionPane


from com.nomagic.magicdraw.teamwork.application import TeamworkUtils
import sys
import traceback
import os

gl = Application.getInstance().getGUILog()
project = Application.getInstance().getProject()
proxyMan = project.getProxyManager()
ef = project.getElementsFactory()
mem = ModelElementsManager.getInstance()
sm = SessionManager.getInstance()
disposeOrphanProxy=False
#CSAF=StereotypesHelper.getProfile(project,"Mission Service Architecture Framework")

fileStereoMap=open('GoodStereo.csv','r')
filePortMap=open('GoodPort.csv','r')
filePropMap=open('GoodProp.csv','r')
#fileRead=fileStereoMap.read()
#map=json.load(fileRead)
StereoCollect={}
PortCollect={}
PropCollect={}

def ProxyFinish(proxyMan, fileStereoMap):
    for line in fileStereoMap:
        #gl.log(str(line))
        try:
            [proxyID,stereoID]=line.split(',')
            stereoID=stereoID.split()
            stereoID=stereoID[0]
            StereoCollect[proxyID]=stereoID
        except:
            pass
        
    proxies=proxyMan.getProxies() #returns all registered proxies
    count=0
#    StereoCollect=[]
    listPort={}
    listProp={}
#    StereoMap = open("StereoMap.dat","w")
    #GoodStereo=csv.writer(open("GoodStereo.csv","w"),delimiter=',',quoting=csv.QUOTE_ALL)
    proxies=StereotypesHelper.filterByProfile(proxies,profile)
    for proxy in proxies:
        #first need to check if orphan proxy
        if True==proxyMan.isGhostProxy(proxy):
            disposeOrphanProxy=False
            #(need to build in cases here of things we want to dispose)
            ids=proxy.getID()
            elementProxy=project.getElementByID(ids)
            #gl.log("what up what up the id of the proxy is===>"+str(ids))
            if isinstance(proxy,Generalization):  #this works
                count+=1
                disposeOrphanProxy=True
                #gl.log("Removing orphan generalizations")
            if isinstance(proxy,Stereotype):
                proxyId=proxy.getID()
                ####the name of the proxy gotten by element
                #gl.log("Name of proxy gotten by element ID====>"+elementProxy.getQualifiedName())
                #gl.log("The name of the orphaned stereotype=====>"+proxy.getQualifiedName())
                elemSt=StereotypesHelper.getExtendedElements(proxy)
                #stereos=
                #get control service framework
                #CSAF=StereotypesHelper.getProfile(project,"Control Service Framework")
                #stereo=MDUtils.getUserSelections([Stereotype], CSAF, False,'Select Stereotype to Replace Orphan Stereotype==>'+proxy.getName(),[Stereotype,Package])
                for elem in elemSt:
                    stereo=None
                    if proxyId in StereoCollect:
                        #Need to see what StereoCollect[proxyID] is giving us
                        #gl.log("This is the stereocollect ID====>"+StereoCollect[proxyId])
                        stereo=project.getElementByID(StereoCollect[proxyId])
                    if stereo is not None:
                        #StereoCollect[proxyID]=stereo.getID()
                        gl.log("***************************")
                        gl.log("This element is using an orphaned stereotype====>"+elem.getQualifiedName()+ "  and will be replaced with selected Stereotype===>"+stereo.getQualifiedName())
                        StereotypesHelper.removeStereotype(elem,proxy)
{'fraction_non_alphanumeric': 0.10615623383341956, 'fraction_numerical': 0.003310915675116399, 'mean_word_length': 3.2675496688741723, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, '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': '5997080', 'n_tokens_mistral': 2962, 'n_tokens_neox': 2738, 'n_words': 575}