<commit_before>package nl.mpi.kinnate.kindocument;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.xml.transform.TransformerException;
import nl.mpi.arbil.clarin.profiles.CmdiProfileReader;
import nl.mpi.arbil.clarin.profiles.CmdiProfileReader.ProfileSelection;
import nl.mpi.arbil.userstorage.SessionStorage;
import nl.mpi.arbil.util.BugCatcherManager;
import nl.mpi.kinnate.ui.entityprofiles.CmdiProfileSelectionPanel;

/**
 *  Document   : ProfileManager
 *  Created on : Jan 30, 2012, 12:03:11 PM
 *  Author     : <NAME>
 */
public class ProfileManager {

    private SessionStorage sessionStorage;

    public ProfileManager(SessionStorage sessionStorage) {
        this.sessionStorage = sessionStorage;
    }

    public void loadProfiles(final boolean forceUpdate, final CmdiProfileSelectionPanel cmdiProfileSelectionPanel) {
        CmdiProfileReader.getSingleInstance().setSelection(ProfileSelection.ALL);
        cmdiProfileSelectionPanel.setStatus(false, "Loading, please wait...", false);
        new Thread("loadProfiles") {

            @Override
            public void run() {
                ArrayList<String> problemProfiles = new ArrayList<String>();
                // load the profiles selected for use on this diagram
                for (String profileId : new String[]{"clarin.eu:cr1:p_1320657629627"}) { // todo: this array should come from the list of selected profiles in the diagram
                    try {
                        cmdiProfileSelectionPanel.setStatus(false, "Loading: " + profileId + ", please wait...", false);
                        File xsdFile = new File(sessionStorage.getCacheDirectory(), "individual" + "-" + profileId + ".xsd");
                        if (!xsdFile.exists() || forceUpdate) {
                            new CmdiTransformer(sessionStorage).transformProfileXmlToXsd(xsdFile, profileId);
                        }
                    } catch (IOException exception) {
                        problemProfiles.add(profileId);
                        BugCatcherManager.getBugCatcher().logError(exception);
                    } catch (TransformerException exception) {
                        problemProfiles.add(profileId);
                        BugCatcherManager.getBugCatcher().logError(exception);
                    }
                }
                // load the profile list from the clarin server
                cmdiProfileSelectionPanel.setStatus(false, "Loading the profile list from the server, please wait...", false);
                CmdiProfileReader cmdiProfileReader = CmdiProfileReader.getSingleInstance();
                cmdiProfileReader.refreshProfilesAndUpdateCache(cmdiProfileSelectionPanel.getProfileReloadProgressBar(), forceUpdate);

                cmdiProfileSelectionPanel.setCmdiProfileReader(cmdiProfileReader);
                if (!problemProfiles.isEmpty()) {
                    // todo: show a message dialogue
                    cmdiProfileSelectionPanel.setStatus(true, "There were " + problemProfiles.size() + " selected profiles that could not be retrieved", true);
                } else {
                    cmdiProfileSelectionPanel.setStatus(true, "", false);
                }
            }
        }.start();
    }
}
<commit_msg>Added code to remove relations between entities. Updated the diagram context menu. Added a functional remove relations menu item. Updated the profile selection panel to; provide progress feedback, no download any profiles until requested, when a profile is selected download and convert the required profile, give better feedback when an error occurs. Updated the add entity to provide better feedback when there is an error creating an entity and to always clear the progress bar even when there is an error. Modified the profile transformer code to delete output and intermediate files when there was an error.<commit_after>package nl.mpi.kinnate.kindocument;

import java.util.ArrayList;
import nl.mpi.arbil.clarin.profiles.CmdiProfileReader;
import nl.mpi.arbil.clarin.profiles.CmdiProfileReader.ProfileSelection;
import nl.mpi.arbil.userstorage.SessionStorage;
import nl.mpi.arbil.util.BugCatcherManager;
import nl.mpi.arbil.util.MessageDialogHandler;
import nl.mpi.kinnate.ui.entityprofiles.CmdiProfileSelectionPanel;

