use of teammates.storage.entity.StudentProfile in project teammates by TEAMMATES.
the class StudentProfileAttributesTest method testToEntity.
@Override
@Test
public void testToEntity() {
StudentProfile expectedEntity = createStudentProfileFrom(profile);
StudentProfileAttributes testProfile = StudentProfileAttributes.valueOf(expectedEntity);
StudentProfile actualEntity = testProfile.toEntity();
assertEquals(expectedEntity.getShortName(), actualEntity.getShortName());
assertEquals(expectedEntity.getInstitute(), actualEntity.getInstitute());
assertEquals(expectedEntity.getEmail(), actualEntity.getEmail());
assertEquals(expectedEntity.getNationality(), actualEntity.getNationality());
assertEquals(expectedEntity.getGender(), actualEntity.getGender());
assertEquals(expectedEntity.getMoreInfo(), actualEntity.getMoreInfo());
assertEquals(expectedEntity.getModifiedDate().toString(), actualEntity.getModifiedDate().toString());
assertEquals(expectedEntity.getPictureKey(), actualEntity.getPictureKey());
}
use of teammates.storage.entity.StudentProfile in project teammates by TEAMMATES.
the class AccountsDb method updateAccount.
/**
* Preconditions:
* <br> * {@code accountToAdd} is not null and has valid data.
*/
public void updateAccount(AccountAttributes a, boolean updateStudentProfile) throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, a);
if (!a.isValid()) {
throw new InvalidParametersException(a.getInvalidityInfo());
}
Account accountToUpdate = getAccountEntity(a.googleId, updateStudentProfile);
if (accountToUpdate == null) {
throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT_ACCOUNT + a.googleId + ThreadHelper.getCurrentThreadStack());
}
a.sanitizeForSaving();
accountToUpdate.setName(a.name);
accountToUpdate.setEmail(a.email);
accountToUpdate.setIsInstructor(a.isInstructor);
accountToUpdate.setInstitute(a.institute);
if (updateStudentProfile) {
StudentProfile existingProfile = accountToUpdate.getStudentProfile();
if (existingProfile == null) {
existingProfile = new StudentProfile(a.studentProfile.googleId);
}
StudentProfileAttributes existingProfileAttributes = StudentProfileAttributes.valueOf(existingProfile);
a.studentProfile.modifiedDate = existingProfileAttributes.modifiedDate;
// this is to maintain integrity of the modified date.
if (!existingProfileAttributes.toString().equals(a.studentProfile.toString())) {
StudentProfile updatedProfile = a.studentProfile.toEntity();
accountToUpdate.setStudentProfile(updatedProfile);
profilesDb.saveEntity(updatedProfile);
}
}
saveEntity(accountToUpdate, a);
}
use of teammates.storage.entity.StudentProfile in project teammates by TEAMMATES.
the class ProfilesDb method updateStudentProfile.
/**
* Updates the entire profile based on the given new profile attributes.
* Assumes that the googleId remains the same and so updates the profile
* with the given googleId.
*/
// TODO: update the profile with whatever given values are valid and ignore those that are not valid.
public void updateStudentProfile(StudentProfileAttributes newSpa) throws InvalidParametersException, EntityDoesNotExistException {
validateNewProfile(newSpa);
StudentProfile profileToUpdate = getCurrentProfileFromDb(newSpa.googleId);
if (hasNoNewChangesToProfile(newSpa, profileToUpdate)) {
return;
}
updateProfileWithNewValues(newSpa, profileToUpdate);
}
use of teammates.storage.entity.StudentProfile in project teammates by TEAMMATES.
the class ProfilesDb method deleteEntities.
@Override
public void deleteEntities(Collection<StudentProfileAttributes> entitiesToDelete) {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, entitiesToDelete);
ArrayList<Key<StudentProfile>> keysToDelete = new ArrayList<>();
for (StudentProfileAttributes entityToDelete : entitiesToDelete) {
Key<StudentProfile> keyToDelete = getEntityQueryKeys(entityToDelete).first().now();
if (keyToDelete == null) {
keyToDelete = getEntityQueryKeysForLegacyData(entityToDelete).first().now();
}
if (keyToDelete == null) {
continue;
}
keysToDelete.add(keyToDelete);
log.info(entityToDelete.getBackupIdentifier());
}
ofy().delete().keys(keysToDelete).now();
}
use of teammates.storage.entity.StudentProfile in project teammates by TEAMMATES.
the class ProfilesDb method getStudentProfileEntityForLegacyData.
/**
* Checks if an account entity exists for the given googleId and creates
* a profile entity for this account. This is only used for porting
* legacy account entities on the fly.
*/
// TODO: remove this function once legacy data have been ported over
private StudentProfile getStudentProfileEntityForLegacyData(String googleId) {
Account account = ofy().load().type(Account.class).id(googleId).now();
if (account == null) {
return null;
}
StudentProfile profile = new StudentProfile(account.getGoogleId());
account.setStudentProfile(profile);
return profile;
}
Aggregations