use of teammates.storage.entity.StudentProfile 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;
}
use of teammates.storage.entity.StudentProfile in project teammates by TEAMMATES.
the class StudentProfileAttributesTest method testValueOf.
@Test
public void testValueOf() {
StudentProfile studentProfile = new StudentProfile("id", "Joe", "joe@gmail.com", "Teammates Institute", "American", "male", new Text("hello"), new BlobKey("key"));
StudentProfileAttributes profileAttributes = StudentProfileAttributes.valueOf(studentProfile);
assertEquals(studentProfile.getGoogleId(), profileAttributes.googleId);
assertEquals(studentProfile.getShortName(), profileAttributes.shortName);
assertEquals(studentProfile.getEmail(), profileAttributes.email);
assertEquals(studentProfile.getInstitute(), profileAttributes.institute);
assertEquals(studentProfile.getNationality(), profileAttributes.nationality);
assertEquals(studentProfile.getGender(), profileAttributes.gender);
assertEquals(studentProfile.getMoreInfo().getValue(), profileAttributes.moreInfo);
assertEquals(studentProfile.getPictureKey().getKeyString(), profileAttributes.pictureKey);
}
use of teammates.storage.entity.StudentProfile in project teammates by TEAMMATES.
the class ProfilesDb method deleteStudentProfilePicture.
/**
* Deletes the profile picture from GCS and
* updates the profile entity:
* empties the key and updates the modifiedDate.
*/
public void deleteStudentProfilePicture(String googleId) throws EntityDoesNotExistException {
StudentProfile sp = getCurrentProfileFromDb(googleId);
if (!sp.getPictureKey().equals(new BlobKey(""))) {
deletePicture(sp.getPictureKey());
sp.setPictureKey(new BlobKey(""));
sp.setModifiedDate(Instant.now());
}
saveEntity(sp);
}
use of teammates.storage.entity.StudentProfile in project teammates by TEAMMATES.
the class ProfilesDb method updateStudentProfilePicture.
/**
* Updates the pictureKey of the profile with given GoogleId.
* Deletes existing picture if key is different and updates
* modifiedDate
*/
public void updateStudentProfilePicture(String googleId, String newPictureKey) throws EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, googleId);
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, newPictureKey);
Assumption.assertNotEmpty("GoogleId is empty", googleId);
Assumption.assertNotEmpty("PictureKey is empty", newPictureKey);
StudentProfile profileToUpdate = getCurrentProfileFromDb(googleId);
boolean hasNewNonEmptyPictureKey = !newPictureKey.isEmpty() && !newPictureKey.equals(profileToUpdate.getPictureKey().getKeyString());
if (hasNewNonEmptyPictureKey) {
profileToUpdate.setPictureKey(new BlobKey(newPictureKey));
profileToUpdate.setModifiedDate(Instant.now());
}
saveEntity(profileToUpdate);
}
use of teammates.storage.entity.StudentProfile in project teammates by TEAMMATES.
the class AccountsDb method deleteAccount.
/**
* Note: This is a non-cascade delete. <br>
* <br> Fails silently if there is no such account.
* <br> Preconditions:
* <br> * {@code googleId} is not null.
*/
public void deleteAccount(String googleId) {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, googleId);
Account accountToDelete = getAccountEntity(googleId, true);
if (accountToDelete == null) {
return;
}
StudentProfile studentProfile = accountToDelete.getStudentProfile();
if (studentProfile != null) {
BlobKey pictureKey = studentProfile.getPictureKey();
if (!pictureKey.getKeyString().isEmpty()) {
deletePicture(pictureKey);
}
profilesDb.deleteEntityDirect(studentProfile);
}
deleteEntityDirect(accountToDelete);
}
Aggregations