Search in sources :

Example 1 with Feature

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

the class ReconciliationReportlet method doExtract.

private void doExtract(final ContentHandler handler, final Any<?> any, final Set<Missing> missing, final Set<Misaligned> misaligned) throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    for (Feature feature : conf.getFeatures()) {
        String type = null;
        String value = null;
        switch(feature) {
            case key:
                type = ReportXMLConst.XSD_STRING;
                value = any.getKey();
                break;
            case username:
                if (any instanceof User) {
                    type = ReportXMLConst.XSD_STRING;
                    value = User.class.cast(any).getUsername();
                }
                break;
            case groupName:
                if (any instanceof Group) {
                    type = ReportXMLConst.XSD_STRING;
                    value = Group.class.cast(any).getName();
                }
                break;
            case workflowId:
                type = ReportXMLConst.XSD_STRING;
                value = any.getWorkflowId();
                break;
            case status:
                type = ReportXMLConst.XSD_STRING;
                value = any.getStatus();
                break;
            case creationDate:
                type = ReportXMLConst.XSD_DATETIME;
                value = any.getCreationDate() == null ? StringUtils.EMPTY : FormatUtils.format(any.getCreationDate());
                break;
            case lastLoginDate:
                if (any instanceof User) {
                    type = ReportXMLConst.XSD_DATETIME;
                    value = User.class.cast(any).getLastLoginDate() == null ? StringUtils.EMPTY : FormatUtils.format(User.class.cast(any).getLastLoginDate());
                }
                break;
            case changePwdDate:
                if (any instanceof User) {
                    type = ReportXMLConst.XSD_DATETIME;
                    value = User.class.cast(any).getChangePwdDate() == null ? StringUtils.EMPTY : FormatUtils.format(User.class.cast(any).getChangePwdDate());
                }
                break;
            case passwordHistorySize:
                if (any instanceof User) {
                    type = ReportXMLConst.XSD_INT;
                    value = String.valueOf(User.class.cast(any).getPasswordHistory().size());
                }
                break;
            case failedLoginCount:
                if (any instanceof User) {
                    type = ReportXMLConst.XSD_INT;
                    value = String.valueOf(User.class.cast(any).getFailedLogins());
                }
                break;
            default:
        }
        if (type != null && value != null) {
            atts.addAttribute("", "", feature.name(), type, value);
        }
    }
    handler.startElement("", "", getAnyElementName(any.getType().getKind()), atts);
    for (Missing item : missing) {
        atts.clear();
        atts.addAttribute("", "", "resource", ReportXMLConst.XSD_STRING, item.getResource());
        atts.addAttribute("", "", "connObjectKeyValue", ReportXMLConst.XSD_STRING, item.getConnObjectKeyValue());
        handler.startElement("", "", "missing", atts);
        handler.endElement("", "", "missing");
    }
    for (Misaligned item : misaligned) {
        atts.clear();
        atts.addAttribute("", "", "resource", ReportXMLConst.XSD_STRING, item.getResource());
        atts.addAttribute("", "", "connObjectKeyValue", ReportXMLConst.XSD_STRING, item.getConnObjectKeyValue());
        atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, item.getName());
        handler.startElement("", "", "misaligned", atts);
        handler.startElement("", "", "onSyncope", null);
        if (item.getOnSyncope() != null) {
            for (Object value : item.getOnSyncope()) {
                char[] asChars = value.toString().toCharArray();
                handler.startElement("", "", "value", null);
                handler.characters(asChars, 0, asChars.length);
                handler.endElement("", "", "value");
            }
        }
        handler.endElement("", "", "onSyncope");
        handler.startElement("", "", "onResource", null);
        if (item.getOnResource() != null) {
            for (Object value : item.getOnResource()) {
                char[] asChars = value.toString().toCharArray();
                handler.startElement("", "", "value", null);
                handler.characters(asChars, 0, asChars.length);
                handler.endElement("", "", "value");
            }
        }
        handler.endElement("", "", "onResource");
        handler.endElement("", "", "misaligned");
    }
    handler.endElement("", "", getAnyElementName(any.getType().getKind()));
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) AttributesImpl(org.xml.sax.helpers.AttributesImpl) User(org.apache.syncope.core.persistence.api.entity.user.User) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) Feature(org.apache.syncope.common.lib.report.ReconciliationReportletConf.Feature)

Aggregations

Feature (org.apache.syncope.common.lib.report.ReconciliationReportletConf.Feature)1 Group (org.apache.syncope.core.persistence.api.entity.group.Group)1 User (org.apache.syncope.core.persistence.api.entity.user.User)1 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1