use of won.owner.model.UserAtom in project webofneeds by researchstudio-sat.
the class RestUserController method getUserSettings.
@ResponseBody
@RequestMapping(value = "/settings", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
public List<UserSettingsPojo> getUserSettings(@RequestParam(name = "uri", required = false) String uri) {
logger.debug("processing request to /settings");
String username = SecurityContextHolder.getContext().getAuthentication().getName();
// cannot use user object from context since hw doesn't know about created in
// this session atom,
// therefore, we have to retrieve the user object from the user repository
User user = userService.getByUsername(username);
List<UserSettingsPojo> userSettings = new ArrayList<UserSettingsPojo>();
if (uri != null) {
URI atomUri = null;
try {
atomUri = new URI(uri);
for (UserAtom userAtom : user.getUserAtoms()) {
if (userAtom.getUri().equals(atomUri)) {
userSettings.add(new UserSettingsPojo(user.getUsername(), user.getEmail(), userAtom.getUri(), userAtom.isMatches(), userAtom.isRequests(), userAtom.isConversations()));
break;
}
}
} catch (URISyntaxException e) {
// TODO error response
logger.warn(uri + " atom uri problem", e);
}
} else {
// No specific uri requested => all userSettings
for (UserAtom userAtom : user.getUserAtoms()) {
if (userAtom.getState() != AtomState.DELETED) {
userSettings.add(new UserSettingsPojo(user.getUsername(), user.getEmail(), userAtom.getUri(), userAtom.isMatches(), userAtom.isRequests(), userAtom.isConversations()));
}
}
}
return userSettings;
}
use of won.owner.model.UserAtom in project webofneeds by researchstudio-sat.
the class RestUserController method setUserSettings.
@ResponseBody
@RequestMapping(value = "/settings", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
// TODO: move transactionality annotation into the service layer
@Transactional(propagation = Propagation.SUPPORTS)
public ResponseEntity setUserSettings(@RequestBody UserSettingsPojo userSettingsPojo) {
logger.debug("processing POST request to /settings");
String username = SecurityContextHolder.getContext().getAuthentication().getName();
// cannot use user object from context since hw doesn't know about created in
// this session atom,
// therefore, we have to retrieve the user object from the user repository
User user = userService.getByUsername(username);
if (!userSettingsPojo.getUsername().isEmpty() && !user.getUsername().equals(userSettingsPojo.getUsername())) {
return generateStatusResponse(RestStatusResponse.USERNAME_MISMATCH);
}
if (!userSettingsPojo.getEmail().isEmpty() && user.getEmail() == null) {
// TODO validate email server-side?
// set email:
user.setEmail(userSettingsPojo.getEmail());
userService.save(user);
} else if (!userSettingsPojo.getEmail().isEmpty() && !user.getEmail().equals(userSettingsPojo.getEmail())) {
// TODO validate email server-side?
// change email:
user.setEmail(userSettingsPojo.getEmail());
userService.save(user);
logger.info("change email requested - email changed");
}
// retrieve UserAtom
for (UserAtom userAtom : user.getUserAtoms()) {
if (userAtom.getUri().equals(userSettingsPojo.getAtomUri())) {
userAtom.setMatches(userSettingsPojo.isNotifyMatches());
userAtom.setRequests(userSettingsPojo.isNotifyRequests());
userAtom.setConversations(userSettingsPojo.isNotifyConversations());
userAtomRepository.save(userAtom);
break;
}
}
return generateStatusResponse(RestStatusResponse.SETTINGS_CREATED);
}
use of won.owner.model.UserAtom in project webofneeds by researchstudio-sat.
the class UserAtomService method setAtomDeleted.
public void setAtomDeleted(URI atomURI) {
// Get the atom from owner application db
UserAtom userAtom = userAtomRepository.findByAtomUri(atomURI);
userAtom.setState(AtomState.DELETED);
userAtomRepository.save(userAtom);
}
use of won.owner.model.UserAtom in project webofneeds by researchstudio-sat.
the class UserAtomService method updateAtomUriState.
private void updateAtomUriState(final WonMessage wonMessage, AtomState newState) {
URI atomUri = getOwnedAtomURI(wonMessage);
UserAtom userAtom = userAtomRepository.findByAtomUri(atomUri);
userAtom.setState(newState);
// reload the user so we can save it
// (the user object we get from getUserForSession is detached)
userAtomRepository.save(userAtom);
}
use of won.owner.model.UserAtom in project webofneeds by researchstudio-sat.
the class OwnerPersistenceTest method createUserWithAtom.
private void createUserWithAtom(URI atomUri, String email) {
UserAtom a = new UserAtom();
a.setUri(atomUri);
a = userAtomRepository.save(a);
String password = "password";
String role = "SOMEROLE";
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
User user = new User(email, passwordEncoder.encode(password), role);
user.setEmail(email);
// transfer only available when flag is set therefore we can just set
user.setAcceptedTermsOfService(true);
// this
// to true (i think)
KeystorePasswordHolder keystorePassword = new KeystorePasswordHolder();
// generate a password for the keystore and save it in the database, encrypted
// with a symmetric key
// derived from the user's password
keystorePassword.setPassword(KeystorePasswordUtils.generatePassword(KeystorePasswordUtils.KEYSTORE_PASSWORD_BYTES), password);
// keystorePassword = keystorePasswordRepository.save(keystorePassword);
// generate the keystore for the user
KeystoreHolder keystoreHolder = new KeystoreHolder();
try {
// create the keystore if it doesnt exist yet
keystoreHolder.getKeystore(keystorePassword.getPassword(password));
} catch (Exception e) {
throw new IllegalStateException("could not create keystore for user " + email);
}
// keystoreHolder = keystoreHolderRepository.save(keystoreHolder);
user.setKeystorePasswordHolder(keystorePassword);
user.setKeystoreHolder(keystoreHolder);
user = userRepository.save(user);
user.addUserAtom(a);
user = userRepository.save(user);
}
Aggregations