Search in sources :

Example 1 with PrincipalData

use of org.candlepin.auth.PrincipalData in project candlepin by candlepin.

the class EventTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public EventDTO populate(ModelTranslator modelTranslator, Event source, EventDTO destination) {
    if (source == null) {
        throw new IllegalArgumentException("source is null");
    }
    if (destination == null) {
        throw new IllegalArgumentException("destination is null");
    }
    destination.setId(source.getId());
    destination.setTargetName(source.getTargetName());
    destination.setConsumerUuid(source.getConsumerUuid());
    destination.setEntityId(source.getEntityId());
    destination.setMessageText(source.getMessageText());
    destination.setOwnerId(source.getOwnerId());
    destination.setPrincipalStore(source.getPrincipalStore());
    destination.setReferenceId(source.getReferenceId());
    destination.setTimestamp(source.getTimestamp());
    destination.setType(source.getType() != null ? source.getType().toString() : null);
    destination.setTarget(source.getTarget() != null ? source.getTarget().toString() : null);
    destination.setReferenceType(source.getReferenceType() != null ? source.getReferenceType().toString() : null);
    destination.setEventData(source.getEventData());
    if (modelTranslator != null) {
        PrincipalData principalData = source.getPrincipal();
        EventDTO.PrincipalDataDTO principalDataDTO = new EventDTO.PrincipalDataDTO(principalData.getType(), principalData.getName());
        destination.setPrincipal(principalDataDTO);
    }
    return destination;
}
Also used : PrincipalData(org.candlepin.auth.PrincipalData)

Example 2 with PrincipalData

use of org.candlepin.auth.PrincipalData in project candlepin by candlepin.

the class EventTranslatorTest method verifyOutput.

@Override
protected void verifyOutput(Event source, EventDTO dest, boolean childrenGenerated) {
    if (source != null) {
        assertEquals(source.getId(), dest.getId());
        assertEquals(source.getTargetName(), dest.getTargetName());
        assertEquals(source.getConsumerUuid(), dest.getConsumerUuid());
        assertEquals(source.getEntityId(), dest.getEntityId());
        assertEquals(source.getOwnerId(), dest.getOwnerId());
        assertEquals(source.getPrincipalStore(), dest.getPrincipalStore());
        assertEquals(source.getMessageText(), dest.getMessageText());
        assertEquals(source.getReferenceId(), dest.getReferenceId());
        assertEquals(source.getTimestamp(), dest.getTimestamp());
        assertEquals(source.getType().toString(), dest.getType());
        assertEquals(source.getTarget().toString(), dest.getTarget());
        assertEquals(source.getReferenceType().toString(), dest.getReferenceType());
        assertEquals(source.getEventData(), dest.getEventData());
        if (childrenGenerated) {
            PrincipalData principalDataSource = source.getPrincipal();
            EventDTO.PrincipalDataDTO principalDataDTO = dest.getPrincipal();
            if (principalDataSource != null) {
                assertEquals(principalDataSource.getType(), principalDataDTO.getType());
                assertEquals(principalDataSource.getName(), principalDataDTO.getName());
            } else {
                assertNull(principalDataDTO);
            }
        } else {
            assertNull(dest.getPrincipal());
        }
    } else {
        assertNull(dest);
    }
}
Also used : PrincipalData(org.candlepin.auth.PrincipalData)

Example 3 with PrincipalData

use of org.candlepin.auth.PrincipalData in project candlepin by candlepin.

the class ListenerWrapperTest method eventJson.

private String eventJson() throws Exception {
    StringWriter sw = new StringWriter();
    Event e = new Event();
    e.setId("10");
    e.setConsumerUuid("20");
    e.setPrincipal(new PrincipalData("5678", "910112"));
    mapper.writeValue(sw, e);
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) PrincipalData(org.candlepin.auth.PrincipalData)

Example 4 with PrincipalData

use of org.candlepin.auth.PrincipalData in project candlepin by candlepin.

the class AtomFeedResourceTest method getEvents.

private List<Event> getEvents(int count) {
    List<Event> list = new ArrayList<>(count);
    Target[] targets = Target.values();
    Type[] types = Type.values();
    for (int i = 0; i < count; i++) {
        Event e = new Event();
        e.setTarget(targets[i % targets.length]);
        e.setType(types[i % types.length]);
        e.setTimestamp(new Date());
        e.setPrincipal(new PrincipalData());
        list.add(e);
    }
    return list;
}
Also used : Target(org.candlepin.audit.Event.Target) Type(org.candlepin.audit.Event.Type) PrincipalData(org.candlepin.auth.PrincipalData) ArrayList(java.util.ArrayList) Event(org.candlepin.audit.Event) Date(java.util.Date)

Example 5 with PrincipalData

use of org.candlepin.auth.PrincipalData in project candlepin by candlepin.

the class EventAdapterImpl method addMessageText.

public void addMessageText(List<Event> events) {
    for (Event event : events) {
        String eventType = (event.getTarget().name() + event.getType().name());
        String message = MESSAGES.get(eventType);
        if (message == null) {
            message = i18n.marktr("Unknown event for user {0} and target {1}");
        }
        PrincipalData pd = event.getPrincipal();
        event.setMessageText(i18n.tr(message, pd.getName(), event.getTargetName()));
    }
}
Also used : PrincipalData(org.candlepin.auth.PrincipalData)

Aggregations

PrincipalData (org.candlepin.auth.PrincipalData)8 Date (java.util.Date)3 Event (org.candlepin.audit.Event)3 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Target (org.candlepin.audit.Event.Target)1 Type (org.candlepin.audit.Event.Type)1