use of org.apereo.portal.io.xml.PortalDataKey in project uPortal by Jasig.
the class LayoutPortalDataTypeTest method testPostProcessSinglePortalDataKey_detectFragmentLayout.
@Test
public void testPostProcessSinglePortalDataKey_detectFragmentLayout() throws Exception {
LayoutPortalDataType lpdt = new LayoutPortalDataType();
XMLEventReader fragmentLayoutReader = FAC.createXMLEventReader(new StringReader(FRAGMENT_LAYOUT_NODE));
String[] fragmentSystemIds = new String[] { "foo.fragment-layout", "foo.fragment-layout.xml" };
for (String sysId : fragmentSystemIds) {
Set<PortalDataKey> keys = lpdt.postProcessPortalDataKey(sysId, REGULAR_LAYOUT_DATA_KEY, fragmentLayoutReader);
assertEquals("postProcessPortalDataKey() returned the wrong number of results. Expected 1, was " + keys.size(), keys.size(), 1);
assertTrue("postProcessPortalDataKey() failed to detect a fragment layout for systemId=" + sysId, keys.contains(FRAGMENT_LAYOUT_DATA_KEY));
}
XMLEventReader regularLayoutReader = FAC.createXMLEventReader(new StringReader(REGULAR_LAYOUT_NODE));
String[] regularSystemIds = new String[] { "foo.layout", "foo.layout.xml" };
for (String sysId : regularSystemIds) {
Set<PortalDataKey> keys = lpdt.postProcessPortalDataKey(sysId, REGULAR_LAYOUT_DATA_KEY, regularLayoutReader);
assertEquals("postProcessPortalDataKey() returned the wrong number of results. Expected 1, was " + keys.size(), keys.size(), 1);
assertTrue("postProcessPortalDataKey() failed to detect a fragment layout for systemId=" + sysId, keys.contains(REGULAR_LAYOUT_DATA_KEY));
}
}
use of org.apereo.portal.io.xml.PortalDataKey in project uPortal by Jasig.
the class TemplateDataTenantOperationsListener method importQueue.
/** Imports the specified entities in the proper order. */
private void importQueue(final ITenant tenant, final Map<PortalDataKey, Set<BucketTuple>> queue, final StringBuilder importReport) throws Exception {
final StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.setRootObject(new RootObjectImpl(tenant));
IDataTemplatingStrategy templating = new SpELDataTemplatingStrategy(portalSpELService, ctx);
Document doc = null;
try {
for (PortalDataKey pdk : dataKeyImportOrder) {
Set<BucketTuple> bucket = queue.get(pdk);
if (bucket != null) {
log.debug("Importing the specified PortalDataKey tenant '{}': {}", tenant.getName(), pdk.getName());
for (BucketTuple tuple : bucket) {
doc = tuple.getDocument();
Source data = templating.processTemplates(doc, tuple.getResource().getURL().toString());
dataHandlerService.importData(data, pdk);
importReport.append(createImportReportLineItem(pdk, tuple));
}
}
}
} catch (Exception e) {
log.error("Failed to process the specified template document:\n{}", (doc != null ? doc.asXML() : "null"), e);
throw e;
}
}
use of org.apereo.portal.io.xml.PortalDataKey in project uPortal by Jasig.
the class TemplateDataTenantOperationsListener method prepareImportQueue.
/** Loads dom4j Documents and sorts the entity files into the proper order for Import. */
private Map<PortalDataKey, Set<BucketTuple>> prepareImportQueue(final ITenant tenant, final Set<Resource> templates) throws Exception {
final Map<PortalDataKey, Set<BucketTuple>> rslt = new HashMap<PortalDataKey, Set<BucketTuple>>();
Resource rsc = null;
try {
for (Resource r : templates) {
rsc = r;
if (log.isDebugEnabled()) {
log.debug("Loading template resource file for tenant " + "'" + tenant.getFname() + "': " + rsc.getFilename());
}
final Document doc = reader.read(rsc.getInputStream());
PortalDataKey atLeastOneMatchingDataKey = null;
for (PortalDataKey pdk : dataKeyImportOrder) {
boolean matches = evaluatePortalDataKeyMatch(doc, pdk);
if (matches) {
// Found the right bucket...
log.debug("Found PortalDataKey '{}' for data document {}", pdk, r.getURI());
atLeastOneMatchingDataKey = pdk;
Set<BucketTuple> bucket = rslt.get(atLeastOneMatchingDataKey);
if (bucket == null) {
// First of these we've seen; create the bucket;
bucket = new HashSet<BucketTuple>();
rslt.put(atLeastOneMatchingDataKey, bucket);
}
BucketTuple tuple = new BucketTuple(rsc, doc);
bucket.add(tuple);
/*
* At this point, we would normally add a break;
* statement, but group_membership.xml files need to
* match more than one PortalDataKey.
*/
}
}
if (atLeastOneMatchingDataKey == null) {
// We can't proceed
throw new RuntimeException("No PortalDataKey found for QName: " + doc.getRootElement().getQName());
}
}
} catch (Exception e) {
log.error("Failed to process the specified template: {}", (rsc != null ? rsc.getFilename() : "null"), e);
throw e;
}
return rslt;
}
use of org.apereo.portal.io.xml.PortalDataKey in project uPortal by Jasig.
the class TemplateDataTenantOperationsListener method setDataTypeImportOrder.
/** Order in which data types should be imported. */
@javax.annotation.Resource(name = "dataTypeImportOrder")
public void setDataTypeImportOrder(List<IPortalDataType> dataTypeImportOrder) {
final ArrayList<PortalDataKey> dataKeyImportOrder = new ArrayList<PortalDataKey>(dataTypeImportOrder.size() * 2);
for (final IPortalDataType portalDataType : dataTypeImportOrder) {
final List<PortalDataKey> supportedDataKeys = portalDataType.getDataKeyImportOrder();
for (final PortalDataKey portalDataKey : supportedDataKeys) {
/*
* Special Handling: Need to prevent some keys from entering our
* sorted collection because they attempt to import both a group
* part and the membership parts of a group (either local or PAGS)
* in one go. We import several entities at once, so it's important
* to do these in 2 phases.
*/
if (!KEYS_TO_IGNORE.contains(portalDataKey)) {
dataKeyImportOrder.add(portalDataKey);
}
}
}
dataKeyImportOrder.trimToSize();
this.dataKeyImportOrder = Collections.unmodifiableList(dataKeyImportOrder);
}
use of org.apereo.portal.io.xml.PortalDataKey in project uPortal by Jasig.
the class ImportExportController method getPortalDataKey.
protected PortalDataKey getPortalDataKey(final BufferedXMLEventReader bufferedXmlEventReader) {
final StartElement rootElement = StaxUtils.getRootElement(bufferedXmlEventReader);
final PortalDataKey portalDataKey = new PortalDataKey(rootElement);
bufferedXmlEventReader.reset();
return portalDataKey;
}
Aggregations