Commit 485f68a1 authored by Noel Alonso's avatar Noel Alonso
Browse files

Añade eventos para clonar y actualizar acceso

Añade entrada en la factoría de evento + tests
parent 4d2b682f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import es.redmic.usersettingslib.events.select.SelectConfirmedEvent;
import es.redmic.usersettingslib.events.select.SelectEvent;
import es.redmic.usersettingslib.events.select.SelectFailedEvent;
import es.redmic.usersettingslib.events.select.SelectedEvent;
import es.redmic.usersettingslib.events.update.UpdateSettingsAccessedDateEvent;

public class SettingsEventFactory {

@@ -126,6 +127,12 @@ public class SettingsEventFactory {
			return new SettingsDeletedEvent().buildFrom(source);
		}

		if (type.equals(SettingsEventTypes.UPDATE_ACCESSED_DATE)) {

			logger.debug("Creando evento UpdateSettingsAccessedDateEvent para: " + source.getAggregateId());
			return new UpdateSettingsAccessedDateEvent().buildFrom(source);
		}

		logger.error("Tipo de evento no soportado");
		throw new InternalException(ExceptionType.INTERNAL_EXCEPTION);
	}
+4 −0
Original line number Diff line number Diff line
@@ -52,6 +52,10 @@ public abstract class SettingsEventTypes {
		SAVED = "SAVED",
		SAVE_FAILED = "SAVE_FAILED",
		SAVE_CANCELLED = "SAVE_CANCELLED",
		//CLONE
		CLONE = "CLONE",
		//UPDATE
		UPDATE_ACCESSED_DATE = "UPDATE_ACCESSED_DATE",
		//DELETE
		DELETE = "DELETE",
		CHECK_DELETE = "CHECK_DELETE",
+59 −0
Original line number Diff line number Diff line
package es.redmic.usersettingslib.events.clone;

import java.util.UUID;

import org.apache.avro.Schema;

import es.redmic.usersettingslib.dto.PersistenceDTO;
import es.redmic.usersettingslib.events.SettingsEventTypes;
import es.redmic.usersettingslib.events.common.PersistenceEvent;

/*-
 * #%L
 * user-settings-lib
 * %%
 * Copyright (C) 2019 REDMIC Project / Server
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

public class CloneSettingsEvent extends PersistenceEvent {

	// @formatter:off

	public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{"
		+ "\"type\":\"record\",\"name\":\"CloneSettingsEvent\","
				+ "\"namespace\":\"es.redmic.usersettingslib.events.clone\",\"fields\":["
			+ getPersistenceEventSchema() + ","
			+ getEventBaseSchema() + "]}");
	// @formatter:on

	static String type = SettingsEventTypes.CLONE;

	public CloneSettingsEvent() {
		super(type);
		setSessionId(UUID.randomUUID().toString());
	}

	public CloneSettingsEvent(PersistenceDTO persistence) {
		super(type);
		this.setPersistence(persistence);
		setSessionId(UUID.randomUUID().toString());
	}

	@Override
	public Schema getSchema() {
		return SCHEMA$;
	}
}
+51 −0
Original line number Diff line number Diff line
package es.redmic.usersettingslib.events.update;

/*-
 * #%L
 * user-settings-lib
 * %%
 * Copyright (C) 2019 REDMIC Project / Server
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.util.UUID;

import org.apache.avro.Schema;

import es.redmic.brokerlib.avro.common.SimpleEvent;
import es.redmic.usersettingslib.events.SettingsEventTypes;

public class UpdateSettingsAccessedDateEvent extends SimpleEvent {

	// @formatter:off

	public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{"
		+ "\"type\":\"record\",\"name\":\"UpdateSettingsAccessedDateEvent\","
				+ "\"namespace\":\"es.redmic.usersettingslib.events.update\",\"fields\":["
			+ getEventBaseSchema() + "]}");
	// @formatter:on

	static String type = SettingsEventTypes.UPDATE_ACCESSED_DATE;

	public UpdateSettingsAccessedDateEvent() {
		super(type);
		setSessionId(UUID.randomUUID().toString());
	}

	@Override
	public Schema getSchema() {
		return SCHEMA$;
	}
}
+13 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import es.redmic.usersettingslib.events.select.SelectConfirmedEvent;
import es.redmic.usersettingslib.events.select.SelectEvent;
import es.redmic.usersettingslib.events.select.SelectFailedEvent;
import es.redmic.usersettingslib.events.select.SelectedEvent;
import es.redmic.usersettingslib.events.update.UpdateSettingsAccessedDateEvent;
import es.redmic.usersettingslib.unit.utils.SettingsDataUtil;

/*-
@@ -211,6 +212,18 @@ public class SettingsEventFactoryTest extends AvroBaseTest {
		checkMetadataFields(source, event);
	}

	@Test
	public void GetEvent_ReturnUpdateSettingsAccessedDateEvent_IfTypeIsSave() {

		Event source = SettingsDataUtil.getUpdateSettingsAccessedDateEvent();
		UpdateSettingsAccessedDateEvent event = (UpdateSettingsAccessedDateEvent) SettingsEventFactory.getEvent(source,
				SettingsEventTypes.UPDATE_ACCESSED_DATE);

		assertEquals(SettingsEventTypes.UPDATE_ACCESSED_DATE, event.getType());

		checkMetadataFields(source, event);
	}

	//

	@Test
Loading