use of org.eclipse.openvsx.entities.EclipseData in project openvsx by eclipse.
the class EclipseServiceTest method testGetPublisherAgreementNotFound.
@Test
public void testGetPublisherAgreementNotFound() throws Exception {
var user = mockUser();
var eclipseData = new EclipseData();
user.setEclipseData(eclipseData);
eclipseData.personId = "test";
Mockito.when(restTemplate.exchange(any(RequestEntity.class), eq(String.class))).thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
var agreement = eclipse.getPublisherAgreement(user);
assertThat(agreement).isNull();
}
use of org.eclipse.openvsx.entities.EclipseData in project openvsx by eclipse.
the class EclipseServiceTest method testRevokePublisherAgreementByAdmin.
@Test
public void testRevokePublisherAgreementByAdmin() throws Exception {
var user = mockUser();
var eclipseData = new EclipseData();
user.setEclipseData(eclipseData);
eclipseData.personId = "test";
eclipseData.publisherAgreement = new EclipseData.PublisherAgreement();
eclipseData.publisherAgreement.isActive = true;
var admin = new UserData();
admin.setLoginName("admin");
admin.setEclipseToken(new AuthToken());
admin.getEclipseToken().accessToken = "67890";
Mockito.when(tokens.getActiveToken(admin, "eclipse")).thenReturn(admin.getEclipseToken());
eclipse.revokePublisherAgreement(user, admin);
assertThat(user.getEclipseData().publisherAgreement.isActive).isFalse();
}
use of org.eclipse.openvsx.entities.EclipseData in project openvsx by eclipse.
the class EclipseService method updateEclipseData.
/**
* Update the Eclipse data of the given user and commit the change to the database.
*/
protected <T> T updateEclipseData(UserData user, Function<EclipseData, T> update, Consumer<EclipseData> initialize) {
return transactions.execute(status -> {
EclipseData eclipseData;
if (user.getEclipseData() == null) {
eclipseData = new EclipseData();
initialize.accept(eclipseData);
} else {
// We need to clone and reset the data to ensure that Hibernate will persist the updated state
eclipseData = user.getEclipseData().clone();
}
var result = update.apply(eclipseData);
user.setEclipseData(eclipseData);
entityManager.merge(user);
return result;
});
}
use of org.eclipse.openvsx.entities.EclipseData in project openvsx by eclipse.
the class EclipseService method updateUserData.
/**
* Update the given user data with a profile obtained from Eclipse API.
*/
@Transactional
public EclipseData updateUserData(UserData user, EclipseProfile profile) {
EclipseData eclipseData;
if (user.getEclipseData() == null) {
eclipseData = new EclipseData();
} else {
// We need to clone and reset the data to ensure that Hibernate will persist the updated state
eclipseData = user.getEclipseData().clone();
}
if (Strings.isNullOrEmpty(eclipseData.personId)) {
eclipseData.personId = profile.name;
}
if (profile.publisherAgreements != null) {
if (profile.publisherAgreements.openVsx == null) {
if (eclipseData.publisherAgreement != null) {
eclipseData.publisherAgreement.isActive = false;
}
} else if (!Strings.isNullOrEmpty(profile.publisherAgreements.openVsx.version)) {
if (eclipseData.publisherAgreement == null) {
eclipseData.publisherAgreement = new EclipseData.PublisherAgreement();
}
eclipseData.publisherAgreement.isActive = true;
eclipseData.publisherAgreement.version = profile.publisherAgreements.openVsx.version;
}
}
user.setEclipseData(eclipseData);
entityManager.merge(user);
return eclipseData;
}
Aggregations