if (storedName != null && !name.equals(storedName)) {
throw new EmailAlreadyAssignedException(email, storedName);
}
}
BNode user = new BNode();
LockableMGraph systemGraph = getSystemGraph();
Lock writeLock = systemGraph.getLock().writeLock();
writeLock.lock();
try {
systemGraph.add(new TripleImpl(user, RDF.type, FOAF.Agent));
systemGraph.add(new TripleImpl(user, PLATFORM.userName,
new PlainLiteralImpl(name)));
if (email != null) {
systemGraph.add(new TripleImpl(user, FOAF.mbox,
new UriRef("mailto:" + email)));
}
if (password != null) {
try {
String pswSha1 = bytes2HexString(MessageDigest.getInstance("SHA1").digest(password.getBytes("UTF-8")));
systemGraph.add(new TripleImpl(user, PERMISSION.passwordSha1, new PlainLiteralImpl(pswSha1)));
} catch (UnsupportedEncodingException ex) {
throw new RuntimeException(ex);
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
}
if (pathPrefix != null && pathPrefix.trim().length() != 0) {
systemGraph.add(new TripleImpl(user, OSGI.agent_path_prefix,
new PlainLiteralImpl(pathPrefix)));
}
if (!assignedRoles.isEmpty()) {
addRolesToUser(assignedRoles, user);
}