Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • arsnova/arsnova-backend
  • pcvl72/arsnova-backend
  • tksl38/arsnova-backend
3 results
Show changes
Showing
with 530 additions and 65 deletions
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
import de.thm.arsnova.model.Entity;
public abstract class AfterUpdateEvent<E extends Entity> extends CrudEvent<E> {
public AfterUpdateEvent(final Object source, final E entity) {
super(source, entity);
}
}
/* /*
* This file is part of ARSnova Backend. * This file is part of ARSnova Backend.
* Copyright (C) 2012-2015 The ARSnova Team * Copyright (C) 2012-2019 The ARSnova Team and Contributors
* *
* ARSnova Backend is free software: you can redistribute it and/or modify * ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -15,18 +15,20 @@ ...@@ -15,18 +15,20 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package de.thm.arsnova.events;
package de.thm.arsnova.event;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
public abstract class NovaEvent extends ApplicationEvent { /**
* Base class of an ARSnova event.
*/
public abstract class ArsnovaEvent extends ApplicationEvent {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public NovaEvent(Object source) { public ArsnovaEvent(final Object source) {
super(source); super(source);
} }
public abstract void accept(NovaEventVisitor visitor);
} }
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
import de.thm.arsnova.model.Entity;
public class BeforeCreationEvent<E extends Entity> extends CrudEvent<E> {
public BeforeCreationEvent(final Object source, final E entity) {
super(source, entity);
}
}
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
import de.thm.arsnova.model.Entity;
public class BeforeDeletionEvent<E extends Entity> extends CrudEvent<E> {
public BeforeDeletionEvent(final Object source, final E entity) {
super(source, entity);
}
}
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
import de.thm.arsnova.model.Entity;
public class BeforeFullUpdateEvent<E extends Entity> extends BeforeUpdateEvent<E> {
private final E oldEntity;
public BeforeFullUpdateEvent(final Object source, final E entity, final E oldEntity) {
super(source, entity);
this.oldEntity = oldEntity;
}
public E getOldEntity() {
return oldEntity;
}
}
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
import java.util.Map;
import java.util.function.Function;
import de.thm.arsnova.model.Entity;
public class BeforePatchEvent<E extends Entity> extends BeforeUpdateEvent<E> {
private final Function<E, ? extends Object> propertyGetter;
private final Map<String, Object> changes;
public BeforePatchEvent(final Object source, final E entity, final Function<E, ? extends Object> propertyGetter,
final Map<String, Object> changes) {
super(source, entity);
this.propertyGetter = propertyGetter;
this.changes = changes;
}
public Function<E, ? extends Object> getPropertyGetter() {
return propertyGetter;
}
public Map<String, Object> getChanges() {
return changes;
}
}
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
import de.thm.arsnova.model.Entity;
public abstract class BeforeUpdateEvent<E extends Entity> extends CrudEvent<E> {
public BeforeUpdateEvent(final Object source, final E entity) {
super(source, entity);
}
}
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
/**
* Fires whenever a score related value changes.
*/
public class ChangeScoreEvent extends RoomEvent {
private static final long serialVersionUID = 1L;
public ChangeScoreEvent(final Object source, final String roomId) {
super(source, roomId);
}
}
/* /*
* This file is part of ARSnova Backend. * This file is part of ARSnova Backend.
* Copyright (C) 2012-2015 The ARSnova Team * Copyright (C) 2012-2019 The ARSnova Team and Contributors
* *
* ARSnova Backend is free software: you can redistribute it and/or modify * ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -15,35 +15,29 @@ ...@@ -15,35 +15,29 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package de.thm.arsnova.events;
import de.thm.arsnova.entities.Question; package de.thm.arsnova.event;
import de.thm.arsnova.entities.Session;
public class NewQuestionEvent extends NovaEvent { import org.springframework.context.ApplicationEvent;
import org.springframework.core.ResolvableType;
import org.springframework.core.ResolvableTypeProvider;
private static final long serialVersionUID = 1L; import de.thm.arsnova.model.Entity;
private final Question question; public abstract class CrudEvent<E extends Entity> extends ApplicationEvent implements ResolvableTypeProvider {
private E entity;
private final Session session; public CrudEvent(final Object source, final E entity) {
public NewQuestionEvent(Object source, Question question, Session session) {
super(source); super(source);
this.question = question; this.entity = entity;
this.session = session;
}
public Question getQuestion() {
return question;
} }
public Session getSession() { public E getEntity() {
return session; return entity;
} }
@Override @Override
public void accept(NovaEventVisitor visitor) { public ResolvableType getResolvableType() {
visitor.visit(this); return ResolvableType.forClassWithGenerics(getClass(), entity.getClass());
} }
} }
/* /*
* This file is part of ARSnova Backend. * This file is part of ARSnova Backend.
* Copyright (C) 2012-2015 The ARSnova Team * Copyright (C) 2012-2019 The ARSnova Team and Contributors
* *
* ARSnova Backend is free software: you can redistribute it and/or modify * ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -15,36 +15,36 @@ ...@@ -15,36 +15,36 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package de.thm.arsnova.events;
import de.thm.arsnova.entities.Question; package de.thm.arsnova.event;
import de.thm.arsnova.entities.Session;
public class DeleteAnswerEvent extends NovaEvent { import java.util.Set;
import de.thm.arsnova.model.Room;
/**
* Fires whenever the feedback of a specific user has been reset.
*/
public class DeleteFeedbackForRoomsEvent extends ArsnovaEvent {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final Question question; private final Set<Room> sessions;
private final Session session; private final String userId;
public DeleteAnswerEvent(Object source, Question question, Session session) { public DeleteFeedbackForRoomsEvent(final Object source, final Set<Room> rooms, final String userId) {
super(source); super(source);
this.question = question; this.sessions = rooms;
this.session = session; this.userId = userId;
}
@Override
public void accept(NovaEventVisitor visitor) {
visitor.visit(this);
} }
public Question getQuestion() { public Set<Room> getSessions() {
return question; return sessions;
} }
public Session getSession() { public String getUserId() {
return session; return userId;
} }
} }
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
/**
* Fires whenever voting on a question is disabled.
*/
public class FlipFlashcardsEvent extends RoomEvent {
private static final long serialVersionUID = 1L;
public FlipFlashcardsEvent(final Object source, final String roomId) {
super(source, roomId);
}
}
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
/**
* Fires whenever the feedback changes.
*/
public class NewFeedbackEvent extends RoomEvent {
private static final long serialVersionUID = 1L;
public NewFeedbackEvent(final Object source, final String roomId) {
super(source, roomId);
}
}
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
/**
* Base class for all {@link ArsnovaEvent}s that are related to a room.
*/
public abstract class RoomEvent extends ArsnovaEvent {
private static final long serialVersionUID = 1L;
private final String roomId;
public RoomEvent(final Object source, final String roomId) {
super(source);
this.roomId = roomId;
}
public String getRoomId() {
return roomId;
}
}
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
import java.util.Optional;
import org.springframework.context.ApplicationEvent;
import org.springframework.core.ResolvableType;
import org.springframework.core.ResolvableTypeProvider;
import de.thm.arsnova.model.Entity;
public class StateChangeEvent<E extends Entity, T> extends ApplicationEvent implements ResolvableTypeProvider {
private final E entity;
private final String stateName;
private final T newValue;
private final T oldValue;
public StateChangeEvent(final Object source, final E entity, final String stateName,
final T newValue, final T oldValue) {
super(source);
this.entity = entity;
this.stateName = stateName;
this.newValue = newValue;
this.oldValue = oldValue;
}
public E getEntity() {
return entity;
}
public String getStateName() {
return stateName;
}
public T getNewValue() {
return newValue;
}
public Optional<T> getOldValue() {
return Optional.ofNullable(oldValue);
}
@Override
public ResolvableType getResolvableType() {
return ResolvableType.forClassWithGenerics(getClass(), entity.getClass(), newValue.getClass());
}
}
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
import java.util.Map;
import java.util.function.Function;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import de.thm.arsnova.model.Content;
import de.thm.arsnova.model.Entity;
import de.thm.arsnova.model.Room;
/**
* StateEventDispatcher publishes additional, more specific events for state changes of entities when
* {@link AfterUpdateEvent}s are received.
*
* @author Daniel Gerhardt
*/
@Component
public class StateEventDispatcher implements ApplicationEventPublisherAware {
private static final String STATE_PROPERTY = "state";
private static final String SETTINGS_PROPERTY = "settings";
private static final String CLOSED_PROPERTY = "closed";
private ApplicationEventPublisher eventPublisher;
@EventListener
public void dispatchRoomStateEvent(final AfterFullUpdateEvent<Room> event) {
final Room newRoom = event.getEntity();
final Room oldRoom = event.getOldEntity();
publishEventIfPropertyChanged(newRoom, oldRoom, Room::isClosed, CLOSED_PROPERTY);
publishEventIfPropertyChanged(newRoom, oldRoom, Room::getSettings, SETTINGS_PROPERTY);
}
@EventListener
public void dispatchRoomStateEvent(final AfterPatchEvent<Room> event) {
publishEventIfPropertyChanged(event, Function.identity(), CLOSED_PROPERTY, CLOSED_PROPERTY);
publishEventIfPropertyChanged(event, Function.identity(), SETTINGS_PROPERTY, SETTINGS_PROPERTY);
publishEventIfPropertyChanged(event, Room::getSettings, null, SETTINGS_PROPERTY);
}
@EventListener
public void dispatchContentStateEvent(final AfterFullUpdateEvent<Content> event) {
final Content newContent = event.getEntity();
final Content oldContent = event.getOldEntity();
final Function<Content, Content.State> f = Content::getState;
f.apply(newContent);
publishEventIfPropertyChanged(newContent, oldContent, Content::getState, STATE_PROPERTY);
}
@EventListener
public void dispatchContentStateEvent(final AfterPatchEvent<Content> event) {
publishEventIfPropertyChanged(event, Function.identity(), STATE_PROPERTY, STATE_PROPERTY);
publishEventIfPropertyChanged(event, Content::getState, null, STATE_PROPERTY);
}
private <E extends Entity, T extends Object> void publishEventIfPropertyChanged(
final E newEntity, final E oldEntity, final Function<E, T> propertyGetter, final String stateName) {
final T newValue = propertyGetter.apply(newEntity);
final T oldValue = propertyGetter.apply(oldEntity);
if (!newValue.equals(oldValue)) {
eventPublisher.publishEvent(new StateChangeEvent<>(this, newEntity, stateName, newValue, oldValue));
}
}
private <E extends Entity, T extends Object> void publishEventIfPropertyChanged(
final AfterPatchEvent<E> event, final Function<E, T> propertyGetter,
final String property, final String stateName) {
final E entity = event.getEntity();
final Map<String, Object> changes = event.getChanges();
if (event.getPropertyGetter().apply(entity) == propertyGetter.apply(entity)
&& (property == null || changes.containsKey(property))) {
final Object value = property == null ? event.getPropertyGetter().apply(entity) : changes.get(property);
eventPublisher.publishEvent(
new StateChangeEvent<>(this, entity, stateName, value, null));
}
}
@Override
public void setApplicationEventPublisher(final ApplicationEventPublisher applicationEventPublisher) {
this.eventPublisher = applicationEventPublisher;
}
}
/**
* Event classes used for the application event system.
*/
package de.thm.arsnova.event;
/**
* @author Christoph Thelen
*
*/
package de.thm.arsnova.events;
package de.thm.arsnova.exceptions;
public class BadRequestException extends RuntimeException {
private static final long serialVersionUID = 1L;
}
package de.thm.arsnova.exceptions;
public class ForbiddenException extends RuntimeException {
private static final long serialVersionUID = 1L;
}
package de.thm.arsnova.exceptions;
public class NoContentException extends RuntimeException {
private static final long serialVersionUID = 1L;
}