Search in sources :

Example 1 with StudentProfile

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());
}
Also used : StudentProfile(teammates.storage.entity.StudentProfile) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) Test(org.testng.annotations.Test)

Example 2 with StudentProfile

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);
}
Also used : StudentProfile(teammates.storage.entity.StudentProfile) Account(teammates.storage.entity.Account) InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 3 with StudentProfile

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

Example 4 with StudentProfile

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();
}
Also used : StudentProfile(teammates.storage.entity.StudentProfile) ArrayList(java.util.ArrayList) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) BlobKey(com.google.appengine.api.blobstore.BlobKey) Key(com.googlecode.objectify.Key)

Example 5 with StudentProfile

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

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