use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.
the class UserTest method issueSYNCOPE1016.
@Test
public void issueSYNCOPE1016() {
User user = userDAO.findByUsername("rossini");
Date initial = user.getLastChangeDate();
assertNotNull(initial);
UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
attr.setOwner(user);
attr.setSchema(plainSchemaDAO.find("obscure"));
attr.add("testvalue", anyUtilsFactory.getInstance(AnyTypeKind.USER));
user.add(attr);
userDAO.save(user);
userDAO.flush();
user = userDAO.findByUsername("rossini");
Date afterwards = user.getLastChangeDate();
assertNotNull(afterwards);
assertTrue(afterwards.after(initial));
}
use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.
the class NotificationManagerImpl method getRecipientEmail.
private String getRecipientEmail(final String recipientAttrName, final User user) {
String email = null;
IntAttrName intAttrName;
try {
intAttrName = intAttrNameParser.parse(recipientAttrName, AnyTypeKind.USER);
} catch (ParseException e) {
LOG.error("Invalid intAttrName '{}' specified as recipient, ignoring", recipientAttrName, e);
return email;
}
if ("username".equals(intAttrName.getField())) {
email = user.getUsername();
} else if (intAttrName.getSchemaType() != null) {
UMembership membership = null;
if (intAttrName.getMembershipOfGroup() != null) {
Group group = groupDAO.findByName(intAttrName.getMembershipOfGroup());
if (group != null) {
membership = user.getMembership(group.getKey()).orElse(null);
}
}
switch(intAttrName.getSchemaType()) {
case PLAIN:
Optional<? extends UPlainAttr> attr = membership == null ? user.getPlainAttr(recipientAttrName) : user.getPlainAttr(recipientAttrName, membership);
if (attr.isPresent()) {
email = attr.get().getValuesAsStrings().isEmpty() ? null : attr.get().getValuesAsStrings().get(0);
}
break;
case DERIVED:
DerSchema schema = derSchemaDAO.find(recipientAttrName);
if (schema == null) {
LOG.warn("Ignoring non existing {} {}", DerSchema.class.getSimpleName(), recipientAttrName);
} else {
email = membership == null ? derAttrHander.getValue(user, schema) : derAttrHander.getValue(user, membership, schema);
}
break;
case VIRTUAL:
VirSchema virSchema = virSchemaDAO.find(recipientAttrName);
if (virSchema == null) {
LOG.warn("Ignoring non existing {} {}", VirSchema.class.getSimpleName(), recipientAttrName);
} else {
List<String> virAttrValues = membership == null ? virAttrHander.getValues(user, virSchema) : virAttrHander.getValues(user, membership, virSchema);
email = virAttrValues.isEmpty() ? null : virAttrValues.get(0);
}
break;
default:
}
}
return email;
}
use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.
the class GoogleAppsPropagationActions method after.
@Transactional
@Override
public void after(final PropagationTask task, final TaskExec execution, final ConnectorObject afterObj) {
if (task.getOperation() == ResourceOperation.DELETE || task.getOperation() == ResourceOperation.NONE) {
return;
}
if (AnyTypeKind.USER != task.getAnyTypeKind()) {
return;
}
User user = userDAO.find(task.getEntityKey());
if (user == null) {
LOG.error("Could not find user {}, skipping", task.getEntityKey());
} else {
boolean modified = false;
AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
PlainSchema googleAppsId = plainSchemaDAO.find(getGoogleAppsIdSchema());
if (googleAppsId == null) {
LOG.error("Could not find schema {}, skipping", getGoogleAppsIdSchema());
} else {
// set back the __UID__ received by Google
UPlainAttr attr = user.getPlainAttr(getGoogleAppsIdSchema()).orElse(null);
if (attr == null) {
attr = entityFactory.newEntity(UPlainAttr.class);
attr.setSchema(googleAppsId);
attr.setOwner(user);
user.add(attr);
try {
attr.add(afterObj.getUid().getUidValue(), anyUtils);
modified = true;
} catch (InvalidPlainAttrValueException e) {
LOG.error("Invalid value for attribute {}: {}", googleAppsId.getKey(), afterObj.getUid().getUidValue(), e);
}
} else {
LOG.debug("User {} has already {} assigned: {}", user, googleAppsId.getKey(), attr.getValuesAsStrings());
}
}
if (modified) {
userDAO.save(user);
}
}
}
use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.
the class PlainAttrTest method findByKey.
@Test
public void findByKey() {
UPlainAttr attribute = plainAttrDAO.find("01f22fbd-b672-40af-b528-686d9b27ebc4", UPlainAttr.class);
assertNotNull(attribute);
attribute = plainAttrDAO.find("9d0d9e40-1b18-488e-9482-37dab82163c9", UPlainAttr.class);
assertNotNull(attribute);
}
use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.
the class PlainAttrTest method validateAndSave.
@Test
public void validateAndSave() {
User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
PlainSchema emailSchema = plainSchemaDAO.find("email");
assertNotNull(emailSchema);
PlainSchema fullnameSchema = plainSchemaDAO.find("fullname");
assertNotNull(fullnameSchema);
UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
attr.setOwner(user);
attr.setSchema(emailSchema);
UPlainAttrUniqueValue uauv = entityFactory.newEntity(UPlainAttrUniqueValue.class);
uauv.setAttr(attr);
uauv.setSchema(fullnameSchema);
uauv.setStringValue("a value");
attr.setUniqueValue(uauv);
user.add(attr);
InvalidEntityException iee = null;
try {
userDAO.save(user);
fail("This should not happen");
} catch (InvalidEntityException e) {
iee = e;
}
assertNotNull(iee);
// for attribute
assertTrue(iee.hasViolation(EntityViolationType.InvalidValueList));
// for uauv
assertTrue(iee.hasViolation(EntityViolationType.InvalidPlainAttr));
}
Aggregations