Search in sources :

Example 1 with PortalDataKey

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));
    }
}
Also used : StringReader(java.io.StringReader) XMLEventReader(javax.xml.stream.XMLEventReader) PortalDataKey(org.apereo.portal.io.xml.PortalDataKey) Test(org.junit.Test)

Example 2 with PortalDataKey

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;
    }
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpELDataTemplatingStrategy(org.apereo.portal.io.xml.SpELDataTemplatingStrategy) IDataTemplatingStrategy(org.apereo.portal.io.xml.IDataTemplatingStrategy) PortalDataKey(org.apereo.portal.io.xml.PortalDataKey) Document(org.dom4j.Document) Source(javax.xml.transform.Source) URISyntaxException(java.net.URISyntaxException)

Example 3 with PortalDataKey

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Resource(org.springframework.core.io.Resource) PortalDataKey(org.apereo.portal.io.xml.PortalDataKey) Document(org.dom4j.Document) URISyntaxException(java.net.URISyntaxException)

Example 4 with PortalDataKey

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);
}
Also used : IPortalDataType(org.apereo.portal.io.xml.IPortalDataType) ArrayList(java.util.ArrayList) PortalDataKey(org.apereo.portal.io.xml.PortalDataKey)

Example 5 with PortalDataKey

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;
}
Also used : StartElement(javax.xml.stream.events.StartElement) PortalDataKey(org.apereo.portal.io.xml.PortalDataKey)

Aggregations

PortalDataKey (org.apereo.portal.io.xml.PortalDataKey)6 URISyntaxException (java.net.URISyntaxException)2 Document (org.dom4j.Document)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 StartElement (javax.xml.stream.events.StartElement)1 Source (javax.xml.transform.Source)1 StAXSource (javax.xml.transform.stax.StAXSource)1 EntityIdentifier (org.apereo.portal.EntityIdentifier)1 IDataTemplatingStrategy (org.apereo.portal.io.xml.IDataTemplatingStrategy)1 IPortalDataType (org.apereo.portal.io.xml.IPortalDataType)1 SpELDataTemplatingStrategy (org.apereo.portal.io.xml.SpELDataTemplatingStrategy)1 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)1 IPerson (org.apereo.portal.security.IPerson)1 BufferedXMLEventReader (org.apereo.portal.xml.stream.BufferedXMLEventReader)1 Test (org.junit.Test)1