use of org.apache.syncope.core.persistence.api.entity.resource.MappingItem in project syncope by apache.
the class AbstractPropagationTaskExecutor method getRemoteObject.
/**
* Get remote object for given task.
*
* @param connector connector facade proxy.
* @param task current propagation task.
* @param provision provision
* @param latest 'FALSE' to retrieve object using old connObjectKey if not null.
* @return remote connector object.
*/
protected ConnectorObject getRemoteObject(final PropagationTask task, final Connector connector, final Provision provision, final boolean latest) {
String connObjectKey = latest || task.getOldConnObjectKey() == null ? task.getConnObjectKey() : task.getOldConnObjectKey();
Set<MappingItem> linkingMappingItems = virSchemaDAO.findByProvision(provision).stream().map(schema -> schema.asLinkingMappingItem()).collect(Collectors.toSet());
ConnectorObject obj = null;
Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
if (connObjectKeyItem.isPresent()) {
try {
obj = connector.getObject(new ObjectClass(task.getObjectClassName()), AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKey), MappingUtils.buildOperationOptions(new IteratorChain<>(MappingUtils.getPropagationItems(provision.getMapping().getItems()).iterator(), linkingMappingItems.iterator())));
for (MappingItem item : linkingMappingItems) {
Attribute attr = obj.getAttributeByName(item.getExtAttrName());
if (attr == null) {
virAttrCache.expire(task.getAnyType(), task.getEntityKey(), item.getIntAttrName());
} else {
VirAttrCacheValue cacheValue = new VirAttrCacheValue();
cacheValue.setValues(attr.getValue());
virAttrCache.put(task.getAnyType(), task.getEntityKey(), item.getIntAttrName(), cacheValue);
}
}
} catch (TimeoutException toe) {
LOG.debug("Request timeout", toe);
throw toe;
} catch (RuntimeException ignore) {
LOG.debug("While resolving {}", connObjectKey, ignore);
}
}
return obj;
}
use of org.apache.syncope.core.persistence.api.entity.resource.MappingItem in project syncope by apache.
the class PlainSchemaTest method deleteSurname.
@Test
public void deleteSurname() {
// search for user schema fullname
PlainSchema schema = plainSchemaDAO.find("surname");
assertNotNull(schema);
// check for associated mappings
Set<MappingItem> mappings = new HashSet<>();
for (ExternalResource resource : resourceDAO.findAll()) {
if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
if (schema.getKey().equals(mapItem.getIntAttrName())) {
mappings.add(mapItem);
}
}
}
}
assertFalse(mappings.isEmpty());
// delete user schema fullname
plainSchemaDAO.delete("surname");
plainSchemaDAO.flush();
// check for schema deletion
schema = plainSchemaDAO.find("surname");
assertNull(schema);
}
use of org.apache.syncope.core.persistence.api.entity.resource.MappingItem in project syncope by apache.
the class PlainSchemaTest method deleteFullname.
@Test
public void deleteFullname() {
// fullname is mapped as ConnObjectKey for ws-target-resource-2, need to swap it otherwise validation errors
// will be raised
resourceDAO.find("ws-target-resource-2").getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().forEach(item -> {
if ("fullname".equals(item.getIntAttrName())) {
item.setConnObjectKey(false);
} else if ("surname".equals(item.getIntAttrName())) {
item.setConnObjectKey(true);
}
});
// search for user schema fullname
PlainSchema schema = plainSchemaDAO.find("fullname");
assertNotNull(schema);
// check for associated mappings
Set<MappingItem> mapItems = new HashSet<>();
for (ExternalResource resource : resourceDAO.findAll()) {
if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
if (schema.getKey().equals(mapItem.getIntAttrName())) {
mapItems.add(mapItem);
}
}
}
}
assertFalse(mapItems.isEmpty());
// delete user schema fullname
plainSchemaDAO.delete("fullname");
plainSchemaDAO.flush();
// check for schema deletion
schema = plainSchemaDAO.find("fullname");
assertNull(schema);
plainSchemaDAO.clear();
// check for mappings deletion
mapItems = new HashSet<>();
for (ExternalResource resource : resourceDAO.findAll()) {
if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
if ("fullname".equals(mapItem.getIntAttrName())) {
mapItems.add(mapItem);
}
}
}
}
assertTrue(mapItems.isEmpty());
assertNull(plainAttrDAO.find("01f22fbd-b672-40af-b528-686d9b27ebc4", UPlainAttr.class));
assertNull(plainAttrDAO.find(UUID.randomUUID().toString(), UPlainAttr.class));
assertFalse(userDAO.findByUsername("rossini").getPlainAttr("fullname").isPresent());
assertFalse(userDAO.findByUsername("vivaldi").getPlainAttr("fullname").isPresent());
}
use of org.apache.syncope.core.persistence.api.entity.resource.MappingItem in project syncope by apache.
the class ResourceTest method issue243.
@Test
public void issue243() {
ExternalResource csv = resourceDAO.find("resource-csv");
assertNotNull(csv);
int origMapItems = csv.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().size();
MappingItem newMapItem = entityFactory.newEntity(MappingItem.class);
newMapItem.setIntAttrName("TEST");
newMapItem.setExtAttrName("TEST");
newMapItem.setPurpose(MappingPurpose.PROPAGATION);
csv.getProvision(anyTypeDAO.findUser()).get().getMapping().add(newMapItem);
resourceDAO.save(csv);
resourceDAO.flush();
csv = resourceDAO.find("resource-csv");
assertNotNull(csv);
assertEquals(origMapItems + 1, csv.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().size());
}
use of org.apache.syncope.core.persistence.api.entity.resource.MappingItem in project syncope by apache.
the class ResourceTest method save.
@Test
public void save() {
ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
resource.setKey("ws-target-resource-save");
// specify the connector
ConnInstance connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
assertNotNull(connector);
resource.setConnector(connector);
Provision provision = entityFactory.newEntity(Provision.class);
provision.setAnyType(anyTypeDAO.findUser());
provision.setObjectClass(ObjectClass.ACCOUNT);
provision.setResource(resource);
resource.add(provision);
Mapping mapping = entityFactory.newEntity(Mapping.class);
mapping.setProvision(provision);
provision.setMapping(mapping);
// specify mappings
for (int i = 0; i < 3; i++) {
MappingItem item = entityFactory.newEntity(MappingItem.class);
item.setExtAttrName("test" + i);
item.setIntAttrName("nonexistent" + i);
item.setMandatoryCondition("false");
item.setPurpose(MappingPurpose.PULL);
mapping.add(item);
item.setMapping(mapping);
}
MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
connObjectKey.setExtAttrName("username");
connObjectKey.setIntAttrName("username");
connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
mapping.setConnObjectKeyItem(connObjectKey);
connObjectKey.setMapping(mapping);
// map a derived attribute
MappingItem derived = entityFactory.newEntity(MappingItem.class);
derived.setConnObjectKey(false);
derived.setExtAttrName("fullname");
derived.setIntAttrName("cn");
derived.setPurpose(MappingPurpose.PROPAGATION);
mapping.add(derived);
derived.setMapping(mapping);
// save the resource
ExternalResource actual = resourceDAO.save(resource);
assertNotNull(actual);
assertNotNull(actual.getProvision(anyTypeDAO.findUser()).get().getMapping());
resourceDAO.flush();
resourceDAO.detach(actual);
connInstanceDAO.detach(connector);
// assign the new resource to an user
User user = userDAO.findByUsername("rossini");
assertNotNull(user);
user.add(actual);
resourceDAO.flush();
// retrieve resource
resource = resourceDAO.find(actual.getKey());
assertNotNull(resource);
resourceDAO.refresh(resource);
// check connector
connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
assertNotNull(connector);
assertNotNull(connector.getResources());
assertNotNull(resource.getConnector());
assertTrue(resource.getConnector().equals(connector));
// check mappings
List<? extends MappingItem> items = resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems();
assertNotNull(items);
assertEquals(5, items.size());
// check user
user = userDAO.findByUsername("rossini");
assertNotNull(user);
assertNotNull(user.getResources());
assertTrue(user.getResources().contains(actual));
}
Aggregations