use of org.apache.syncope.common.lib.report.UserReportletConf.Feature in project syncope by apache.
the class UserReportlet method doExtract.
private void doExtract(final ContentHandler handler, final List<User> users) throws SAXException {
AttributesImpl atts = new AttributesImpl();
for (User user : users) {
atts.clear();
for (Feature feature : conf.getFeatures()) {
String type = null;
String value = null;
switch(feature) {
case key:
type = ReportXMLConst.XSD_STRING;
value = user.getKey();
break;
case username:
type = ReportXMLConst.XSD_STRING;
value = user.getUsername();
break;
case workflowId:
type = ReportXMLConst.XSD_STRING;
value = user.getWorkflowId();
break;
case status:
type = ReportXMLConst.XSD_STRING;
value = user.getStatus();
break;
case creationDate:
type = ReportXMLConst.XSD_DATETIME;
value = user.getCreationDate() == null ? "" : FormatUtils.format(user.getCreationDate());
break;
case lastLoginDate:
type = ReportXMLConst.XSD_DATETIME;
value = user.getLastLoginDate() == null ? "" : FormatUtils.format(user.getLastLoginDate());
break;
case changePwdDate:
type = ReportXMLConst.XSD_DATETIME;
value = user.getChangePwdDate() == null ? "" : FormatUtils.format(user.getChangePwdDate());
break;
case passwordHistorySize:
type = ReportXMLConst.XSD_INT;
value = String.valueOf(user.getPasswordHistory().size());
break;
case failedLoginCount:
type = ReportXMLConst.XSD_INT;
value = String.valueOf(user.getFailedLogins());
break;
default:
}
if (type != null && value != null) {
atts.addAttribute("", "", feature.name(), type, value);
}
}
handler.startElement("", "", "user", atts);
// Using UserTO for attribute values, since the conversion logic of
// values to String is already encapsulated there
UserTO userTO = userDataBinder.getUserTO(user, true);
doExtractAttributes(handler, userTO, conf.getPlainAttrs(), conf.getDerAttrs(), conf.getVirAttrs());
if (conf.getFeatures().contains(Feature.relationships)) {
handler.startElement("", "", "relationships", null);
for (RelationshipTO rel : userTO.getRelationships()) {
atts.clear();
atts.addAttribute("", "", "anyObjectKey", ReportXMLConst.XSD_STRING, rel.getOtherEndKey());
handler.startElement("", "", "relationship", atts);
if (conf.getFeatures().contains(Feature.resources)) {
for (URelationship actualRel : user.getRelationships(rel.getOtherEndKey())) {
doExtractResources(handler, anyObjectDataBinder.getAnyObjectTO(actualRel.getRightEnd(), true));
}
}
handler.endElement("", "", "relationship");
}
handler.endElement("", "", "relationships");
}
if (conf.getFeatures().contains(Feature.memberships)) {
handler.startElement("", "", "memberships", null);
for (MembershipTO memb : userTO.getMemberships()) {
atts.clear();
atts.addAttribute("", "", "groupKey", ReportXMLConst.XSD_STRING, memb.getGroupKey());
atts.addAttribute("", "", "groupName", ReportXMLConst.XSD_STRING, memb.getGroupName());
handler.startElement("", "", "membership", atts);
if (conf.getFeatures().contains(Feature.resources)) {
UMembership actualMemb = user.getMembership(memb.getGroupKey()).orElse(null);
if (actualMemb == null) {
LOG.warn("Unexpected: cannot find membership for group {} for user {}", memb.getGroupKey(), user);
} else {
doExtractResources(handler, groupDataBinder.getGroupTO(actualMemb.getRightEnd(), true));
}
}
handler.endElement("", "", "membership");
}
handler.endElement("", "", "memberships");
}
if (conf.getFeatures().contains(Feature.resources)) {
doExtractResources(handler, userTO);
}
handler.endElement("", "", "user");
}
}
use of org.apache.syncope.common.lib.report.UserReportletConf.Feature in project syncope by apache.
the class UserReportlet method doExtractConf.
private void doExtractConf(final ContentHandler handler) throws SAXException {
AttributesImpl atts = new AttributesImpl();
handler.startElement("", "", "configurations", null);
handler.startElement("", "", "userAttributes", atts);
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("", "", "userAttributes");
handler.endElement("", "", "configurations");
}
Aggregations