use of pcgen.persistence.PersistenceManager in project pcgen by PCGen.
the class PreCampaignTest method testNestedKeyMatch.
/**
* Test matching by key.
*
* @throws Exception the exception
*/
@Test
public void testNestedKeyMatch() throws Exception {
// Setup campaigns
PersistenceManager pmgr = PersistenceManager.getInstance();
List<URI> uris = new ArrayList<>();
uris.add(camp1.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
final PreParserFactory factory = PreParserFactory.getInstance();
Prerequisite preCampaign = factory.parse("PRECAMPAIGN:1,INCLUDES=Camp3");
assertFalse("Nonpresent campaign should not be found", PrereqHandler.passes(preCampaign, null, sourceCamp));
uris.add(camp2KeyParent.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
assertTrue("Present but nested campaign should be found", PrereqHandler.passes(preCampaign, null, sourceCamp));
}
use of pcgen.persistence.PersistenceManager in project pcgen by PCGen.
the class PreCampaignTest method testKeyMatch.
/**
* Test matching by key.
*
* @throws Exception the exception
*/
@Test
public void testKeyMatch() throws Exception {
// Setup campaigns
PersistenceManager pmgr = PersistenceManager.getInstance();
List<URI> uris = new ArrayList<>();
pmgr.setChosenCampaignSourcefiles(uris);
final PreParserFactory factory = PreParserFactory.getInstance();
Prerequisite preCamp1 = factory.parse("PRECAMPAIGN:1,Camp1");
assertFalse("Nonpresent campaign should not be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
uris = new ArrayList<>();
uris.add(camp1.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
assertTrue("Present campaign should be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
uris.add(camp2KeyParent.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
Prerequisite preCamp3 = factory.parse("PRECAMPAIGN:1,Camp3");
assertFalse("Present but nested campaign should not be found", PrereqHandler.passes(preCamp3, null, sourceCamp));
}
use of pcgen.persistence.PersistenceManager in project pcgen by PCGen.
the class Gui2CampaignInfoFactory method getHTMLInfo.
@Override
public String getHTMLInfo(CampaignFacade campaign, List<CampaignFacade> testList) {
PersistenceManager pman = PersistenceManager.getInstance();
List<URI> oldList = setSourcesForPrereqTesting(testList, pman);
String htmlInfo = getHTMLInfo(campaign);
pman.setChosenCampaignSourcefiles(oldList);
return htmlInfo;
}
use of pcgen.persistence.PersistenceManager in project pcgen by PCGen.
the class PreCampaignTester method countCampaignByName.
/**
* Count the campaigns currently loaded or selected that match the
* supplied key name.
*
* @param key The key to be checked for
* @param includeSubCampaigns Should we count included sub campaigns that match
* @return The number of matching campaigns
*/
private int countCampaignByName(final String key, CDOMObject source, boolean includeSubCampaigns) {
int total = 0;
Campaign campaignToFind = Globals.getCampaignKeyedSilently(key);
if (campaignToFind != null) {
PersistenceManager pMan = PersistenceManager.getInstance();
List<URI> selCampaigns = pMan.getChosenCampaignSourcefiles();
for (URI element : selCampaigns) {
final Campaign aCampaign = Globals.getCampaignByURI(element, true);
if (includeSubCampaigns) {
List<Campaign> campList = getFullCampaignList(aCampaign);
for (Campaign camp : campList) {
if (camp.equals(campaignToFind)) {
++total;
}
}
} else {
if (aCampaign.equals(campaignToFind)) {
++total;
}
}
}
} else {
String sourceUri = (source == null ? "" : String.valueOf(source.getSourceURI()));
Logging.errorPrint(//$NON-NLS-1$
"Unable to find campaign " + key + " used in prereq for source " + source + //$NON-NLS-1$ //$NON-NLS-2$
" at " + sourceUri);
}
return total;
}
Aggregations