use of org.alfresco.service.cmr.preference.PreferenceService in project alfresco-remote-api by Alfresco.
the class NodesImpl method isFavorite.
/**
* @param node
*/
private boolean isFavorite(NodeRef node) {
PreferenceService preferenceService = (PreferenceService) sr.getService(ServiceRegistry.PREFERENCE_SERVICE);
String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser();
Map<String, Serializable> preferences = preferenceService.getPreferences(currentUserName);
for (Serializable nodesFavorites : preferences.values()) {
if (nodesFavorites instanceof String) {
StringTokenizer st = new StringTokenizer((String) nodesFavorites, ",");
while (st.hasMoreTokens()) {
String nodeRefStr = st.nextToken();
nodeRefStr = nodeRefStr.trim();
if (!NodeRef.isNodeRef((String) nodeRefStr)) {
continue;
}
NodeRef nodeRef = new NodeRef((String) nodeRefStr);
if (nodeRef.equals(node)) {
return true;
}
}
}
}
return false;
}
use of org.alfresco.service.cmr.preference.PreferenceService in project alfresco-remote-api by Alfresco.
the class TestPeople method testGetPerson_withCustomProps.
@Test
public void testGetPerson_withCustomProps() throws PublicApiException {
// Create the person directly using the Java services - we don't want to test
// the REST API's "create person" function here, so we're isolating this test from it.
MutableAuthenticationService authService = applicationContext.getBean("AuthenticationService", MutableAuthenticationService.class);
PreferenceService prefService = applicationContext.getBean("PreferenceService", PreferenceService.class);
Map<QName, Serializable> nodeProps = new HashMap<>();
// The papi:lunchable aspect should be auto-added for the papi:lunch property
nodeProps.put(PROP_LUNCH, "Falafel wrap");
nodeProps.put(PROP_LUNCH_COMMENTS, "");
// These properties should not be present when a person is retrieved
// since they are present as top-level fields.
String userName = "docbrown@" + account1.getId();
nodeProps.put(ContentModel.PROP_USERNAME, userName);
nodeProps.put(ContentModel.PROP_FIRSTNAME, "Doc");
nodeProps.put(ContentModel.PROP_LASTNAME, "Brown");
nodeProps.put(ContentModel.PROP_JOBTITLE, "Inventor");
nodeProps.put(ContentModel.PROP_LOCATION, "Location");
nodeProps.put(ContentModel.PROP_TELEPHONE, "123345");
nodeProps.put(ContentModel.PROP_MOBILE, "456456");
nodeProps.put(ContentModel.PROP_EMAIL, "doc.brown@example.com");
nodeProps.put(ContentModel.PROP_ORGANIZATION, "Acme");
nodeProps.put(ContentModel.PROP_COMPANYADDRESS1, "123 Acme Crescent");
nodeProps.put(ContentModel.PROP_COMPANYADDRESS2, "Cholsey");
nodeProps.put(ContentModel.PROP_COMPANYADDRESS3, "Oxfordshire");
nodeProps.put(ContentModel.PROP_COMPANYPOSTCODE, "OX10 1AB");
nodeProps.put(ContentModel.PROP_COMPANYTELEPHONE, "098876234");
nodeProps.put(ContentModel.PROP_COMPANYFAX, "098234876");
nodeProps.put(ContentModel.PROP_COMPANYEMAIL, "info@example.com");
nodeProps.put(ContentModel.PROP_SKYPE, "doc.brown");
nodeProps.put(ContentModel.PROP_INSTANTMSG, "doc.brown.instmsg");
nodeProps.put(ContentModel.PROP_USER_STATUS, "status");
nodeProps.put(ContentModel.PROP_USER_STATUS_TIME, new Date());
nodeProps.put(ContentModel.PROP_GOOGLEUSERNAME, "doc.brown.google");
nodeProps.put(ContentModel.PROP_SIZE_QUOTA, 12345000);
nodeProps.put(ContentModel.PROP_SIZE_CURRENT, 1230);
nodeProps.put(ContentModel.PROP_EMAIL_FEED_DISABLED, false);
// TODO: PROP_PERSON_DESCRIPTION?
// Namespaces that should be filtered
nodeProps.put(ContentModel.PROP_ENABLED, true);
nodeProps.put(ContentModel.PROP_SYS_NAME, "name-value");
// Create a password and enable the user so that we can check the usr:* props aren't present later.
AuthenticationUtil.setFullyAuthenticatedUser("admin@" + account1.getId());
authService.createAuthentication(userName, "password".toCharArray());
authService.setAuthenticationEnabled(userName, true);
personService.createPerson(nodeProps);
// Set a preference, so that we can test that we're filtering this property correctly.
prefService.setPreferences(userName, Collections.singletonMap("olives", "green"));
// Get the person using the REST API
publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
Person person = people.getPerson(userName);
// Did we get the correct aspects/properties?
assertEquals(userName, person.getId());
assertEquals("Doc", person.getFirstName());
assertEquals("Falafel wrap", person.getProperties().get("papi:lunch"));
assertTrue(person.getAspectNames().contains("papi:lunchable"));
// Empty (zero length) string values are considered to be
// null values, and will be represented the same as null
// values (i.e. by non-existence of the property).
assertNull(person.getProperties().get("papi:lunchcomments"));
// Check that no properties are present that should have been filtered by namespace.
for (String key : person.getProperties().keySet()) {
if (key.startsWith("cm:") || key.startsWith("sys:") || key.startsWith("usr:")) {
Object value = person.getProperties().get(key);
String keyValueStr = String.format("(key=%s, value=%s)", key, value);
fail("Property " + keyValueStr + " found with namespace that should have been excluded.");
}
}
}
Aggregations