if (null==getPassword()) throw new NullPointerException("User.create() password cannot be null");
if (null==getEmail()) throw new NullPointerException("User.create() email cannot be null");
if (getEmail().length()==0) throw new NullPointerException("User.create() email cannot be empty");
AuthorizationManager oAum = oSes.getAuthorizationManager();
AuthorizationAdminManager oAam = oSes.getAuthorizationAdminManager();
AdministeredGroup oGrp = oAam.getGroup("Zesped Users");
if (null==sNickName) sNickName = Gadgets.generateUUID();
Log.out.debug("AuthorizationAdminManager.createUser("+sNickName+","+getPassword()+","+getFirstName()+","+getLastName()+","+oGrp.getName()+")");
setAdministeredUser(oAam.createUser(sNickName, getPassword(), getFirstName(), getLastName(), oGrp));
String sUsrs = Users.top(oSes).getDocument().id();
DocumentIndexer oIdx = oSes.getDocumentIndexer();
SortableList<Document> oLst = (SortableList<Document>) oSes.getDms().query("User$email='"+getEmail()+"'");
if (!oLst.isEmpty()) {
Log.out.error("E-mail address "+getEmail()+" already belongs to another user");
throw new IllegalArgumentException("E-mail address "+getEmail()+" already belongs to another user");
}
Dms oDms = oSes.getDms();
Document oDoc = oDms.newDocument(oDms.getDocumentType("User"), oDms.getDocument(sUsrs));
oDoc.save("");
setDocument(oDoc);
AttributeMultiValue oUid = oDoc.attribute("user_id");
oUid.set(oDoc.id());
AttributeMultiValue oUuid = oDoc.attribute("user_uuid");
oUuid.set(sNickName);
AttributeMultiValue oAttr = oDoc.attribute("email");
oAttr.set(getEmail());
AttributeMultiValue oActv = oDoc.attribute("active");
oActv.set(getStringNull("active","1"));
AttributeMultiValue oSrvs = oDoc.attribute("allowed_services");
oSrvs.set(String.valueOf(CaptureService.INVOICES.toInt())+","+String.valueOf(CaptureService.BILLNOTES.toInt()));
AttributeMultiValue oPassw = oDoc.attribute("password");
oPassw.set(ACL.encript(getPassword(), ACL.PWD_DTIP_RC4_64));
AttributeMultiValue oApr = oDoc.attribute("can_approve");
oApr.set("1");
AttributeMultiValue oStl = oDoc.attribute("can_settle");
oStl.set("1");
AttributeMultiValue oPre = oDoc.attribute("can_premium");
oPre.set("1");
oDoc.save("");
oIdx.indexDocument(oDoc);
put("user_id", oDoc.id());
put("user_uuid", sNickName);
put("can_approve", "1");
put("can_settle", "1");
put("can_premium", "1");
put("active", getStringNull("active","1"));
put("allowed_services", String.valueOf(CaptureService.INVOICES.toInt())+","+String.valueOf(CaptureService.BILLNOTES.toInt()));
es.ipsa.atril.sec.user.User oUsr = oAum.getUser(getNickName());
oAum.setDocumentRights(oUsr, oDoc, RightsFactory.getDocumentRightsAllGrant());
try {
oAum.setDocumentRights(oUsr, Deposits.top(oSes).getDocument(), RightsFactory.getDocumentRightsAllGrant());
} catch (ElementNotFoundException ignore) { }
DAO.log(oSes, oDoc, User.class, "CREATE USER", AtrilEvent.Level.INFO, String.valueOf(getAdministeredUser().getId())+";"+getEmail());
Log.out.debug("End com.zesped.model.User.create() : "+oDoc.id());