use of org.alfresco.util.PropertyMap in project alfresco-repository by Alfresco.
the class LDAPUserRegistry method mapToNode.
private NodeDescription mapToNode(Map<String, String> attributeMapping, Map<String, String> attributeDefaults, SearchResult result) throws NamingException {
NodeDescription nodeDescription = new NodeDescription(result.getNameInNamespace());
Attributes ldapAttributes = result.getAttributes();
// Parse the timestamp
Attribute modifyTimestamp = ldapAttributes.get(this.modifyTimestampAttributeName);
if (modifyTimestamp != null) {
try {
nodeDescription.setLastModified(this.timestampFormat.parse(modifyTimestamp.get().toString()));
} catch (ParseException e) {
throw new AlfrescoRuntimeException("Failed to parse timestamp.", e);
}
}
// Apply the mapped attributes
PropertyMap properties = nodeDescription.getProperties();
for (String key : attributeMapping.keySet()) {
QName keyQName = QName.createQName(key, this.namespaceService);
// cater for null
String attributeName = attributeMapping.get(key);
if (attributeName != null) {
Attribute attribute = ldapAttributes.get(attributeName);
String defaultAttribute = attributeDefaults.get(key);
if (attribute != null) {
String value = (String) attribute.get(0);
if (value != null) {
properties.put(keyQName, value);
}
} else if (defaultAttribute != null) {
properties.put(keyQName, defaultAttribute);
} else {
// Make sure that a 2nd sync, updates deleted ldap attributes(MNT-14026)
properties.put(keyQName, null);
}
} else {
String defaultValue = attributeDefaults.get(key);
if (defaultValue != null) {
properties.put(keyQName, defaultValue);
}
}
}
return nodeDescription;
}
use of org.alfresco.util.PropertyMap in project alfresco-repository by Alfresco.
the class PersonServiceLoader method main.
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
sb.append("\n").append("Usage\n").append(" PersonServiceLoader --user=<username> --pwd=<password> --batch-count=<batch-count> --batch-size=<batch-size> --threads=<threads>\n");
String usage = sb.toString();
ArgumentHelper argHelper = new ArgumentHelper(usage, args);
try {
String user = argHelper.getStringValue("user", true, true);
String pwd = argHelper.getStringValue("pwd", true, true);
int batchCount = argHelper.getIntegerValue("batch-count", true, 1, Integer.MAX_VALUE);
int batchSize = argHelper.getIntegerValue("batch-size", true, 1, Integer.MAX_VALUE);
int threads = argHelper.getIntegerValue("threads", true, 1, Integer.MAX_VALUE);
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
// Create the worker instance
PersonServiceLoader loader = new PersonServiceLoader(ctx, batchSize, batchCount);
loader.run(user, pwd, threads);
// check the lazy creation
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
final AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
final PersonService personService = serviceRegistry.getPersonService();
final TransactionService transactionService = serviceRegistry.getTransactionService();
final NodeService nodeService = serviceRegistry.getNodeService();
String firstName = "" + System.currentTimeMillis();
String lastName = String.format("%05d", -1);
final String username = GUID.generate();
String emailAddress = String.format("%s.%s@xyz.com", firstName, lastName);
PropertyMap properties = new PropertyMap(7);
properties.put(ContentModel.PROP_USERNAME, username);
properties.put(ContentModel.PROP_FIRSTNAME, firstName);
properties.put(ContentModel.PROP_LASTNAME, lastName);
properties.put(ContentModel.PROP_EMAIL, emailAddress);
NodeRef madePerson = personService.createPerson(properties);
NodeRef homeFolder = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, nodeService.getProperty(madePerson, ContentModel.PROP_HOMEFOLDER));
if (homeFolder != null) {
throw new IllegalStateException("Home folder created eagerly");
}
RetryingTransactionHelper helper = transactionService.getRetryingTransactionHelper();
helper.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
NodeRef person = personService.getPerson(username);
NodeRef homeFolder = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER));
if (homeFolder == null) {
throw new IllegalStateException("Home folder not created lazily");
}
return null;
}
}, true, true);
NodeRef autoPerson = personService.getPerson(GUID.generate());
NodeRef autoHomeFolder = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, nodeService.getProperty(autoPerson, ContentModel.PROP_HOMEFOLDER));
if (autoHomeFolder == null) {
throw new IllegalStateException("Home folder not created lazily for auto created users");
}
// All done
ApplicationContextHelper.closeApplicationContext();
System.exit(0);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
argHelper.printUsage();
System.exit(1);
} catch (Throwable e) {
logger.error("PersonServiceLoader (userCount, batchSize) failed.", e);
System.exit(1);
}
}
use of org.alfresco.util.PropertyMap in project alfresco-repository by Alfresco.
the class ScriptNodeTest method testVersioningPropsDefaultChanged.
/**
* MNT-9369
* <p>
* Initially the ContentModel.PROP_AUTO_VERSION and ContentModel.PROP_AUTO_VERSION_PROPS are true by defaults. We'll set them to false.
*/
@Test
public void testVersioningPropsDefaultChanged() {
setUpBootstrap();
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
try {
// Authenticate as the system user
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
log.debug("Adding new model.");
// Create a model node
PropertyMap properties = new PropertyMap(1);
properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
final NodeRef modelNode = NODE_SERVICE.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.ALFRESCO_URI, "dictionaryModels"), ContentModel.TYPE_DICTIONARY_MODEL, properties).getChildRef();
assertNotNull(modelNode);
// Add the model content to the model node
ContentWriter contentWriter = CONTENT_SERVICE.getWriter(modelNode, ContentModel.PROP_CONTENT, true);
contentWriter.setEncoding("UTF-8");
contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML);
InputStream cmStream = getClass().getClassLoader().getResourceAsStream(TEST_CONTENT_MODEL);
contentWriter.putContent(IOUtils.toString(cmStream));
cmStream.close();
} finally {
AuthenticationUtil.popAuthentication();
}
return null;
}
});
Map<QName, PropertyDefinition> versionableProps = DICTIONARY_SERVICE.getAspect(ContentModel.ASPECT_VERSIONABLE).getProperties();
autoVersion = Boolean.parseBoolean(versionableProps.get(ContentModel.PROP_AUTO_VERSION).getDefaultValue());
autoVersionProps = Boolean.parseBoolean(versionableProps.get(ContentModel.PROP_AUTO_VERSION_PROPS).getDefaultValue());
createTestContent(false);
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
log.debug("Adding versionable aspect.");
ScriptNode sn = new ScriptNode(testNode, SERVICE_REGISTRY);
sn.addAspect("cm:versionable");
return null;
}
});
assertEquals("Incorrect Auto Version property.", autoVersion, NODE_SERVICE.getProperty(testNode, ContentModel.PROP_AUTO_VERSION));
assertEquals("Incorrect Auto Version Props property.", autoVersionProps, NODE_SERVICE.getProperty(testNode, ContentModel.PROP_AUTO_VERSION_PROPS));
revertBootstrap();
}
use of org.alfresco.util.PropertyMap in project alfresco-repository by Alfresco.
the class PeopleTest method createUsers.
private void createUsers() throws HeuristicRollbackException, RollbackException, HeuristicMixedException, SystemException, NotSupportedException {
txn = transactionService.getUserTransaction();
txn.begin();
for (UserInfo user : userInfos) {
String username = user.getUserName();
NodeRef nodeRef = personService.getPersonOrNull(username);
boolean create = nodeRef == null;
if (create) {
PropertyMap testUser = new PropertyMap();
testUser.put(ContentModel.PROP_USERNAME, username);
testUser.put(ContentModel.PROP_FIRSTNAME, user.getFirstName());
testUser.put(ContentModel.PROP_LASTNAME, user.getLastName());
testUser.put(ContentModel.PROP_EMAIL, user.getUserName() + "@acme.test");
testUser.put(ContentModel.PROP_PASSWORD, "password");
nodeRef = personService.createPerson(testUser);
}
userNodeRefs.add(nodeRef);
// System.out.println((create ? "create" : "existing")+" user " + username + " nodeRef=" + nodeRef);
}
txn.commit();
}
use of org.alfresco.util.PropertyMap in project alfresco-remote-api by Alfresco.
the class RemoteAlfrescoTicketServiceTest method createUser.
private void createUser(String userName) {
// if user with given user name doesn't already exist then create user
if (this.authenticationService.authenticationExists(userName) == false) {
// create user
this.authenticationService.createAuthentication(userName, PASSWORD.toCharArray());
// create person properties
PropertyMap personProps = new PropertyMap();
personProps.put(ContentModel.PROP_USERNAME, userName);
personProps.put(ContentModel.PROP_FIRSTNAME, "First");
personProps.put(ContentModel.PROP_LASTNAME, "Last");
personProps.put(ContentModel.PROP_EMAIL, "FirstName123.LastName123@email.com");
personProps.put(ContentModel.PROP_JOBTITLE, "JobTitle123");
personProps.put(ContentModel.PROP_JOBTITLE, "Organisation123");
// create person node for user
this.personService.createPerson(personProps);
}
}
Aggregations