/*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017, 2018 Free Software Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
import java.util.Objects;
import javax.ejb.EJB;
import javax.ejb.Stateless;
-import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicCompanyDataAlreadyAddedException;
-import org.mxchange.jcontactsbusiness.model.employee.Employee;
+import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicDataAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.model.employee.Employable;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
import org.mxchange.jusercore.model.user.User;
-import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
/**
* An administrative stateless session bean for business data
* @author Roland Häder<roland@mxchange.org>
*/
@Stateless (name = "adminBasicCompanyData", description = "An administrative statless bean for handling business data (all)")
-public class PizzaAdminBusinessDataSessionBean extends BasePizzaDatabaseBean implements AdminBasicCompanyDataSessionBeanRemote {
+public class PizzaAdminBusinessDataSessionBean extends BasePizzaEnterpriseBean implements AdminBasicCompanyDataSessionBeanRemote {
/**
* Serial number
}
@Override
- public BusinessBasicData addCompanyBasicData (final BusinessBasicData basicData) throws BasicCompanyDataAlreadyAddedException {
+ public BasicData addBusinessBasicData (final BasicData basicData) throws BasicDataAlreadyAddedException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBusinessBasicData: basicData={1} - CALLED!", this.getClass().getSimpleName(), basicData)); //NOI18N
} else if (basicData.getBasicDataId() != null) {
// Should be null
throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} - is not null", basicData.getBasicDataId())); //NOI18N
- } else if (this.isSameCompanyNameAdded(basicData)) {
+ } else if (basicData.getCompanyShortName() == null) {
+ // Should not be null
+ throw new NullPointerException("basicData.companyShortName is null"); //NOI18N
+ } else if (basicData.getCompanyShortName().isEmpty()) {
+ // Should not be empty string
+ throw new IllegalArgumentException("basicData.companyShortName is empty"); //NOI18N
+ } else if (this.isSameCompanyShortNameAdded(basicData)) {
// Throw exception
- throw new BasicCompanyDataAlreadyAddedException(basicData);
+ throw new BasicDataAlreadyAddedException(basicData);
+ } else if ((basicData.getCompanyName() != null) && (basicData.getCompanyName().isEmpty())) {
+ // Should not be empty string when set
+ throw new IllegalArgumentException("basicData.companyName is empty"); //NOI18N
+ } else if ((basicData.getCompanyName() != null) && (this.isSameCompanyNameAdded(basicData))) {
+ // Throw exception
+ throw new BasicDataAlreadyAddedException(basicData);
}
// Now add current date
}
// Is a founder set?
- if (basicData.getCompanyFounder() instanceof Employee) {
+ if (basicData.getCompanyFounder() instanceof Employable) {
// Get managed instance
- final Employee managedEmployee = this.createManaged(basicData.getCompanyFounder());
+ final Employable managedEmployee = this.createManaged(basicData.getCompanyFounder());
// Set it back
basicData.setCompanyFounder(managedEmployee);
}
// Is a contact person set?
- if (basicData.getCompanyContactEmployee() instanceof Employee) {
+ if (basicData.getCompanyContactEmployee() instanceof Employable) {
// Get managed instance
- final Employee managedEmployee = this.createManaged(basicData.getCompanyContactEmployee());
+ final Employable managedEmployee = this.createManaged(basicData.getCompanyContactEmployee());
// Set it back
basicData.setCompanyContactEmployee(managedEmployee);
}
+ // Is a headquarter set?
+ if (basicData.getCompanyHeadquarterData() instanceof Headquarter) {
+ // Get managed instance
+ final Headquarter managedHeadquarter = this.createManaged(basicData.getCompanyHeadquarterData());
+
+ // Set it back
+ basicData.setCompanyHeadquarterData(managedHeadquarter);
+ }
+
// Set created timestamps for any assigned numbers
this.setAllPhoneEntriesCreated(basicData);
*
* @return Whether same company name has been used
*/
- private boolean isSameCompanyNameAdded (final BusinessBasicData basicData) {
+ private boolean isSameCompanyNameAdded (final BasicData basicData) {
// Get all available entries
- final List<BusinessBasicData> list = this.businessDataBean.allCompanyBasicData();
+ final List<BasicData> list = this.businessDataBean.allBusinessBasicData();
// Default is not found
boolean isFound = false;
// Then check each entry
- for (final BusinessBasicData entry : list) {
+ for (final BasicData entry : list) {
// Is the company name matching?
if (Objects.equals(entry.getCompanyName(), basicData.getCompanyName())) {
// Found match
return isFound;
}
+ /**
+ * Checks if given basic data is already added by it's company short name
+ * <p>
+ * @param basicData Basic data to be checked
+ *
+ * @return Whether same company short name has been used
+ */
+ private boolean isSameCompanyShortNameAdded (final BasicData basicData) {
+ // Get all available entries
+ final List<BasicData> list = this.businessDataBean.allBusinessBasicData();
+
+ // Default is not found
+ boolean isFound = false;
+
+ // Then check each entry
+ for (final BasicData entry : list) {
+ // Is the company name matching?
+ if (Objects.equals(entry.getCompanyShortName(), basicData.getCompanyShortName())) {
+ // Found match
+ isFound = true;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
}