use of org.gluu.oxtrust.model.scim2.MemberRef in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
/**
* Copy data from ScimGroup object to GluuGroupn object
*
* @param source
* @param destination
* @param isUpdate
* @return
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
* @throws Exception
*/
public GluuGroup copy(Group source, GluuGroup destination, boolean isUpdate) throws Exception {
if (source == null || !isValidData(source, isUpdate)) {
return null;
}
if (destination == null) {
log.trace(" creating a new GluuGroup instant ");
destination = new GluuGroup();
}
if (isUpdate) {
if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
destination.setDisplayName(source.getDisplayName());
}
if (source.getMembers() != null && source.getMembers().size() > 0) {
Set<MemberRef> members = source.getMembers();
List<String> listMembers = new ArrayList<String>();
for (MemberRef member : members) {
listMembers.add(personService.getDnForPerson(member.getValue()));
}
destination.setMembers(listMembers);
}
} else {
log.trace(" creating a new GroupService instant ");
log.trace(" source.getDisplayName() : ", source.getDisplayName());
if (groupService.getGroupByDisplayName(source.getDisplayName()) != null) {
log.trace(" groupService1.getGroupByDisplayName(source.getDisplayName() != null : ");
return null;
}
if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
destination.setDisplayName(source.getDisplayName());
}
log.trace(" source.getMembers() : ", source.getMembers());
log.trace(" source.getMembers().size() : ", source.getMembers().size());
if (source.getMembers() != null && source.getMembers().size() > 0) {
Set<MemberRef> members = source.getMembers();
List<String> listMembers = new ArrayList<String>();
for (MemberRef member : members) {
listMembers.add(personService.getDnForPerson(member.getValue()));
}
destination.setMembers(listMembers);
}
/*GluuCustomPerson authUser = (GluuCustomPerson) identity.getSessionMap().get(OxTrustConstants.CURRENT_PERSON);
destination.setOwner(authUser.getDn());
log.trace(" authUser.getDn() : ", authUser.getDn());*/
destination.setStatus(GluuStatus.ACTIVE);
destination.setOrganization(organizationService.getDnForOrganization());
}
return destination;
}
use of org.gluu.oxtrust.model.scim2.MemberRef in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
/**
* Copy data from GluuGroup object to ScimGroup object
*
* @param source
* @param destination
* @return
* @throws Exception
*/
public Group copy(GluuGroup source, Group destination) throws Exception {
if (source == null) {
return null;
}
if (destination == null) {
destination = new Group();
}
destination.setDisplayName(source.getDisplayName());
destination.setId(source.getInum());
if (source.getMembers() != null) {
if (source.getMembers().size() > 0) {
Set<MemberRef> memberRefSet = new HashSet<MemberRef>();
List<String> membersList = source.getMembers();
for (String oneMember : membersList) {
if (oneMember != null && !oneMember.isEmpty()) {
GluuCustomPerson gluuCustomPerson = personService.getPersonByDn(oneMember);
MemberRef memberRef = new MemberRef();
memberRef.setValue(gluuCustomPerson.getInum());
memberRef.setDisplay(gluuCustomPerson.getDisplayName());
String reference = appConfiguration.getBaseEndpoint() + "/scim/v2/Users/" + gluuCustomPerson.getInum();
memberRef.setReference(reference);
memberRefSet.add(memberRef);
}
}
destination.setMembers(memberRefSet);
}
}
log.trace(" getting meta ");
Meta meta = (destination.getMeta() != null) ? destination.getMeta() : new Meta();
if (source.getAttribute("oxTrustMetaVersion") != null) {
meta.setVersion(source.getAttribute("oxTrustMetaVersion"));
}
String location = source.getAttribute("oxTrustMetaLocation");
if (location != null && !location.isEmpty()) {
if (!location.startsWith("https://") && !location.startsWith("http://")) {
location = appConfiguration.getBaseEndpoint() + location;
}
} else {
location = appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/" + source.getInum();
}
meta.setLocation(location);
if (source.getAttribute("oxTrustMetaCreated") != null && !source.getAttribute("oxTrustMetaCreated").isEmpty()) {
try {
DateTime dateTimeUtc = new DateTime(source.getAttribute("oxTrustMetaCreated"), DateTimeZone.UTC);
meta.setCreated(dateTimeUtc.toDate());
} catch (Exception e) {
log.error(" Date parse exception (NEW format), continuing...", e);
// For backward compatibility
try {
meta.setCreated(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(source.getAttribute("oxTrustMetaCreated")));
} catch (Exception ex) {
log.error(" Date parse exception (OLD format)", ex);
}
}
}
if (source.getAttribute("oxTrustMetaLastModified") != null && !source.getAttribute("oxTrustMetaLastModified").isEmpty()) {
try {
DateTime dateTimeUtc = new DateTime(source.getAttribute("oxTrustMetaLastModified"), DateTimeZone.UTC);
meta.setLastModified(dateTimeUtc.toDate());
} catch (Exception e) {
log.error(" Date parse exception (NEW format), continuing...", e);
// For backward compatibility
try {
meta.setLastModified(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(source.getAttribute("oxTrustMetaLastModified")));
} catch (Exception ex) {
log.error(" Date parse exception (OLD format)", ex);
}
}
}
destination.setMeta(meta);
return destination;
}
use of org.gluu.oxtrust.model.scim2.MemberRef in project oxTrust by GluuFederation.
the class GroupCoreLoadingStrategy method createDummyGroup.
private Group createDummyGroup() {
Group group = new Group();
group.setId("");
group.setExternalId("");
group.setDisplayName("");
Set<MemberRef> members = new HashSet<MemberRef>();
MemberRef memberRef = new MemberRef();
memberRef.setOperation("");
memberRef.setPrimary(false);
memberRef.setValue("test");
memberRef.setDisplay("");
memberRef.setType(MemberRef.Type.USER);
memberRef.setReference("");
members.add(memberRef);
group.setMembers(members);
return group;
}
Aggregations