Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Added two batch job tests in the restaurant sample #442

Closed
wants to merge 17 commits into from
Closed
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.oasp.gastronomy.restaurant.batch.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.SkipListener;
import org.springframework.batch.core.listener.SkipListenerSupport;

/**
* Implementation of a {@link SkipListener} for logging skipped items in batch processes.
*
* @author sroeger
*
*/
public class CustomSkipListener<T, S> extends SkipListenerSupport<T, S> {

private static final Logger LOG = LoggerFactory.getLogger(CustomSkipListener.class);

@Override
public void onSkipInRead(Throwable t) {

LOG.warn("skipped item: {}", t.toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public String toString() {
return getValue().toPlainString() + " " + getCurrency();
}

/**
* {@inheritDoc}
*/
@Override
public int compareTo(Object o) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.oasp.gastronomy.restaurant.general.common.base;

import io.oasp.module.beanmapping.common.api.BeanMapper;

import javax.inject.Inject;

import io.oasp.module.beanmapping.common.api.BeanMapper;

/**
* This abstract class provides {@link #getBeanMapper() access} to the {@link BeanMapper}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package io.oasp.gastronomy.restaurant.general.configuration;

/**
* This class contains the configuration like jobLauncher,Jobrepository etc.
* @author ssarmoka
*/

import io.oasp.module.batch.common.impl.JobLauncherWithAdditionalRestartCapabilities;

import javax.inject.Inject;
import javax.sql.DataSource;

Expand All @@ -18,11 +11,14 @@
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.transaction.PlatformTransactionManager;

import io.oasp.module.batch.common.impl.JobLauncherWithAdditionalRestartCapabilities;

/**
* This class contains configuration of batch beans.
*/
Expand Down Expand Up @@ -50,15 +46,28 @@ public class BeansBatchConfig {
private JobExplorerFactoryBean jobExplorer;

/**
* Datasource configuartion
* Datasource configuration
*/

private DataSource dataSource;

/**
* Transaction manager configuration
*/
private PlatformTransactionManager transactionManager;

/**
* This method is creating beanFactoryPostProcesor bean to register a bean of type 'scope' in
* {@link CustomBeanFactoryPostProcessor}
*
* @return {@link CustomBeanFactoryPostProcessor}
*/
@Bean
public static BeanFactoryPostProcessor beanFactoryPostProcessor() {

return new CustomBeanFactoryPostProcessor();
}

/**
* Isolation level configuration
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.oasp.gastronomy.restaurant.general.configuration;

import org.springframework.batch.core.scope.StepScope;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

/**
* Registers bean of type 'step' to be used in batch processing. E.g to be able to access jobParameter within a reader.
* Note that the annotation {@code @StepScope} has to be used on an implementation not an interface to function properly
*
* @author sroeger
*
*/
public class CustomBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

beanFactory.registerScope("step", new StepScope());
Copy link
Member

@maihacke maihacke Aug 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

muss dieser Scope wirklich so manuell registriert werden? Gibt es da keinen eleganteren Weg?

Copy link
Member

@maihacke maihacke Aug 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the two ways of ENUM-Mapping. I think both ways are eligible. It's more or less a matter of taste and I don't think we need standardize this in OASP. Just leave it as it is...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prinzipiell nein, man könnte den ganzen Stack an Einstellungen und Konfigurationen über @EnableBatchProcessing beziehen. Ich hab angenommen, wir machen das absichtlich alles manuell, um mehr Kontrolle zu haben. Oder wäre es im Zuge der Umstellung auf Spring Boot auch besser, alles über die Annotation zu laden?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for remark. Ticket for migration to java config created by @sroeger #472

}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.oasp.gastronomy.restaurant.general.dataaccess.base.dao;

import org.springframework.stereotype.Repository;

import io.oasp.gastronomy.restaurant.general.dataaccess.api.dao.ApplicationDao;
import io.oasp.module.jpa.dataaccess.api.MutablePersistenceEntity;
import io.oasp.module.jpa.dataaccess.base.AbstractRevisionedDao;

import org.springframework.stereotype.Repository;

/**
* This is the abstract base implementation of {@link ApplicationDao}.
*
Expand All @@ -14,8 +14,8 @@
* @author hohwille
*/
@Repository
public abstract class ApplicationDaoImpl<ENTITY extends MutablePersistenceEntity<Long>> extends
AbstractRevisionedDao<ENTITY> implements ApplicationDao<ENTITY> {
public abstract class ApplicationDaoImpl<ENTITY extends MutablePersistenceEntity<Long>>
extends AbstractRevisionedDao<ENTITY> implements ApplicationDao<ENTITY> {

/**
* The constructor.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package io.oasp.gastronomy.restaurant.general.logic.base;


import io.oasp.gastronomy.restaurant.general.common.base.AbstractBeanMapperSupport;
import io.oasp.module.jpa.common.api.to.PaginatedListTo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -15,6 +11,9 @@
import net.sf.mmm.util.transferobject.api.AbstractTransferObject;
import net.sf.mmm.util.transferobject.api.TransferObject;

import io.oasp.gastronomy.restaurant.general.common.base.AbstractBeanMapperSupport;
import io.oasp.module.jpa.common.api.to.PaginatedListTo;

/**
* Abstract base class for any management implementation class in this application.
*/
Expand Down Expand Up @@ -55,8 +54,8 @@ protected <T extends TransferObject, E extends PersistenceEntity<?>> PaginatedLi

/**
* Creates a {@link Map} with all {@link GenericEntity entities} from the given {@link Collection} using their
* {@link GenericEntity#getId() ID} as key. All {@link GenericEntity entities} without an
* {@link GenericEntity#getId() ID} ({@code null}) will be ignored.
* {@link GenericEntity#getId() ID} as key. All {@link GenericEntity entities} without an {@link GenericEntity#getId()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generell gibt es in deinem PR relativ viele "Code-style"-Änderungen. Ich möchte vermeiden, dass wir häufige Changes wegen unterschiedlicher Code-Style-Configs haben. Ist in deinem Eclipse alles "richtig" konfiguriert, nutzt du ggf. eine andere Version, als bisher?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das ist auffällig, das stimmt. Ich geh durch meine Config durch und schaue, was da nicht passt.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also selbst auf einer frischen Umgebung werden die Änderungen so durchgeführt. In der AbstractComponentFacade z.B. werden die io.oasp imports nach unten geschoben und die Zeilenlänge in Zeile 58/59 "gekürzt". Das sind genau die Einstellungen die wohl bei der oasp-IDE-2.0 mitgeliefert werden (mit zwei Kollegen getestet - bei allen ändern sich Import und Zeilenlänge beim Speichern der Klasse).
Entweder werden alle Klassen an diese Einstellung angepasst, oder die Config wird abgeändert. Im Code finden sich momentan beide Varianten - da sollte man eine Lösung finden: #454

* ID} ({@code null}) will be ignored.
*
* @param <ID> is the generic type of the {@link GenericEntity#getId() ID}.
* @param <E> is the generic type of the {@link GenericEntity entity}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package io.oasp.gastronomy.restaurant.general.logic.base;

import io.oasp.gastronomy.restaurant.general.common.base.AbstractBeanMapperSupport;
import io.oasp.module.jpa.common.api.to.PaginatedListTo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -14,6 +11,9 @@
import net.sf.mmm.util.transferobject.api.AbstractTransferObject;
import net.sf.mmm.util.transferobject.api.TransferObject;

import io.oasp.gastronomy.restaurant.general.common.base.AbstractBeanMapperSupport;
import io.oasp.module.jpa.common.api.to.PaginatedListTo;

/**
* Abstract base class for any <em>use case</em> in this application. Actual implementations need to be annotated with
* {@link javax.inject.Named} and {@link io.oasp.gastronomy.restaurant.general.logic.api.UseCase}.
Expand Down Expand Up @@ -57,8 +57,8 @@ protected <T extends TransferObject, E extends PersistenceEntity<?>> PaginatedLi

/**
* Creates a {@link Map} with all {@link GenericEntity entities} from the given {@link Collection} using their
* {@link GenericEntity#getId() ID} as key. All {@link GenericEntity entities} without an
* {@link GenericEntity#getId() ID} ({@code null}) will be ignored.
* {@link GenericEntity#getId() ID} as key. All {@link GenericEntity entities} without an {@link GenericEntity#getId()
* ID} ({@code null}) will be ignored.
*
* @param <ID> is the generic type of the {@link GenericEntity#getId() ID}.
* @param <E> is the generic type of the {@link GenericEntity entity}.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package io.oasp.gastronomy.restaurant.offermanagement.batch.impl.offerimport.writer;

import io.oasp.gastronomy.restaurant.salesmanagement.logic.api.to.OrderEto;

/**
* Helper entity in order to convert imported data into a {@link OrderEto} as this contains an enum value and a custom
* type. An other solution is to use CustomEditors as done in staffImport.
*
* @author sroeger
*/
public class OfferCsv {

private String name;

private String description;

private String state;

private String mealId;

private String sideDishId;

private String drinkId;

private String price;

/**
* @return name
*/
public String getName() {

return this.name;
}

/**
* @param name new value of name.
*/
public void setName(String name) {

this.name = name;
}

/**
* @return description
*/
public String getDescription() {

return this.description;
}

/**
* @param description new value of description.
*/
public void setDescription(String description) {

this.description = description;
}

/**
* @return state
*/
public String getState() {

return this.state;
}

/**
* @param state new value of state.
*/
public void setState(String state) {

this.state = state;
}

/**
* @return mealId
*/
public String getMealId() {

return this.mealId;
}

/**
* @param mealId new value of mealId.
*/
public void setMealId(String mealId) {

this.mealId = mealId;
}

/**
* @return sideDishId
*/
public String getSideDishId() {

return this.sideDishId;
}

/**
* @param sideDishId new value of sideDishId.
*/
public void setSideDishId(String sideDishId) {

this.sideDishId = sideDishId;
}

/**
* @return drinkId
*/
public String getDrinkId() {

return this.drinkId;
}

/**
* @param drinkId new value of drinkId.
*/
public void setDrinkId(String drinkId) {

this.drinkId = drinkId;
}

/**
* @return price
*/
public String getPrice() {

return this.price;
}

/**
* @param price new value of price.
*/
public void setPrice(String price) {

this.price = price;
}

}
Loading