use of teammates.storage.entity.Account in project teammates by TEAMMATES.
the class AccountAttributesTest method testLegacyAccountEntityToAttributes.
@Test
public void testLegacyAccountEntityToAttributes() {
Account a = new Account("test.googleId", "name", true, "email@e.com", "institute");
a.setStudentProfile(null);
AccountAttributes attr = AccountAttributes.valueOf(a);
assertEquals(a.getGoogleId(), attr.googleId);
assertEquals(a.getEmail(), attr.email);
assertEquals(a.getInstitute(), attr.institute);
assertEquals(a.getName(), attr.name);
assertNull(a.getStudentProfile());
assertNull(attr.studentProfile);
}
use of teammates.storage.entity.Account in project teammates by TEAMMATES.
the class AccountAttributesTest method testToEntity.
@Override
@Test
public void testToEntity() {
AccountAttributes account = createValidAccountAttributesObject();
Account expectedAccount = new Account(account.googleId, account.name, account.isInstructor, account.email, account.institute, account.studentProfile.toEntity());
Account actualAccount = account.toEntity();
assertEquals(expectedAccount.getGoogleId(), actualAccount.getGoogleId());
assertEquals(expectedAccount.getName(), actualAccount.getName());
assertEquals(expectedAccount.getEmail(), actualAccount.getEmail());
assertEquals(expectedAccount.getInstitute(), actualAccount.getInstitute());
assertEquals(expectedAccount.isInstructor(), actualAccount.isInstructor());
ProfilesDb profilesDb = new ProfilesDb();
profilesDb.saveEntity(account.studentProfile.toEntity());
String expectedProfile = StudentProfileAttributes.valueOf(expectedAccount.getStudentProfile()).toString();
String actualProfile = StudentProfileAttributes.valueOf(actualAccount.getStudentProfile()).toString();
assertEquals(expectedProfile, actualProfile);
profilesDb.deleteEntity(account.studentProfile);
}
use of teammates.storage.entity.Account 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.Account 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;
}
use of teammates.storage.entity.Account in project teammates by TEAMMATES.
the class ProfilesDb method getStudentProfileEntityFromDb.
/**
* Gets the profile entity associated with given googleId.
* If the profile does not exist, it tries to get the
* profile from the function
* 'getStudentProfileEntityForLegacyData'.
*/
// TODO: update this function once legacy data have been ported over
private StudentProfile getStudentProfileEntityFromDb(String googleId) {
Key<Account> parentKey = Key.create(Account.class, googleId);
Key<StudentProfile> childKey = Key.create(parentKey, StudentProfile.class, googleId);
StudentProfile profile = ofy().load().key(childKey).now();
if (profile == null) {
return getStudentProfileEntityForLegacyData(googleId);
}
return profile;
}
Aggregations