Search in sources :

Example 1 with Feature

use of org.apache.syncope.common.lib.report.GroupReportletConf.Feature in project syncope by apache.

the class GroupReportlet method doExtract.

private void doExtract(final ContentHandler handler, final List<Group> groups) throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    for (Group group : groups) {
        atts.clear();
        for (Feature feature : conf.getFeatures()) {
            String type = null;
            String value = null;
            switch(feature) {
                case key:
                    type = ReportXMLConst.XSD_STRING;
                    value = group.getKey();
                    break;
                case name:
                    type = ReportXMLConst.XSD_STRING;
                    value = String.valueOf(group.getName());
                    break;
                case groupOwner:
                    type = ReportXMLConst.XSD_STRING;
                    value = group.getGroupOwner().getKey();
                    break;
                case userOwner:
                    type = ReportXMLConst.XSD_STRING;
                    value = group.getUserOwner().getKey();
                    break;
                default:
            }
            if (type != null && value != null) {
                atts.addAttribute("", "", feature.name(), type, value);
            }
        }
        handler.startElement("", "", "group", atts);
        // Using GroupTO for attribute values, since the conversion logic of
        // values to String is already encapsulated there
        GroupTO groupTO = groupDataBinder.getGroupTO(group, true);
        doExtractAttributes(handler, groupTO, conf.getPlainAttrs(), conf.getDerAttrs(), conf.getVirAttrs());
        // to get resources associated to a group
        if (conf.getFeatures().contains(Feature.resources)) {
            doExtractResources(handler, groupTO);
        }
        // to get users asscoiated to a group is preferred GroupDAO to GroupTO
        if (conf.getFeatures().contains(Feature.users)) {
            handler.startElement("", "", "users", null);
            for (UMembership memb : groupDAO.findUMemberships(group)) {
                atts.clear();
                atts.addAttribute("", "", "key", ReportXMLConst.XSD_STRING, memb.getLeftEnd().getKey());
                atts.addAttribute("", "", "username", ReportXMLConst.XSD_STRING, String.valueOf(memb.getLeftEnd().getUsername()));
                handler.startElement("", "", "user", atts);
                handler.endElement("", "", "user");
            }
            handler.endElement("", "", "users");
        }
        handler.endElement("", "", "group");
    }
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) AttributesImpl(org.xml.sax.helpers.AttributesImpl) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) Feature(org.apache.syncope.common.lib.report.GroupReportletConf.Feature) GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 2 with Feature

use of org.apache.syncope.common.lib.report.GroupReportletConf.Feature in project syncope by apache.

the class GroupReportlet method doExtractConf.

private void doExtractConf(final ContentHandler handler) throws SAXException {
    if (conf == null) {
        LOG.debug("Report configuration is not present");
    }
    AttributesImpl atts = new AttributesImpl();
    handler.startElement("", "", "configurations", null);
    handler.startElement("", "", "groupAttributes", atts);
    if (conf != null) {
        for (Feature feature : conf.getFeatures()) {
            atts.clear();
            handler.startElement("", "", "feature", atts);
            handler.characters(feature.name().toCharArray(), 0, feature.name().length());
            handler.endElement("", "", "feature");
        }
        for (String attr : conf.getPlainAttrs()) {
            atts.clear();
            handler.startElement("", "", "attribute", atts);
            handler.characters(attr.toCharArray(), 0, attr.length());
            handler.endElement("", "", "attribute");
        }
        for (String derAttr : conf.getDerAttrs()) {
            atts.clear();
            handler.startElement("", "", "derAttribute", atts);
            handler.characters(derAttr.toCharArray(), 0, derAttr.length());
            handler.endElement("", "", "derAttribute");
        }
        for (String virAttr : conf.getVirAttrs()) {
            atts.clear();
            handler.startElement("", "", "virAttribute", atts);
            handler.characters(virAttr.toCharArray(), 0, virAttr.length());
            handler.endElement("", "", "virAttribute");
        }
    }
    handler.endElement("", "", "groupAttributes");
    handler.endElement("", "", "configurations");
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Feature(org.apache.syncope.common.lib.report.GroupReportletConf.Feature)

Aggregations

Feature (org.apache.syncope.common.lib.report.GroupReportletConf.Feature)2 AttributesImpl (org.xml.sax.helpers.AttributesImpl)2 GroupTO (org.apache.syncope.common.lib.to.GroupTO)1 Group (org.apache.syncope.core.persistence.api.entity.group.Group)1 UMembership (org.apache.syncope.core.persistence.api.entity.user.UMembership)1