Search in sources :

Example 1 with ThanksForGUI

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());
}
Also used : ThanksForGUI(cz.metacentrum.perun.cabinet.model.ThanksForGUI) Thanks(cz.metacentrum.perun.cabinet.model.Thanks) Date(java.util.Date) Test(org.junit.Test)

Example 2 with ThanksForGUI

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());
}
Also used : ThanksForGUI(cz.metacentrum.perun.cabinet.model.ThanksForGUI) Thanks(cz.metacentrum.perun.cabinet.model.Thanks) Date(java.util.Date) Test(org.junit.Test)

Example 3 with ThanksForGUI

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);
    }
}
Also used : ThanksForGUI(cz.metacentrum.perun.cabinet.model.ThanksForGUI) CabinetException(cz.metacentrum.perun.cabinet.bl.CabinetException) PerunException(cz.metacentrum.perun.core.api.exceptions.PerunException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ThanksForGUI (cz.metacentrum.perun.cabinet.model.ThanksForGUI)3 Thanks (cz.metacentrum.perun.cabinet.model.Thanks)2 Date (java.util.Date)2 Test (org.junit.Test)2 CabinetException (cz.metacentrum.perun.cabinet.bl.CabinetException)1 PerunException (cz.metacentrum.perun.core.api.exceptions.PerunException)1 LinkedHashMap (java.util.LinkedHashMap)1