Search in sources :

Example 6 with StudentProfile

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;
}
Also used : StudentProfile(teammates.storage.entity.StudentProfile) Account(teammates.storage.entity.Account)

Example 7 with StudentProfile

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);
}
Also used : StudentProfile(teammates.storage.entity.StudentProfile) BlobKey(com.google.appengine.api.blobstore.BlobKey) Text(com.google.appengine.api.datastore.Text) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) Test(org.testng.annotations.Test)

Example 8 with StudentProfile

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);
}
Also used : StudentProfile(teammates.storage.entity.StudentProfile) BlobKey(com.google.appengine.api.blobstore.BlobKey)

Example 9 with StudentProfile

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);
}
Also used : StudentProfile(teammates.storage.entity.StudentProfile) BlobKey(com.google.appengine.api.blobstore.BlobKey)

Example 10 with StudentProfile

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);
}
Also used : StudentProfile(teammates.storage.entity.StudentProfile) Account(teammates.storage.entity.Account) BlobKey(com.google.appengine.api.blobstore.BlobKey)

Aggregations

StudentProfile (teammates.storage.entity.StudentProfile)10 BlobKey (com.google.appengine.api.blobstore.BlobKey)5 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)4 Account (teammates.storage.entity.Account)4 Test (org.testng.annotations.Test)2 Text (com.google.appengine.api.datastore.Text)1 Key (com.googlecode.objectify.Key)1 ArrayList (java.util.ArrayList)1 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)1 InvalidParametersException (teammates.common.exception.InvalidParametersException)1