Search in sources :

Example 1 with ReconciliationReportletConf

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

the class ReconciliationReportlet method doExtract.

@Override
protected void doExtract(final ReportletConf conf, final ContentHandler handler, final AtomicReference<String> status) throws SAXException {
    if (conf instanceof ReconciliationReportletConf) {
        this.conf = ReconciliationReportletConf.class.cast(conf);
    } else {
        throw new ReportException(new IllegalArgumentException("Invalid configuration provided"));
    }
    AttributesImpl atts = new AttributesImpl();
    if (StringUtils.isBlank(this.conf.getUserMatchingCond())) {
        int total = userDAO.count();
        int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
        status.set("Processing " + total + " users in " + pages + " pages");
        atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
        handler.startElement("", "", getAnyElementName(AnyTypeKind.USER) + "s", atts);
        for (int page = 1; page <= pages; page++) {
            status.set("Processing " + total + " users: page " + page + " of " + pages);
            doExtract(handler, userDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE));
        }
    } else {
        SearchCond cond = SearchCondConverter.convert(this.conf.getUserMatchingCond());
        int total = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, cond, AnyTypeKind.USER);
        int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
        status.set("Processing " + total + " users in " + pages + " pages");
        atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
        handler.startElement("", "", getAnyElementName(AnyTypeKind.USER) + "s", atts);
        for (int page = 1; page <= pages; page++) {
            status.set("Processing " + total + " users: page " + page + " of " + pages);
            doExtract(handler, searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, cond, page, PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.USER));
        }
    }
    handler.endElement("", "", getAnyElementName(AnyTypeKind.USER) + "s");
    atts.clear();
    if (StringUtils.isBlank(this.conf.getGroupMatchingCond())) {
        int total = groupDAO.count();
        int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
        status.set("Processing " + total + " groups in " + pages + " pages");
        atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
        handler.startElement("", "", getAnyElementName(AnyTypeKind.GROUP) + "s", atts);
        for (int page = 1; page <= pages; page++) {
            status.set("Processing " + total + " groups: page " + page + " of " + pages);
            doExtract(handler, groupDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE));
        }
    } else {
        SearchCond cond = SearchCondConverter.convert(this.conf.getUserMatchingCond());
        int total = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, cond, AnyTypeKind.GROUP);
        int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
        status.set("Processing " + total + " groups in " + pages + " pages");
        atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
        handler.startElement("", "", getAnyElementName(AnyTypeKind.GROUP) + "s", atts);
        for (int page = 1; page <= pages; page++) {
            status.set("Processing " + total + " groups: page " + page + " of " + pages);
            doExtract(handler, searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, cond, page, PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.GROUP));
        }
    }
    handler.endElement("", "", getAnyElementName(AnyTypeKind.GROUP) + "s");
    for (AnyType anyType : anyTypeDAO.findAll()) {
        if (!anyType.equals(anyTypeDAO.findUser()) && !anyType.equals(anyTypeDAO.findGroup())) {
            AnyTypeCond anyTypeCond = new AnyTypeCond();
            anyTypeCond.setAnyTypeKey(anyType.getKey());
            SearchCond cond = StringUtils.isBlank(this.conf.getAnyObjectMatchingCond()) ? SearchCond.getLeafCond(anyTypeCond) : SearchCond.getAndCond(SearchCond.getLeafCond(anyTypeCond), SearchCondConverter.convert(this.conf.getAnyObjectMatchingCond()));
            int total = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, cond, AnyTypeKind.ANY_OBJECT);
            int pages = (total / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
            status.set("Processing " + total + " any objects " + anyType.getKey() + " in " + pages + " pages");
            atts.clear();
            atts.addAttribute("", "", "type", ReportXMLConst.XSD_STRING, anyType.getKey());
            atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(total));
            handler.startElement("", "", getAnyElementName(AnyTypeKind.ANY_OBJECT) + "s", atts);
            for (int page = 1; page <= pages; page++) {
                status.set("Processing " + total + " any objects " + anyType.getKey() + ": page " + page + " of " + pages);
                doExtract(handler, searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, cond, page, PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.ANY_OBJECT));
            }
            handler.endElement("", "", getAnyElementName(AnyTypeKind.ANY_OBJECT) + "s");
        }
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) ReconciliationReportletConf(org.apache.syncope.common.lib.report.ReconciliationReportletConf) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType)

Aggregations

ReconciliationReportletConf (org.apache.syncope.common.lib.report.ReconciliationReportletConf)1 AnyTypeCond (org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond)1 OrderByClause (org.apache.syncope.core.persistence.api.dao.search.OrderByClause)1 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)1 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1