@Test public void testShareWithGroupExcludeAccount() throws Exception { LivePost livePost = createLivePost("Hello sharing!", pimoService.getUser()); PrivacyPreference preference = modelFactory.getPPOFactory().createPrivacyPreference(); preference.setLabel(PrivacyPreferenceType.LIVEPOST.name()); preference.setCreator(pimoService.getUser()); preference.setAppliesToResource(livePost); PersonGroup group = createPersonGroup("Friends", personR1, personR2); AccessSpace accessSpace = modelFactory.getNSOFactory().createAccessSpace(); accessSpace.setSharedThrough(accountSender); accessSpace.addIncludes(group); accessSpace.addExcludes(accountR2); preference.addAccessSpace(accessSpace); preference.getModel().addAll(accessSpace.getModel().iterator()); tripleStore.addAll(pimoService.getPimoUri(), preference.getModel().iterator()); Event event = new Event(connection.getName(), Event.ACTION_RESOURCE_ADD, preference); notifier.onReceive(event); assertEquals(1, notifierManager.external.size()); DimeExternalNotification notification = notifierManager.external.get(0); assertEquals(accountSender.toString(), notification.getSender()); assertEquals(accountR1.toString(), notification.getTarget()); assertEquals(livePost.toString(), notification.getItemID()); assertEquals(DimeExternalNotification.OP_SHARE, notification.getOperation()); assertEquals(Type.get(livePost).toString(), notification.getItemType()); }
@Override public void onReceive(Event event) { if (notifierManager == null) { logger.warn("NotifierManager bean not set for SharingNotifier: " + "notifications for sharing actions won't be sent!"); return; } Tenant tenant = TenantHelper.getTenant(event.getTenantId()); Connection connection = null; ResourceStore resourceStore = null; PimoService pimoService = null; PrivacyPreferenceService ppoService = null; try { org.ontoware.rdfreactor.schema.rdfs.Resource resource = event.getData(); if (resource == null) { return; } String[] allowedActions = new String[] { Event.ACTION_RESOURCE_ADD, Event.ACTION_RESOURCE_MODIFY, Event.ACTION_RESOURCE_DELETE }; if (!Arrays.contains(allowedActions, event.getAction())) { return; } URI[] allowedTypes = new URI[] { PPO.PrivacyPreference, DLPO.LivePost, NIE.DataObject, PIMO.PersonGroup }; boolean typeAllowed = false; for (URI allowedType : allowedTypes) { if (event.is(allowedType)) { typeAllowed = true; break; } } if (!typeAllowed) { return; } connection = connectionProvider.getConnection(event.getTenant()); resourceStore = connection.getResourceStore(); pimoService = connection.getPimoService(); ppoService = connection.getPrivacyPreferenceService(); if (event.is(PPO.PrivacyPreference) && (Event.ACTION_RESOURCE_ADD.equals(event.getAction()) || Event.ACTION_RESOURCE_MODIFY.equals(event.getAction()))) { PrivacyPreference preference = ppoService.get(resource.asURI()); org.ontoware.rdfreactor.schema.rdfs.Resource sharedItem = null; try { sharedItem = getSharedItem(preference, ppoService, pimoService); } catch (NotFoundException e) { logger.error("Privacy preference " + preference + " could not be shared.", e); return; } sendNotifications(connection, preference, sharedItem, true, tenant); } else if (event.is(PPO.PrivacyPreference) && Event.ACTION_RESOURCE_DELETE.equals(event.getAction())) { } else if (event.is(DLPO.LivePost) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { try { LivePost livePost = resourceStore.get(resource.asURI(), LivePost.class); PrivacyPreference preference = ppoService.getForLivePost(livePost); if (preference != null) { sendNotifications(connection, preference, livePost, true, tenant); } } catch (NotFoundException e) { logger.error("A 'resource modified' event was received for " + resource.asURI() + " (livepost), but it could not be found in the RDF store", e); } } else if (event.is(NIE.DataObject) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { try { DataObject dataObject = resourceStore.get(resource.asURI(), DataObject.class); PrivacyPreference preference = ppoService.getForDataObject(dataObject); if (preference != null) { sendNotifications(connection, preference, dataObject, true, tenant); } } catch (NotFoundException e) { logger.error("A 'resource modified' event was received for " + resource.asURI() + " (livepost), but it could not be found in the RDF store", e); } } else if (event.is(PIMO.PersonGroup) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { Collection<Resource> ppUris = resourceStore.find(PrivacyPreference.class) .distinct() .where(PPO.hasAccessSpace).is(Query.X) .where(Query.X, NSO.includes).is(resource.asURI()) .ids(); for (Resource ppUri : ppUris) { PrivacyPreference preference = ppoService.get(ppUri.asURI()); org.ontoware.rdfreactor.schema.rdfs.Resource sharedItem = null; try { sharedItem = getSharedItem(preference, ppoService, pimoService); } catch (NotFoundException e) { logger.error("Privacy preference " + preference + " could not be shared.", e); return; } sendNotifications(connection, preference, sharedItem, false, tenant); } } } catch (RepositoryException e) { logger.error("Cannot connect with the RDF repository '" + Long.parseLong(event.getTenant()) + "': " + e, e); return; } }
SharingNotifier implements BroadcastReceiver { @Override public void onReceive(Event event) { if (notifierManager == null) { logger.warn("NotifierManager bean not set for SharingNotifier: " + "notifications for sharing actions won't be sent!"); return; } Tenant tenant = TenantHelper.getTenant(event.getTenantId()); Connection connection = null; ResourceStore resourceStore = null; PimoService pimoService = null; PrivacyPreferenceService ppoService = null; try { org.ontoware.rdfreactor.schema.rdfs.Resource resource = event.getData(); if (resource == null) { return; } String[] allowedActions = new String[] { Event.ACTION_RESOURCE_ADD, Event.ACTION_RESOURCE_MODIFY, Event.ACTION_RESOURCE_DELETE }; if (!Arrays.contains(allowedActions, event.getAction())) { return; } URI[] allowedTypes = new URI[] { PPO.PrivacyPreference, DLPO.LivePost, NIE.DataObject, PIMO.PersonGroup }; boolean typeAllowed = false; for (URI allowedType : allowedTypes) { if (event.is(allowedType)) { typeAllowed = true; break; } } if (!typeAllowed) { return; } connection = connectionProvider.getConnection(event.getTenant()); resourceStore = connection.getResourceStore(); pimoService = connection.getPimoService(); ppoService = connection.getPrivacyPreferenceService(); if (event.is(PPO.PrivacyPreference) && (Event.ACTION_RESOURCE_ADD.equals(event.getAction()) || Event.ACTION_RESOURCE_MODIFY.equals(event.getAction()))) { PrivacyPreference preference = ppoService.get(resource.asURI()); org.ontoware.rdfreactor.schema.rdfs.Resource sharedItem = null; try { sharedItem = getSharedItem(preference, ppoService, pimoService); } catch (NotFoundException e) { logger.error("Privacy preference " + preference + " could not be shared.", e); return; } sendNotifications(connection, preference, sharedItem, true, tenant); } else if (event.is(PPO.PrivacyPreference) && Event.ACTION_RESOURCE_DELETE.equals(event.getAction())) { } else if (event.is(DLPO.LivePost) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { try { LivePost livePost = resourceStore.get(resource.asURI(), LivePost.class); PrivacyPreference preference = ppoService.getForLivePost(livePost); if (preference != null) { sendNotifications(connection, preference, livePost, true, tenant); } } catch (NotFoundException e) { logger.error("A 'resource modified' event was received for " + resource.asURI() + " (livepost), but it could not be found in the RDF store", e); } } else if (event.is(NIE.DataObject) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { try { DataObject dataObject = resourceStore.get(resource.asURI(), DataObject.class); PrivacyPreference preference = ppoService.getForDataObject(dataObject); if (preference != null) { sendNotifications(connection, preference, dataObject, true, tenant); } } catch (NotFoundException e) { logger.error("A 'resource modified' event was received for " + resource.asURI() + " (livepost), but it could not be found in the RDF store", e); } } else if (event.is(PIMO.PersonGroup) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { Collection<Resource> ppUris = resourceStore.find(PrivacyPreference.class) .distinct() .where(PPO.hasAccessSpace).is(Query.X) .where(Query.X, NSO.includes).is(resource.asURI()) .ids(); for (Resource ppUri : ppUris) { PrivacyPreference preference = ppoService.get(ppUri.asURI()); org.ontoware.rdfreactor.schema.rdfs.Resource sharedItem = null; try { sharedItem = getSharedItem(preference, ppoService, pimoService); } catch (NotFoundException e) { logger.error("Privacy preference " + preference + " could not be shared.", e); return; } sendNotifications(connection, preference, sharedItem, false, tenant); } } } catch (RepositoryException e) { logger.error("Cannot connect with the RDF repository '" + Long.parseLong(event.getTenant()) + "': " + e, e); return; } } }
SharingNotifier implements BroadcastReceiver { @Override public void onReceive(Event event) { if (notifierManager == null) { logger.warn("NotifierManager bean not set for SharingNotifier: " + "notifications for sharing actions won't be sent!"); return; } Tenant tenant = TenantHelper.getTenant(event.getTenantId()); Connection connection = null; ResourceStore resourceStore = null; PimoService pimoService = null; PrivacyPreferenceService ppoService = null; try { org.ontoware.rdfreactor.schema.rdfs.Resource resource = event.getData(); if (resource == null) { return; } String[] allowedActions = new String[] { Event.ACTION_RESOURCE_ADD, Event.ACTION_RESOURCE_MODIFY, Event.ACTION_RESOURCE_DELETE }; if (!Arrays.contains(allowedActions, event.getAction())) { return; } URI[] allowedTypes = new URI[] { PPO.PrivacyPreference, DLPO.LivePost, NIE.DataObject, PIMO.PersonGroup }; boolean typeAllowed = false; for (URI allowedType : allowedTypes) { if (event.is(allowedType)) { typeAllowed = true; break; } } if (!typeAllowed) { return; } connection = connectionProvider.getConnection(event.getTenant()); resourceStore = connection.getResourceStore(); pimoService = connection.getPimoService(); ppoService = connection.getPrivacyPreferenceService(); if (event.is(PPO.PrivacyPreference) && (Event.ACTION_RESOURCE_ADD.equals(event.getAction()) || Event.ACTION_RESOURCE_MODIFY.equals(event.getAction()))) { PrivacyPreference preference = ppoService.get(resource.asURI()); org.ontoware.rdfreactor.schema.rdfs.Resource sharedItem = null; try { sharedItem = getSharedItem(preference, ppoService, pimoService); } catch (NotFoundException e) { logger.error("Privacy preference " + preference + " could not be shared.", e); return; } sendNotifications(connection, preference, sharedItem, true, tenant); } else if (event.is(PPO.PrivacyPreference) && Event.ACTION_RESOURCE_DELETE.equals(event.getAction())) { } else if (event.is(DLPO.LivePost) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { try { LivePost livePost = resourceStore.get(resource.asURI(), LivePost.class); PrivacyPreference preference = ppoService.getForLivePost(livePost); if (preference != null) { sendNotifications(connection, preference, livePost, true, tenant); } } catch (NotFoundException e) { logger.error("A 'resource modified' event was received for " + resource.asURI() + " (livepost), but it could not be found in the RDF store", e); } } else if (event.is(NIE.DataObject) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { try { DataObject dataObject = resourceStore.get(resource.asURI(), DataObject.class); PrivacyPreference preference = ppoService.getForDataObject(dataObject); if (preference != null) { sendNotifications(connection, preference, dataObject, true, tenant); } } catch (NotFoundException e) { logger.error("A 'resource modified' event was received for " + resource.asURI() + " (livepost), but it could not be found in the RDF store", e); } } else if (event.is(PIMO.PersonGroup) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { Collection<Resource> ppUris = resourceStore.find(PrivacyPreference.class) .distinct() .where(PPO.hasAccessSpace).is(Query.X) .where(Query.X, NSO.includes).is(resource.asURI()) .ids(); for (Resource ppUri : ppUris) { PrivacyPreference preference = ppoService.get(ppUri.asURI()); org.ontoware.rdfreactor.schema.rdfs.Resource sharedItem = null; try { sharedItem = getSharedItem(preference, ppoService, pimoService); } catch (NotFoundException e) { logger.error("Privacy preference " + preference + " could not be shared.", e); return; } sendNotifications(connection, preference, sharedItem, false, tenant); } } } catch (RepositoryException e) { logger.error("Cannot connect with the RDF repository '" + Long.parseLong(event.getTenant()) + "': " + e, e); return; } } SharingNotifier(); }
SharingNotifier implements BroadcastReceiver { @Override public void onReceive(Event event) { if (notifierManager == null) { logger.warn("NotifierManager bean not set for SharingNotifier: " + "notifications for sharing actions won't be sent!"); return; } Tenant tenant = TenantHelper.getTenant(event.getTenantId()); Connection connection = null; ResourceStore resourceStore = null; PimoService pimoService = null; PrivacyPreferenceService ppoService = null; try { org.ontoware.rdfreactor.schema.rdfs.Resource resource = event.getData(); if (resource == null) { return; } String[] allowedActions = new String[] { Event.ACTION_RESOURCE_ADD, Event.ACTION_RESOURCE_MODIFY, Event.ACTION_RESOURCE_DELETE }; if (!Arrays.contains(allowedActions, event.getAction())) { return; } URI[] allowedTypes = new URI[] { PPO.PrivacyPreference, DLPO.LivePost, NIE.DataObject, PIMO.PersonGroup }; boolean typeAllowed = false; for (URI allowedType : allowedTypes) { if (event.is(allowedType)) { typeAllowed = true; break; } } if (!typeAllowed) { return; } connection = connectionProvider.getConnection(event.getTenant()); resourceStore = connection.getResourceStore(); pimoService = connection.getPimoService(); ppoService = connection.getPrivacyPreferenceService(); if (event.is(PPO.PrivacyPreference) && (Event.ACTION_RESOURCE_ADD.equals(event.getAction()) || Event.ACTION_RESOURCE_MODIFY.equals(event.getAction()))) { PrivacyPreference preference = ppoService.get(resource.asURI()); org.ontoware.rdfreactor.schema.rdfs.Resource sharedItem = null; try { sharedItem = getSharedItem(preference, ppoService, pimoService); } catch (NotFoundException e) { logger.error("Privacy preference " + preference + " could not be shared.", e); return; } sendNotifications(connection, preference, sharedItem, true, tenant); } else if (event.is(PPO.PrivacyPreference) && Event.ACTION_RESOURCE_DELETE.equals(event.getAction())) { } else if (event.is(DLPO.LivePost) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { try { LivePost livePost = resourceStore.get(resource.asURI(), LivePost.class); PrivacyPreference preference = ppoService.getForLivePost(livePost); if (preference != null) { sendNotifications(connection, preference, livePost, true, tenant); } } catch (NotFoundException e) { logger.error("A 'resource modified' event was received for " + resource.asURI() + " (livepost), but it could not be found in the RDF store", e); } } else if (event.is(NIE.DataObject) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { try { DataObject dataObject = resourceStore.get(resource.asURI(), DataObject.class); PrivacyPreference preference = ppoService.getForDataObject(dataObject); if (preference != null) { sendNotifications(connection, preference, dataObject, true, tenant); } } catch (NotFoundException e) { logger.error("A 'resource modified' event was received for " + resource.asURI() + " (livepost), but it could not be found in the RDF store", e); } } else if (event.is(PIMO.PersonGroup) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { Collection<Resource> ppUris = resourceStore.find(PrivacyPreference.class) .distinct() .where(PPO.hasAccessSpace).is(Query.X) .where(Query.X, NSO.includes).is(resource.asURI()) .ids(); for (Resource ppUri : ppUris) { PrivacyPreference preference = ppoService.get(ppUri.asURI()); org.ontoware.rdfreactor.schema.rdfs.Resource sharedItem = null; try { sharedItem = getSharedItem(preference, ppoService, pimoService); } catch (NotFoundException e) { logger.error("Privacy preference " + preference + " could not be shared.", e); return; } sendNotifications(connection, preference, sharedItem, false, tenant); } } } catch (RepositoryException e) { logger.error("Cannot connect with the RDF repository '" + Long.parseLong(event.getTenant()) + "': " + e, e); return; } } SharingNotifier(); @Autowired void setLogEventManager(LogEventManager logEventManager); void setNotifierManager(NotifierManager notifierManager); void setConnectionProvider(ConnectionProvider connectionProvider); void setServiceGateway(ServiceGateway serviceGateway); @Override void onReceive(Event event); }
SharingNotifier implements BroadcastReceiver { @Override public void onReceive(Event event) { if (notifierManager == null) { logger.warn("NotifierManager bean not set for SharingNotifier: " + "notifications for sharing actions won't be sent!"); return; } Tenant tenant = TenantHelper.getTenant(event.getTenantId()); Connection connection = null; ResourceStore resourceStore = null; PimoService pimoService = null; PrivacyPreferenceService ppoService = null; try { org.ontoware.rdfreactor.schema.rdfs.Resource resource = event.getData(); if (resource == null) { return; } String[] allowedActions = new String[] { Event.ACTION_RESOURCE_ADD, Event.ACTION_RESOURCE_MODIFY, Event.ACTION_RESOURCE_DELETE }; if (!Arrays.contains(allowedActions, event.getAction())) { return; } URI[] allowedTypes = new URI[] { PPO.PrivacyPreference, DLPO.LivePost, NIE.DataObject, PIMO.PersonGroup }; boolean typeAllowed = false; for (URI allowedType : allowedTypes) { if (event.is(allowedType)) { typeAllowed = true; break; } } if (!typeAllowed) { return; } connection = connectionProvider.getConnection(event.getTenant()); resourceStore = connection.getResourceStore(); pimoService = connection.getPimoService(); ppoService = connection.getPrivacyPreferenceService(); if (event.is(PPO.PrivacyPreference) && (Event.ACTION_RESOURCE_ADD.equals(event.getAction()) || Event.ACTION_RESOURCE_MODIFY.equals(event.getAction()))) { PrivacyPreference preference = ppoService.get(resource.asURI()); org.ontoware.rdfreactor.schema.rdfs.Resource sharedItem = null; try { sharedItem = getSharedItem(preference, ppoService, pimoService); } catch (NotFoundException e) { logger.error("Privacy preference " + preference + " could not be shared.", e); return; } sendNotifications(connection, preference, sharedItem, true, tenant); } else if (event.is(PPO.PrivacyPreference) && Event.ACTION_RESOURCE_DELETE.equals(event.getAction())) { } else if (event.is(DLPO.LivePost) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { try { LivePost livePost = resourceStore.get(resource.asURI(), LivePost.class); PrivacyPreference preference = ppoService.getForLivePost(livePost); if (preference != null) { sendNotifications(connection, preference, livePost, true, tenant); } } catch (NotFoundException e) { logger.error("A 'resource modified' event was received for " + resource.asURI() + " (livepost), but it could not be found in the RDF store", e); } } else if (event.is(NIE.DataObject) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { try { DataObject dataObject = resourceStore.get(resource.asURI(), DataObject.class); PrivacyPreference preference = ppoService.getForDataObject(dataObject); if (preference != null) { sendNotifications(connection, preference, dataObject, true, tenant); } } catch (NotFoundException e) { logger.error("A 'resource modified' event was received for " + resource.asURI() + " (livepost), but it could not be found in the RDF store", e); } } else if (event.is(PIMO.PersonGroup) && Event.ACTION_RESOURCE_MODIFY.equals(event.getAction())) { Collection<Resource> ppUris = resourceStore.find(PrivacyPreference.class) .distinct() .where(PPO.hasAccessSpace).is(Query.X) .where(Query.X, NSO.includes).is(resource.asURI()) .ids(); for (Resource ppUri : ppUris) { PrivacyPreference preference = ppoService.get(ppUri.asURI()); org.ontoware.rdfreactor.schema.rdfs.Resource sharedItem = null; try { sharedItem = getSharedItem(preference, ppoService, pimoService); } catch (NotFoundException e) { logger.error("Privacy preference " + preference + " could not be shared.", e); return; } sendNotifications(connection, preference, sharedItem, false, tenant); } } } catch (RepositoryException e) { logger.error("Cannot connect with the RDF repository '" + Long.parseLong(event.getTenant()) + "': " + e, e); return; } } SharingNotifier(); @Autowired void setLogEventManager(LogEventManager logEventManager); void setNotifierManager(NotifierManager notifierManager); void setConnectionProvider(ConnectionProvider connectionProvider); void setServiceGateway(ServiceGateway serviceGateway); @Override void onReceive(Event event);  }