use of cz.metacentrum.perun.cabinet.model.ThanksForGUI in project perun by CESNET.
the class ThanksManagerIntegrationTest method getRichThanksByPublicationIdTest.
@Test
public void getRichThanksByPublicationIdTest() throws Exception {
System.out.println("ThanksManagerIntegrationTest.getRichThanksByPublicationIdTest");
Thanks t = new Thanks();
t.setCreatedBy(sess.getPerunPrincipal().getActor());
t.setCreatedDate(new Date());
t.setOwnerId(owner.getId());
t.setPublicationId(publicationOne.getId());
t = getCabinetManager().createThanks(sess, t);
assertTrue(t != null);
List<ThanksForGUI> thanks = getCabinetManager().getRichThanksByPublicationId(publicationOne.getId());
assertNotNull("No thanks returned for publicationOne", thanks);
assertEquals("Stored and returned thanks should be equals", t.getId(), thanks.get(0).getId());
}
use of cz.metacentrum.perun.cabinet.model.ThanksForGUI in project perun by CESNET.
the class ThanksManagerIntegrationTest method getRichThanksByUserIdTest.
@Test
public void getRichThanksByUserIdTest() throws Exception {
System.out.println("ThanksManagerIntegrationTest.getRichThanksByUserIdTest");
Thanks t = new Thanks();
t.setCreatedBy(sess.getPerunPrincipal().getActor());
t.setCreatedDate(new Date());
t.setOwnerId(owner.getId());
t.setPublicationId(publicationOne.getId());
t = getCabinetManager().createThanks(sess, t);
assertTrue(t != null);
List<ThanksForGUI> thanks = getCabinetManager().getRichThanksByUserId(USER_ID);
assertNotNull("No thanks returned for user " + USER_ID, thanks);
assertEquals("Stored and returned thanks should be equals", t.getId(), thanks.get(0).getId());
}
use of cz.metacentrum.perun.cabinet.model.ThanksForGUI in project perun by CESNET.
the class CabinetManagerBlImpl method setThanksAttribute.
@Override
public void setThanksAttribute(int userId) throws CabinetException {
List<ThanksForGUI> thanks = getThanksManagerBl().getRichThanksByUserId(userId);
try {
// get user
User u = perun.getUsersManager().getUserById(cabinetSession, userId);
// get attribute
AttributeDefinition attrDef = perun.getAttributesManager().getAttributeDefinition(cabinetSession, ATTR_PUBS_NAMESPACE + ":" + ATTR_PUBS_FRIENDLY_NAME);
Attribute attr = new Attribute(attrDef);
// if there are thanks to set
if (thanks != null && !thanks.isEmpty()) {
// create new values map
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
for (ThanksForGUI t : thanks) {
Integer count = 1;
if (map.containsKey(t.getOwnerName())) {
// if contains value already, do +1
String value = map.get(t.getOwnerName());
count = Integer.parseInt(value);
count = count + 1;
}
map.put(t.getOwnerName(), count.toString());
}
attr.setValue(map);
perun.getAttributesManager().setAttribute(cabinetSession, u, attr);
} else {
// empty or null thanks - update to: remove
perun.getAttributesManager().removeAttribute(cabinetSession, u, attrDef);
}
} catch (PerunException e) {
throw new CabinetException("Failed to update " + ATTR_PUBS_NAMESPACE + ":" + ATTR_PUBS_FRIENDLY_NAME + " in Perun.", ErrorCodes.PERUN_EXCEPTION, e);
}
}
Aggregations