Add Organization and roleOrganization to the User Info. Also allow to

edit the user's name from the updateSettings
This commit is contained in:
George Kalampokis 2020-10-23 11:48:27 +03:00
parent 8dd728a85d
commit 56d6b12555
3 changed files with 39 additions and 1 deletions

View File

@ -115,6 +115,8 @@ public class UserManager {
apiContext.getOperationsContext().getDatabaseRepository().detachEntity(userInfo);
HashMap<String, Object> result =
new ObjectMapper().readValue(userInfo.getAdditionalinfo(), HashMap.class);
userInfo.setName(settings.entrySet().stream().filter(entry -> entry.getKey().equals("name")).filter(Objects::nonNull).map(entry -> entry.getValue().toString()).findFirst().orElse(userInfo.getName()));
settings.remove("name");
result.putAll(settings);
userInfo.setAdditionalinfo(new JSONObject(result).toString());
apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao()

View File

@ -4,6 +4,7 @@ import eu.eudat.models.DataModel;
import eu.eudat.logic.utilities.helpers.LabelGenerator;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
public class Organisation implements DataModel<eu.eudat.data.entities.Organisation, Organisation>, LabelGenerator {
@ -95,6 +96,18 @@ public class Organisation implements DataModel<eu.eudat.data.entities.Organisati
organisationEntity.setStatus((short) this.status);
return organisationEntity;
}
public static Organisation fromMap(HashMap<String, Object> map) {
Organisation model = new Organisation();
model.id = (String) map.get("id");
model.key = (String) map.get("key");
model.label = (String) map.get("label");
model.name = (String) map.get("name");
model.reference = (String) map.get("reference");
model.status = (int) map.get("status");
model.tag = (String) map.get("tag");
return model;
}
@Override
public String generateLabel() {

View File

@ -6,6 +6,7 @@ import eu.eudat.data.entities.*;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.dmp.Organisation;
import net.minidev.json.parser.JSONParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -32,6 +33,8 @@ public class UserProfile implements DataModel<eu.eudat.data.entities.UserInfo, U
private String timezone;
private Map<String, Object> culture;
private String avatarUrl;
private Organisation organization;
private String roleOrganization;
public UUID getId() {
return id;
@ -128,8 +131,26 @@ public class UserProfile implements DataModel<eu.eudat.data.entities.UserInfo, U
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
@Override
public Organisation getOrganization() {
return organization;
}
public void setOrganization(Organisation organization) {
this.organization = organization;
}
public String getRoleOrganization() {
return roleOrganization;
}
public void setRoleOrganization(String roleOrganization) {
this.roleOrganization = roleOrganization;
}
@Override
public UserProfile fromDataModel(UserInfo entity) {
this.id = entity.getId();
this.email = entity.getEmail();
@ -144,6 +165,8 @@ public class UserProfile implements DataModel<eu.eudat.data.entities.UserInfo, U
this.timezone = (String) additionalInfo.get("timezone");
this.zenodoEmail = (String) additionalInfo.get("zenodoEmail");
this.avatarUrl = (String) additionalInfo.get("avatarUrl");
this.organization = Organisation.fromMap((HashMap<String, Object>) additionalInfo.get("organization"));
this.roleOrganization = (String) additionalInfo.get("roleOrganization");
} catch (IOException e) {
logger.error(e.getMessage(), e);
}