/**
 *  Document   : ProfileManager
 *  Created on : Jan 30, 2012, 12:03:11 PM
 *  Author     : <NAME>
 */
public class ProfileManager {

    private SessionStorage sessionStorage;
    private MessageDialogHandler dialogHandler;
    private CmdiProfileSelectionPanel cmdiProfileSelectionPanel;
    private ArrayList<String> selectedProfiles = new ArrayList<String>();

    public ProfileManager(SessionStorage sessionStorage, MessageDialogHandler dialogHandler) {
        this.sessionStorage = sessionStorage;
        this.dialogHandler = dialogHandler;
    }

    public void loadProfiles(final boolean forceUpdate, final CmdiProfileSelectionPanel cmdiProfileSelectionPanel) {
        this.cmdiProfileSelectionPanel = cmdiProfileSelectionPanel;
        CmdiProfileReader.getSingleInstance().setSelection(ProfileSelection.ALL);
        cmdiProfileSelectionPanel.setStatus(false, "Loading, please wait...", false);
        new Thread("loadProfiles") {

            @Override
            public void run() {
                ArrayList<String> problemProfiles = new ArrayList<String>();
                // load the profiles selected for use on this diagram
                for (String profileId : new String[]{"clarin.eu:cr1:p_1320657629627"}) { // todo: this array should come from the list of selected profiles in the diagram
                    cmdiProfileSelectionPanel.setStatus(false, "Loading: " + profileId + ", please wait...", false);
                    try {
                        preloadProfile(profileId, forceUpdate);
                    } catch (KinXsdException exception) {
                        problemProfiles.add(profileId);
                        BugCatcherManager.getBugCatcher().logError(exception);
                    }
                }
                // load the profile list from the clarin server
                cmdiProfileSelectionPanel.setStatus(false, "Loading the profile list from the server, please wait...", false);
                CmdiProfileReader cmdiProfileReader = CmdiProfileReader.getSingleInstance();
                cmdiProfileReader.refreshProfiles(forceUpdate);

                cmdiProfileSelectionPanel.setCmdiProfileReader(cmdiProfileReader, ProfileManager.this);
                if (!problemProfiles.isEmpty()) {
                    // todo: show a message dialogue
                    cmdiProfileSelectionPanel.setStatus(true, "There were " + problemProfiles.size() + " selected profiles that could not be retrieved", true);
                } else {
                    cmdiProfileSelectionPanel.setStatus(true, "", false);
                }
            }
        }.start();
    }

    private void preloadProfile(String profileId, boolean forceUpdate) throws KinXsdException {
//        File xsdFile = new File(sessionStorage.getCacheDirectory(), "individual" + "-" + profileId + ".xsd");
//        if (!xsdFile.exists() || forceUpdate) {
        new CmdiTransformer(sessionStorage).getXsd(profileId, forceUpdate);
//        }
    }

    public void addProfileSelection(final String profileId, final String displayName) {
        new Thread("addProfileSelection") {

            @Override
            public void run() {
                try {
                    cmdiProfileSelectionPanel.setStatus(false, "Loading, please wait...", false);
                    preloadProfile(profileId, false);
                    selectedProfiles.add(profileId);
//            return true;
                } catch (KinXsdException exception) {
                    BugCatcherManager.getBugCatcher().logError(exception);
                    dialogHandler.addMessageDialogToQueue("The selected profile (" + displayName + ") could not be loaded.", "Profile Selection Error");
//            return false;
                }
                cmdiProfileSelectionPanel.setStatus(true, "", false);
            }
        }.start();

    }

    public void removeProfileSelection(String profileId) {
        selectedProfiles.remove(profileId);
    }

    public boolean profileIsSelected(String profileId) {
        return selectedProfiles.contains(profileId);
    }
}

{'fraction_non_alphanumeric': 0.08427433733507667, 'fraction_numerical': 0.006180910495661477, 'mean_word_length': 2.5397559949516197, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1565681', 'n_tokens_mistral': 2130, 'n_tokens_neox': 1990, 'n_words': 514}