Commit 84689e5a authored by trang.nguyen's avatar trang.nguyen

ja

parent e86548c5
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
\ No newline at end of file
File added
{
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
}
}
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.dpunkt</groupId>
<artifactId>my-aktion</artifactId>
......@@ -11,25 +10,30 @@
<artifactId>jakarta.jakartaee-api</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>3.0</version>
<type>pom</type>
<scope>provided</scope>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-neo4j</artifactId>
<version>4.0.0.Beta4</version>
</dependency>
</dependencies>
<build>
<finalName>my-aktion</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.2.Final</version>
</plugin>
</plugins>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.2.Final</version>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
......
package de.dpunkt.myaktion.controller;
import java.io.Serializable;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.inject.Inject;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import de.dpunkt.myaktion.model.Donation;
import de.dpunkt.myaktion.model.Donation.Status;
import de.dpunkt.myaktion.services.DonationService;
@ViewScoped
@Named
public class DonateMoneyController implements Serializable {
private static final long serialVersionUID = 5493038842003809106L;
private String textColor = "000000";
private String bgColor = "ffffff";
private Long campaignId;
private Donation donation;
@Inject
private DonationService donationService;
@Inject
private FacesContext facesContext;
@Inject
private Logger logger;
@PostConstruct
public void init() {
this.donation = new Donation();
}
public Long getCampaignId() {
return campaignId;
}
public void setCampaignId(Long campaignId) {
this.campaignId = campaignId;
}
public Donation getDonation() {
return donation;
}
public void setDonation(Donation donation) {
this.donation = donation;
}
public String getTextColor() {
return textColor;
}
public void setTextColor(String textColor) {
this.textColor = textColor;
}
public String getBgColor() {
return bgColor;
}
public void setBgColor(String bgColor) {
this.bgColor = bgColor;
}
public String doDonation() {
getDonation().setStatus(Status.IN_PROCESS);
donationService.addDonation(getCampaignId(), getDonation());
logger.log(Level.INFO, "log.donateMoney.thank_you",
new Object[] { getDonation().getDonorName(), getDonation().getAmount() });
final ResourceBundle resourceBundle = facesContext.getApplication().getResourceBundle(facesContext, "msg");
final String msg = resourceBundle.getString("donateMoney.thank_you");
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, msg, null));
init();
return Pages.DONATE_MONEY;
}
}
\ No newline at end of file
package de.dpunkt.myaktion.controller;
import de.dpunkt.myaktion.data.CampaignProducer;
import de.dpunkt.myaktion.model.Campaign;
import de.dpunkt.myaktion.util.Events.Added;
import de.dpunkt.myaktion.util.Events.Deleted;
import de.dpunkt.myaktion.util.Events.Update;
import javax.enterprise.event.Event;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
@ViewScoped
@Named
public class EditCampaignController implements Serializable {
private static final long serialVersionUID = 2815796004558360299L;
/*
* @Inject public EditCampaignController(CampaignListProducer
* campaignListProducer){ this.campaignListProducer = campaignListProducer; }
*
* @Inject public void setCampaignListProducer(CampaignListProducer
* campaignListProducer) { this.campaignListProducer = campaignListProducer; }
*
*/
@Inject
private CampaignProducer CampaignProducer;
@Inject
@Added
private Event<Campaign> campaignAddEvent;
@Inject
@Deleted
private Event<Campaign> campaignDeleteEvent;
@Inject
@Update
private Event<Campaign> campaignUpdateEvent;
public String doSave() {
if (CampaignProducer.isAddMode()) {
campaignAddEvent.fire(CampaignProducer.getSelectedCampaign());
} else {
campaignUpdateEvent.fire(CampaignProducer.getSelectedCampaign());
}
return Pages.LIST_CAMPAIGNS;
}
public String doCancel() {
return Pages.LIST_CAMPAIGNS;
}
}
package de.dpunkt.myaktion.controller;
import de.dpunkt.myaktion.data.CampaignProducer;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
@SessionScoped
@Named
public class EditDonationFormController implements Serializable {
private static final long serialVersionUID = -4210085664588144340L;
private String textColor = "000000";
private String bgColor = "ffffff";
@Inject
private CampaignProducer campaignProducer;
public String doOk() {
return Pages.LIST_CAMPAIGNS;
}
@Inject
private HttpServletRequest req;
private String getAppUrl() {
String scheme = req.getScheme();
String serverName = req.getServerName();
int serverPort = req.getServerPort();
String contextPath = req.getContextPath();
return scheme+"://"+serverName+":"+serverPort+contextPath;
}
public String getUrl() {
return getAppUrl() + "/" + Pages.DONATE_MONEY + ".jsf" + "?bgColor="
+ bgColor + "&textColor=" + textColor + "&campaignId="
+ campaignProducer.getSelectedCampaign().getId();
}
public String getTextColor() {
return textColor;
}
public void setTextColor(String textColor) {
this.textColor = textColor;
}
public String getBgColor() {
return bgColor;
}
public void setBgColor(String bgColor) {
this.bgColor = bgColor;
}
}
\ No newline at end of file
package de.dpunkt.myaktion.controller;
import de.dpunkt.myaktion.data.CampaignProducer;
import de.dpunkt.myaktion.model.Campaign;
import de.dpunkt.myaktion.model.Donation;
import de.dpunkt.myaktion.services.DonationService;
import de.dpunkt.myaktion.util.Events.Deleted;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.List;
@SessionScoped
@Named
public class ListCampaignsController implements Serializable {
private static final long serialVersionUID = 8693277383648025822L;
@Inject
private CampaignProducer campaignProducer;
private Campaign campaignToDelete;
@Inject
private DonationService donationService;
@Inject
@Deleted
private Event<Campaign> campaignDeleteEvent;
public String doAddCampaign() {
campaignProducer.prepareAddCampaign();
return Pages.EDIT_CAMPAIGN;
}
public String doEditCampaign(Campaign campaign) {
campaignProducer.prepareEditCampaign(campaign);
return Pages.EDIT_CAMPAIGN;
}
public String doEditDonationForm(Campaign campaign) {
campaignProducer.setSelectedCampaign(campaign);
return Pages.EDIT_DONATION_FORM;
}
public String doListDonations(Campaign campaign) {
final List<Donation> donations = donationService.getDonationList(campaign.getId());
campaign.setDonations(donations);
campaignProducer.setSelectedCampaign(campaign);
return Pages.LIST_DONATIONS;
}
public void doDeleteCampaign(Campaign campaign) {
this.campaignToDelete = campaign;
System.out.println("Aktion zum löschen vorgemerkt");
}
public void commitDeleteCampaign() {
campaignDeleteEvent.fire(campaignToDelete);
}
}
\ No newline at end of file
package de.dpunkt.myaktion.controller;
import java.io.Serializable;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
@ViewScoped
@Named
public class ListDonationsController implements Serializable {
private static final long serialVersionUID = 437878972432L;
public String doOk() {
return Pages.LIST_CAMPAIGNS;
}
}
\ No newline at end of file
package de.dpunkt.myaktion.controller;
public class Pages {
public static final String LIST_CAMPAIGNS = "listCampaigns";
public static final String EDIT_CAMPAIGN = "editCampaign";
public static final String EDIT_DONATION_FORM = "editDonationForm";
public static final String LIST_DONATIONS = "listDonations";
public static final String DONATE_MONEY = "donateMoney";
}
\ No newline at end of file
package de.dpunkt.myaktion.data;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Produces;
import javax.inject.Named;
import de.dpunkt.myaktion.model.Campaign;
import de.dpunkt.myaktion.services.CampaignService;
import de.dpunkt.myaktion.util.Events.Added;
import de.dpunkt.myaktion.util.Events.Deleted;
import de.dpunkt.myaktion.util.Events.Update;
import java.util.List;
import javax.inject.Inject;
import javax.annotation.PostConstruct;
@RequestScoped
public class CampaignListProducer {
private List<Campaign> campaigns;
@Inject
private CampaignService campaignService;
public void onCampaignAdded(@Observes @Added Campaign campaign) {
campaignService.addCampaign(campaign);
init();
}
public void onCampaignDeleted(@Observes @Deleted Campaign campaign) {
campaignService.deleteCampaign(campaign);
init();
}
public void onCampaignUpdated(@Observes @Update Campaign campaign) {
campaignService.updateCampaign(campaign);
init();
}
@PostConstruct
public void init() {
campaigns = campaignService.getAllCampaigns();
}
@Produces
@Named
public List<Campaign> getCampaigns() {
return campaigns;
}
}
\ No newline at end of file
package de.dpunkt.myaktion.data;
import de.dpunkt.myaktion.model.Campaign;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Named;
import java.io.Serializable;
@SessionScoped
public class CampaignProducer implements Serializable {
private static final long serialVersionUID = -1828660647917534556L;
private enum Mode {
EDIT, ADD
}
private Campaign campaign;
private Mode mode;
@Produces
@Named
public Campaign getSelectedCampaign() {
return campaign;
}
public void setSelectedCampaign(Campaign campaign) {
this.campaign = campaign;
}
@Produces
@Named
public boolean isAddMode() {
return mode == Mode.ADD;
}
public void prepareAddCampaign() {
this.campaign = new Campaign();
this.mode = Mode.ADD;
}
public void prepareEditCampaign(Campaign campaign) {
this.campaign = campaign;
this.mode = Mode.EDIT;
}
}
\ No newline at end of file
package de.dpunkt.myaktion.model;
import javax.persistence.Embeddable;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
@Embeddable
public class Account {
@NotNull
@Size(min = 5, max = 60, message = "{account.name.size}")
private String name;
@NotNull
@Size(min = 4, max = 40, message = "{account.nameOfBank.size}")
private String nameOfBank;
@NotNull
@Pattern(regexp = "[A-Z]{2}[0-9]{2}[A-Z0-9]{12,30}", message = "{account.iban.pattern}")
private String iban;
public Account() {
this(null, null, null);
}
public Account(String name, String nameOfBank, String iban) {
super();
this.name = name;
this.nameOfBank = nameOfBank;
this.iban = iban;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNameOfBank() {
return nameOfBank;
}
public void setNameOfBank(String nameOfBank) {
this.nameOfBank = nameOfBank;
}
public String getIban() {
return iban;
}
public void setIban(String iban) {
this.iban = iban;
}
}
package de.dpunkt.myaktion.model;
import java.math.BigDecimal;
import java.util.List;
import de.dpunkt.myaktion.model.Account;
import javax.faces.convert.BigDecimalConverter;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@NamedQueries({
@NamedQuery(name = Campaign.findByOrganizer, query = "SELECT c FROM Campaign c WHERE c.organizer = :organizer ORDER BY c.name"),
@NamedQuery(name = Campaign.findAll, query = "SELECT c FROM Campaign c ORDER BY c.name"),
@NamedQuery(name = Campaign.getAmountDonatedSoFar, query = "SELECT SUM(d.amount) FROM Donation d WHERE d.campaign = :campaign") })
@Entity
public class Campaign {
public static final String findByOrganizer = "Campaign.findByOrganizer";
public static final String findAll = "Campaign.findAll";
public static final String getAmountDonatedSoFar = "Campaign.getAmountDonatedSoFar";
@Size(min = 4, max = 30, message = "Der Name einer Aktion muss min. 4 und darf max.30 Zeichen lang sein.")
private String name;
@NotNull(message = "{campaign.targetAmount.notNull}")
@DecimalMin(value = "10.00", message = "{campaign.targetAmount.decimalMin}")
private BigDecimal targetAmount;
@NotNull(message = "{campaign.donationMinimum.notNull}")
@DecimalMin(value = "1.00", message = "{campaign.donationMinimum.decimalMin}")
private BigDecimal donationMinimum;
@Transient
private BigDecimal amountDonatedSoFar;
@AttributeOverrides({ @AttributeOverride(name = "name", column = @Column(name = "accountName")) })
@Embedded
private Account account;