chore(java): consolidate mss-failsafe to single canonical copy
Replace the stale multi-module java/mss-failsafe skeleton (old user-management prototype) with the active single-module machine-safety inspection app that was living in its own standalone repo at the repo root. - Remove old java/mss-failsafe/ multi-module tree (mss, userdata, userManagement, mssfailsafe.datalayer, mssfailsafeWeblayer) incl. committed build artifacts - Add the active app (PrimeFaces 11 / JSF 2.3 / Hibernate 5.6 / iText / POI) flattened into java/mss-failsafe/ as the only mss-failsafe in git - Working tree captured = master tip 2a142b5 + in-progress uncommitted work (incl. .github/*.instructions.md AI-context files) - Archive the standalone repo's 33-commit history in GIT_HISTORY_ARCHIVE.md since its .git was not migrated This is the source of truth / base for the upcoming upgraded rewrite.
This commit is contained in:
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.transaction.Transactional;
|
||||
import model.AbstractEntity;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class AbstractManager<T extends AbstractEntity> {
|
||||
|
||||
protected final Logger LOGGER = LogManager.getLogger(this.getClass());
|
||||
|
||||
private final Class<T> entityClass;
|
||||
|
||||
public AbstractManager(Class<T> entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
}
|
||||
|
||||
protected abstract EntityManager getEntityManager();
|
||||
|
||||
@Transactional
|
||||
public boolean save(T entity) {
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entity.getId() != null) {
|
||||
try {
|
||||
edit(entity);
|
||||
getEntityManager().flush();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
create(entity);
|
||||
getEntityManager().flush();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean saveAll(Collection<T> entities) {
|
||||
if (entities == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entities.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (T entity : entities) {
|
||||
if (entity.getId() != null) {
|
||||
try {
|
||||
edit(entity);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
create(entity);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getEntityManager().flush();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void create(T entity) {
|
||||
try {
|
||||
getEntityManager().persist(entity);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void edit(T entity) {
|
||||
getEntityManager().merge(entity);
|
||||
}
|
||||
|
||||
public T refresh(T entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
if (entity.getId() == null) {
|
||||
save(entity);
|
||||
}
|
||||
|
||||
entity = getEntityManager().merge(entity);
|
||||
Hibernate.initialize(entity);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public boolean removeAllIn(Collection<T> col) {
|
||||
if (col == null || col.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
boolean success = true;
|
||||
|
||||
for (T entity : col) {
|
||||
if (!remove(entity)) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean remove(T entity) {
|
||||
if (entity == null || entity.getId() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Hibernate.initialize(entity);
|
||||
entity = find(entity.getId());
|
||||
|
||||
getEntityManager().remove(entity);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
String queryString = "DELETE FROM " + entityClass.getSimpleName() + " e WHERE e.id = :id";
|
||||
Query query = getEntityManager().createQuery(queryString);
|
||||
query.setParameter("id", entity.getId());
|
||||
|
||||
try {
|
||||
query.executeUpdate();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
|
||||
public T find(Object id) {
|
||||
return getEntityManager().find(entityClass, id);
|
||||
}
|
||||
|
||||
public List<T> findAll() {
|
||||
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
|
||||
cq.select(cq.from(entityClass));
|
||||
return getEntityManager().createQuery(cq).getResultList();
|
||||
}
|
||||
|
||||
public List<T> findRange(int[] range) {
|
||||
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
|
||||
cq.select(cq.from(entityClass));
|
||||
javax.persistence.Query q = getEntityManager().createQuery(cq);
|
||||
q.setMaxResults(range[1] - range[0] + 1);
|
||||
q.setFirstResult(range[0]);
|
||||
return q.getResultList();
|
||||
}
|
||||
|
||||
public int count() {
|
||||
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
|
||||
javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
|
||||
cq.select(getEntityManager().getCriteriaBuilder().count(rt));
|
||||
javax.persistence.Query q = getEntityManager().createQuery(cq);
|
||||
return ((Long) q.getSingleResult()).intValue();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package business;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.inject.Named;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.primefaces.model.DefaultStreamedContent;
|
||||
import org.primefaces.model.StreamedContent;
|
||||
|
||||
@Named
|
||||
@SessionScoped
|
||||
public class BackupFileManager implements Serializable {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(BackupFileManager.class);
|
||||
private static final String BACKUP_DIRECTORY = "/h2DB/";
|
||||
private List<File> backupFiles;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
loadBackupFiles();
|
||||
}
|
||||
|
||||
public void loadBackupFiles() {
|
||||
File directory = new File(BACKUP_DIRECTORY);
|
||||
if (directory.exists() && directory.isDirectory()) {
|
||||
File[] files = directory.listFiles((dir, name) -> name.startsWith("h2-mss-database-backup_") && name.endsWith(".zip"));
|
||||
if (files != null) {
|
||||
backupFiles = Arrays.asList(files);
|
||||
// Sortiere Dateien nach Änderungsdatum (neueste zuerst)
|
||||
Collections.sort(backupFiles, (f1, f2) -> Long.compare(f2.lastModified(), f1.lastModified()));
|
||||
} else {
|
||||
backupFiles = Collections.emptyList();
|
||||
}
|
||||
} else {
|
||||
backupFiles = Collections.emptyList();
|
||||
logger.warn("Backup-Verzeichnis existiert nicht: " + BACKUP_DIRECTORY);
|
||||
}
|
||||
}
|
||||
|
||||
public List<File> getBackupFiles() {
|
||||
return backupFiles;
|
||||
}
|
||||
|
||||
public StreamedContent downloadFile(String fileName) {
|
||||
try {
|
||||
File file = new File(BACKUP_DIRECTORY + fileName);
|
||||
return DefaultStreamedContent.builder()
|
||||
.name(fileName)
|
||||
.contentType("application/zip")
|
||||
.stream(() -> {
|
||||
try {
|
||||
return new FileInputStream(file);
|
||||
} catch (IOException e) {
|
||||
logger.error("Fehler beim Lesen der Backup-Datei: " + fileName, e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
logger.error("Fehler beim Vorbereiten des Downloads für: " + fileName, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.metamodel.Metamodel;
|
||||
import javax.persistence.metamodel.ManagedType;
|
||||
import javax.persistence.metamodel.EntityType;
|
||||
import javax.persistence.metamodel.Attribute;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Stateless
|
||||
@Named
|
||||
public class ChangeToCLOBManager {
|
||||
|
||||
// Inject the Logger
|
||||
private static final Logger logger = LogManager.getLogger(ChangeToCLOBManager.class);
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@javax.ejb.Asynchronous
|
||||
public void checkColumnType() {
|
||||
|
||||
/*
|
||||
Map<String, List<String>> tables_values = checkLobAnnotations(em);
|
||||
logger.info("running check for table values!");
|
||||
tables_values.forEach((table, columns) -> {
|
||||
if (columns == null || columns.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
logger.info("looking for fields in {}", table);
|
||||
|
||||
// Check if the column's data type is VARCHAR
|
||||
columns.stream().filter(col -> (isVarcharColumn(em, table, col))).map(col -> {
|
||||
// Change the column's data type to CLOB
|
||||
changeColumnType(em, table, col);
|
||||
return col;
|
||||
}).forEachOrdered(col -> {
|
||||
logger.info("Changed column type to CLOB of table: {}; column: {}", table, col);
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
private boolean isVarcharColumn(EntityManager em, String tableName, String columnName) {
|
||||
// Construct the native SQL query
|
||||
String nativeSql = "SELECT TYPE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ?1 AND COLUMN_NAME = ?2";
|
||||
|
||||
// Create a native Query
|
||||
Query nativeQuery = em.createNativeQuery(nativeSql);
|
||||
|
||||
// Set the parameters for the query
|
||||
nativeQuery.setParameter(1, tableName.toUpperCase());
|
||||
nativeQuery.setParameter(2, columnName.toUpperCase());
|
||||
|
||||
logger.info("Added parameters 1: {}; 2:{}", tableName.toUpperCase(), columnName.toUpperCase());
|
||||
String dataType = null;
|
||||
// Execute the query and get the result
|
||||
try {
|
||||
dataType = (String) nativeQuery.getSingleResult();
|
||||
} catch (NoResultException e) {
|
||||
logger.info("NoResult", e);
|
||||
}
|
||||
|
||||
// Return true if the column's data type is VARCHAR, false otherwise
|
||||
return dataType != null ? "VARCHAR".equalsIgnoreCase(dataType) : false;
|
||||
}
|
||||
|
||||
private void changeColumnType(EntityManager em, String tableName, String columnName) {
|
||||
// Construct the native SQL query
|
||||
String nativeSql = "ALTER TABLE " + tableName.toUpperCase() + " MODIFY COLUMN " + columnName.toUpperCase() + " CLOB";
|
||||
|
||||
logger.info(nativeSql);
|
||||
|
||||
// Create a native Query
|
||||
Query nativeQuery = em.createNativeQuery(nativeSql);
|
||||
|
||||
// Execute the query
|
||||
nativeQuery.executeUpdate();
|
||||
}
|
||||
|
||||
private Map<String, List<String>> checkLobAnnotations(EntityManager em) {
|
||||
// Create a Map to store the results
|
||||
Map<String, List<String>> results = new HashMap<>();
|
||||
// Get the Metamodel from the EntityManager
|
||||
Metamodel metamodel = em.getMetamodel();
|
||||
|
||||
// Iterate over all the managed types
|
||||
for (ManagedType<?> managedType : metamodel.getManagedTypes()) {
|
||||
// Check if the managed type is an Entity
|
||||
if (managedType.getJavaType().isAnnotationPresent(Entity.class)) {
|
||||
// Get the EntityType for the managed type
|
||||
EntityType<?> entityType = (EntityType<?>) managedType;
|
||||
// Get the table name
|
||||
|
||||
// Iterate over all the attributes
|
||||
for (Attribute<?, ?> attribute : entityType.getAttributes()) {
|
||||
String tableName = entityType.getName();
|
||||
String columnName = attribute.getName();
|
||||
|
||||
try {
|
||||
|
||||
logger.info(entityType.getJavaType().getName());
|
||||
Class<?> cl = getClass().getClassLoader().loadClass(entityType.getJavaType().getName());
|
||||
Field[] fields = getClass().getClassLoader().loadClass(entityType.getJavaType().getName()).getFields();
|
||||
for(Field field : fields){
|
||||
field.setAccessible(true);
|
||||
logger.info(field.getName());
|
||||
if (field.isAnnotationPresent(Lob.class)) {
|
||||
logger.info("Field with lob class!!!");
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("entity name : {}; attribute name: {}; isLob: {}", tableName, columnName, "todo");
|
||||
} catch (SecurityException ex) {
|
||||
logger.error("Security");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
logger.error("Classnot");
|
||||
}
|
||||
|
||||
// Check if the element has the @Lob annotation
|
||||
if (attribute.getJavaType().isAnnotationPresent(Lob.class)) {
|
||||
logger.info("Attribute " + attribute.getName() + " in " + entityType.getName() + " has @Lob annotation");
|
||||
if (!results.containsKey(tableName)) {
|
||||
results.put(tableName, new ArrayList<>());
|
||||
}
|
||||
|
||||
results.get(tableName).add(columnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Schedule;
|
||||
import javax.ejb.Singleton;
|
||||
import javax.ejb.Startup;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Named
|
||||
@Startup
|
||||
@Singleton
|
||||
public class DatabaseBackupManager {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(DatabaseBackupManager.class);
|
||||
|
||||
@EJB
|
||||
private ChangeToCLOBManager changeToCLOBManager;
|
||||
|
||||
@PersistenceContext(unitName="pu_person")
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Schedule(hour="4", minute = "0", second = "0", persistent = true)
|
||||
public void createDatabaseBackup() {
|
||||
// Get the current date and time
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// Format the date and time to be included in the filename
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss");
|
||||
String formattedDateTime = now.format(formatter);
|
||||
|
||||
// Create the backup filename
|
||||
String backupFilename = "/h2DB/h2-mss-database-backup_" + formattedDateTime + ".zip";
|
||||
|
||||
// Use the EntityManager to create a backup of the H2 database
|
||||
entityManager.createNativeQuery("BACKUP TO '" + backupFilename + "'")
|
||||
.executeUpdate();
|
||||
|
||||
// Log a message indicating that the backup was successful
|
||||
logger.info("Successfully created H2 database backup: " + backupFilename);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init(){
|
||||
changeToCLOBManager.checkColumnType();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package business;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.inject.Named;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.primefaces.model.DefaultStreamedContent;
|
||||
import org.primefaces.model.StreamedContent;
|
||||
|
||||
@Named
|
||||
@SessionScoped
|
||||
public class LogFileManager implements Serializable {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(LogFileManager.class);
|
||||
private static final String LOG_DIRECTORY = "/logs/";
|
||||
|
||||
private List<File> logFiles;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
loadLogFiles();
|
||||
}
|
||||
|
||||
public void loadLogFiles() {
|
||||
File directory = new File(LOG_DIRECTORY);
|
||||
if (directory.exists() && directory.isDirectory()) {
|
||||
File[] files = directory.listFiles((dir, name) -> name != null && name.startsWith("application.log"));
|
||||
if (files != null) {
|
||||
logFiles = Arrays.asList(files);
|
||||
Collections.sort(logFiles, (f1, f2) -> Long.compare(f2.lastModified(), f1.lastModified()));
|
||||
} else {
|
||||
logFiles = Collections.emptyList();
|
||||
}
|
||||
} else {
|
||||
logFiles = Collections.emptyList();
|
||||
logger.warn("Log-Verzeichnis existiert nicht: " + LOG_DIRECTORY);
|
||||
}
|
||||
}
|
||||
|
||||
public List<File> getLogFiles() {
|
||||
return logFiles;
|
||||
}
|
||||
|
||||
public StreamedContent downloadFile(String fileName) {
|
||||
try {
|
||||
final File file = new File(LOG_DIRECTORY + fileName);
|
||||
final String contentType;
|
||||
if (fileName.endsWith(".gz")) {
|
||||
contentType = "application/gzip";
|
||||
} else if (fileName.endsWith(".log")) {
|
||||
contentType = "text/plain";
|
||||
} else {
|
||||
contentType = "application/octet-stream";
|
||||
}
|
||||
return DefaultStreamedContent.builder()
|
||||
.name(fileName)
|
||||
.contentType(contentType)
|
||||
.stream(() -> {
|
||||
try {
|
||||
return new FileInputStream(file);
|
||||
} catch (IOException e) {
|
||||
logger.error("Fehler beim Lesen der Log-Datei: " + fileName, e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
logger.error("Fehler beim Vorbereiten des Downloads für Log-Datei: " + fileName, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.util.Properties;
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.DataSource;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.inject.Named;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeBodyPart;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Named
|
||||
@Stateless
|
||||
public class PasswordResetEJB {
|
||||
|
||||
protected final Logger LOGGER = LogManager.getLogger(PasswordResetEJB.class);
|
||||
|
||||
// Set up the email server properties
|
||||
private static final String SMTP_SERVER = "smtp.gmail.com";
|
||||
private static final String USERNAME = "dein@user.gmail.com";
|
||||
private static final String PASSWORD = "HierStehtDeinPasswort";
|
||||
|
||||
// Set up the email message properties
|
||||
private static final String EMAIL_SUBJECT = "Password Reset Request";
|
||||
private static final String EMAIL_BODY
|
||||
= "Sehr geehrte/r %s,\n\n"
|
||||
+ "Sie haben angefordert, Ihr Passwort zurückzusetzen. Bitte klicken Sie auf den unten stehenden Link, um fortzufahren:\n\n"
|
||||
+ "%s\n\n"
|
||||
+ "Wenn Sie diese Anfrage nicht gestellt haben, ignorieren Sie bitte diese E-Mail.\n\n"
|
||||
+ "Bitte beachten Sie, dass der Link nur einmal verwendet werden kann und innerhalb von 24 Stunden ab Erhalt dieser E-Mail abläuft.\n\n"
|
||||
+ "Wenn Sie weitere Fragen haben, zögern Sie bitte nicht, uns zu kontaktieren.\n\n"
|
||||
+ "Freundliche Grüße,\n\n"
|
||||
+ "%s";
|
||||
private static final String COMPANY
|
||||
= "MSS Machine Safety Services\n"
|
||||
+ "+49162 1322 382\n"
|
||||
+ "kontakt@mss-failsafe.com\n"
|
||||
+ "Lüneburger Str. 48\n"
|
||||
+ "28870 Ottersberg";
|
||||
|
||||
private static final String imagePath = "/resources/images/logos/logo_small.png";
|
||||
private static DataSource dataSource;
|
||||
|
||||
public boolean sendPasswordResetEmail(String to, String name, String resetLink) {
|
||||
if (dataSource == null) {
|
||||
dataSource = new FileDataSource(imagePath);
|
||||
}
|
||||
// Set up the email server properties
|
||||
Properties prop = new Properties();
|
||||
prop.put("mail.smtp.host", SMTP_SERVER);
|
||||
prop.put("mail.smtp.port", "587");
|
||||
prop.put("mail.smtp.auth", "true");
|
||||
prop.put("mail.smtp.starttls.enable", "true");
|
||||
|
||||
try {
|
||||
// Set up the email session
|
||||
Session session = Session.getInstance(prop, null);
|
||||
|
||||
// Create a MimeMultipart object to hold the text and image parts of the email
|
||||
MimeMultipart multipart = new MimeMultipart("related");
|
||||
|
||||
// Create a MimeBodyPart object to hold the text of the email
|
||||
MimeBodyPart messageBodyPart = new MimeBodyPart();
|
||||
messageBodyPart.setText(getFormattedMessage(name, resetLink));
|
||||
multipart.addBodyPart(messageBodyPart);
|
||||
|
||||
// Create a MimeBodyPart object to hold the image
|
||||
//MimeBodyPart imagePart = new MimeBodyPart();
|
||||
//imagePart.setDataHandler(new DataHandler(dataSource));
|
||||
//imagePart.setHeader("Content-ID", "MSS Machine Safety Services");
|
||||
//multipart.addBodyPart(imagePart);
|
||||
|
||||
// Set up the email message
|
||||
MimeMessage message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(USERNAME));
|
||||
message.setRecipients(Message.RecipientType.TO, to);
|
||||
message.setSubject(EMAIL_SUBJECT);
|
||||
message.setContent(multipart);
|
||||
|
||||
// Send the email message
|
||||
Transport transport = session.getTransport("smtp");
|
||||
transport.connect(SMTP_SERVER, USERNAME, PASSWORD);
|
||||
transport.sendMessage(message, message.getAllRecipients());
|
||||
transport.close();
|
||||
|
||||
return true;
|
||||
} catch (MessagingException e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getFormattedMessage(String name, String resetLink) {
|
||||
return String.format(EMAIL_BODY, name, resetLink, COMPANY);
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.addresses;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.company.Location;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class CompanyAddressManager extends AbstractManager<Location>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public CompanyAddressManager() {
|
||||
super(Location.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.addresses;
|
||||
|
||||
import business.AbstractManager;
|
||||
import java.util.List;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.company.Location;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class LocationAddressManager extends AbstractManager<Location>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public LocationAddressManager() {
|
||||
super(Location.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.company;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.company.CompanyLogo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class CompanyLogoManager extends AbstractManager<CompanyLogo>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public CompanyLogoManager() {
|
||||
super(CompanyLogo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.company;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.transaction.Transactional;
|
||||
import model.company.Company;
|
||||
import model.company.Location;
|
||||
import model.machine.Machine;
|
||||
import org.hibernate.Hibernate;
|
||||
import java.util.List;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class CompanyManager extends AbstractManager<Company> {
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
private static final String loadWithCollectionQuery =
|
||||
"SELECT DISTINCT c FROM Company c " +
|
||||
"LEFT JOIN FETCH c.addresses " +
|
||||
"LEFT JOIN FETCH c.locations l " +
|
||||
"LEFT JOIN FETCH l.machines m " +
|
||||
"LEFT JOIN FETCH m.securityArea sa " +
|
||||
"LEFT JOIN FETCH sa.securityDevices " +
|
||||
"LEFT JOIN FETCH sa.dangerPoints " +
|
||||
"LEFT JOIN FETCH sa.switchingDevices " +
|
||||
"LEFT JOIN FETCH sa.questionnaires " +
|
||||
"WHERE c.id = :companyId";
|
||||
|
||||
public CompanyManager() {
|
||||
super(Company.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Company findWithAddresses(Company selected) {
|
||||
Company loaded = null;
|
||||
|
||||
/*
|
||||
try {
|
||||
return em.createQuery(loadWithCollectionQuery, Company.class)
|
||||
.setParameter("companyId", selected.getId())
|
||||
.getSingleResult();
|
||||
} catch (NoResultException e) {
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
loaded = find(selected.getId());
|
||||
Hibernate.initialize(loaded);
|
||||
loaded.getLocations().stream()
|
||||
.map(Location::getMachines)
|
||||
.flatMap(List::stream)
|
||||
.map(Machine::getSecurityArea)
|
||||
.flatMap(List::stream)
|
||||
.forEach(area -> {
|
||||
Hibernate.initialize(area.getSecurityDevices());
|
||||
Hibernate.initialize(area.getDangerPoints());
|
||||
Hibernate.initialize(area.getSwitchingDevices());
|
||||
Hibernate.initialize(area.getQuestionnaires());
|
||||
if (area.getQuestionnaires() != null) {
|
||||
area.getQuestionnaires().forEach(q -> Hibernate.initialize(q.getQuestions()));
|
||||
}
|
||||
});
|
||||
//loaded.getLocations().size();
|
||||
//loaded.getAddresses().size();
|
||||
//loaded.getCustomers().size();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
|
||||
return loaded;
|
||||
}
|
||||
|
||||
public Company findCompanyByName(String name) {
|
||||
TypedQuery<Company> query = em.createNamedQuery(Company.FIND_BY_NAME, Company.class);
|
||||
query.setParameter("name", name);
|
||||
|
||||
try {
|
||||
Company loaded = query.getSingleResult();
|
||||
if (loaded != null) {
|
||||
Hibernate.initialize(loaded.getAddresses());
|
||||
loaded.getLocations().stream()
|
||||
.map(Location::getMachines)
|
||||
.flatMap(List::stream)
|
||||
.map(Machine::getSecurityArea)
|
||||
.flatMap(List::stream)
|
||||
.forEach(area -> {
|
||||
Hibernate.initialize(area.getSecurityDevices());
|
||||
Hibernate.initialize(area.getDangerPoints());
|
||||
Hibernate.initialize(area.getSwitchingDevices());
|
||||
});
|
||||
}
|
||||
return loaded;
|
||||
|
||||
} catch (NoResultException noRe) {
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Company findWithLocations(Company selected) {
|
||||
Company loaded = null;
|
||||
|
||||
try {
|
||||
loaded = find(selected.getId());
|
||||
loaded.getCustomers().size();
|
||||
loaded.getLocations().size();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return loaded;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.company;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
import model.customer.Customer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Stateless
|
||||
@Named
|
||||
public class CustomerManager extends AbstractManager<Customer>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public CustomerManager() {
|
||||
super(Customer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
public Customer findByEmail(String email){
|
||||
Customer result = null;
|
||||
if (email == null || email.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
TypedQuery<Customer> query = em.createNamedQuery(Customer.GET_BY_EMAIL, Customer.class);
|
||||
query.setParameter("email", email);
|
||||
|
||||
try {
|
||||
result = query.getSingleResult();
|
||||
} catch (Exception e) {
|
||||
LOGGER.info(e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.company;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.company.Location;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class LocationManager extends AbstractManager<Location>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public LocationManager() {
|
||||
super(Location.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
public Location loadWithMachines(Long id){
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Location loc = find(id);
|
||||
loc.getMachines().size();
|
||||
return loc;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.machine.Contact;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class ContactManager extends AbstractManager<Contact>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public ContactManager() {
|
||||
super(Contact.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import java.util.Collection;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.AbstractEntity;
|
||||
import model.security.DangerPoint;
|
||||
import model.security.MeasuringPoint;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class DangerPointManager extends AbstractManager<DangerPoint> {
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
@EJB
|
||||
MeasuringPointManager measuringPointManager;
|
||||
|
||||
public DangerPointManager() {
|
||||
super(DangerPoint.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(DangerPoint entity) {
|
||||
entity = em.find(DangerPoint.class, entity.getId());
|
||||
Hibernate.initialize(entity.getMeasuringPoint());
|
||||
if (entity.getMeasuringPoint() != null) {
|
||||
entity.getMeasuringPoint().setDangerPoint(null);
|
||||
em.remove(entity.getMeasuringPoint());
|
||||
//measuringPointManager.remove(entity.getMeasuringPoint());
|
||||
entity.setMeasuringPoint(null);
|
||||
}
|
||||
|
||||
entity = em.find(DangerPoint.class, entity.getId());
|
||||
em.remove(entity);
|
||||
//save(entity);
|
||||
|
||||
//return super.remove(entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAllIn(Collection<DangerPoint> col) {
|
||||
for (DangerPoint dp : col) {
|
||||
if (dp.getMeasuringPoint() != null) {
|
||||
dp.getMeasuringPoint().setDangerPoint(null);
|
||||
MeasuringPoint pt = dp.getMeasuringPoint();
|
||||
dp.setMeasuringPoint(null);
|
||||
measuringPointManager.save(pt);
|
||||
measuringPointManager.remove(pt);
|
||||
}
|
||||
dp.setSecurityArea(null);
|
||||
save(dp);
|
||||
}
|
||||
|
||||
return super.removeAllIn(col);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.transaction.Transactional;
|
||||
import model.company.Location;
|
||||
import model.machine.Machine;
|
||||
import model.security.SecurityArea;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class MachineManager extends AbstractManager<Machine>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public MachineManager() {
|
||||
super(Machine.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Machine copyMachine(Machine mac){
|
||||
save(mac);
|
||||
|
||||
mac = refresh(mac);
|
||||
if (mac.getInspections() != null) {
|
||||
mac.getInspections().size();
|
||||
}
|
||||
|
||||
if (mac.getSecurityArea() != null) {
|
||||
mac.getSecurityArea().size();
|
||||
for(SecurityArea area : mac.getSecurityArea()){
|
||||
area.getSecurityDevices().size();
|
||||
area.getSwitchingDevices().size();
|
||||
area.getDangerPoints().size();
|
||||
}
|
||||
}
|
||||
|
||||
Machine copy = new Machine(mac);
|
||||
if (save(copy)) {
|
||||
return copy;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.machine.ManufacturerAddress;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class ManufacturerAddressManager extends AbstractManager<ManufacturerAddress>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public ManufacturerAddressManager() {
|
||||
super(ManufacturerAddress.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.machine.Manufacturer;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class ManufacturerManager extends AbstractManager<Manufacturer>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public ManufacturerManager() {
|
||||
super(Manufacturer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
public Manufacturer reload(Manufacturer manufacturer){
|
||||
if (manufacturer == null || manufacturer.getId() == null) {
|
||||
return new Manufacturer();
|
||||
}
|
||||
|
||||
manufacturer = refresh(manufacturer);
|
||||
Hibernate.initialize(manufacturer.getAdresses());
|
||||
Hibernate.initialize(manufacturer.getContacts());
|
||||
|
||||
return manufacturer;
|
||||
}
|
||||
|
||||
public Manufacturer reloadWithMachines(Manufacturer manufacturer){
|
||||
if (manufacturer == null || manufacturer.getId() == null) {
|
||||
return new Manufacturer();
|
||||
}
|
||||
|
||||
manufacturer = refresh(manufacturer);
|
||||
Hibernate.initialize(manufacturer.getMachines());
|
||||
Hibernate.initialize(manufacturer.getAdresses());
|
||||
Hibernate.initialize(manufacturer.getContacts());
|
||||
|
||||
return manufacturer;
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.security.MeasuringPoint;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Stateless
|
||||
public class MeasuringPointManager extends AbstractManager<MeasuringPoint> {
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public MeasuringPointManager() {
|
||||
super(MeasuringPoint.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import java.util.List;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
import model.question.Questionaire;
|
||||
import model.security.SecurityArea;
|
||||
import model.security.SecurityAreaQuestionnaire;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class SecurityAreaManager extends AbstractManager<SecurityArea>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public SecurityAreaManager() {
|
||||
super(SecurityArea.class);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean delete(SecurityArea area){
|
||||
Query query = em.createNamedQuery(SecurityArea.DELETE);
|
||||
query.setParameter("id", area.getId());
|
||||
|
||||
try{
|
||||
query.executeUpdate();
|
||||
} catch (Exception e){
|
||||
LOGGER.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public SecurityArea cloneArea(SecurityArea area){
|
||||
if (area.getId() != null && area.getId() > 0) {
|
||||
area = em.find(SecurityArea.class, area.getId());
|
||||
Hibernate.initialize(area);
|
||||
//area.getDangerPoints().size();
|
||||
//area.getSecurityDevices().size();
|
||||
}
|
||||
|
||||
return new SecurityArea(area);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a questionnaire to a security area
|
||||
*/
|
||||
@Transactional
|
||||
public SecurityArea addQuestionnaireToSecurityArea(SecurityArea area, Questionaire questionaire) {
|
||||
try {
|
||||
if (area.getId() != null && area.getId() > 0) {
|
||||
area = em.find(SecurityArea.class, area.getId());
|
||||
}
|
||||
|
||||
SecurityAreaQuestionnaire securityAreaQuestionnaire = new SecurityAreaQuestionnaire(questionaire);
|
||||
securityAreaQuestionnaire.setArea(area);
|
||||
|
||||
if (area.getQuestionnaires() == null) {
|
||||
area.setQuestionnaires(new java.util.ArrayList<>());
|
||||
}
|
||||
|
||||
area.getQuestionnaires().add(securityAreaQuestionnaire);
|
||||
em.persist(securityAreaQuestionnaire);
|
||||
em.merge(area);
|
||||
|
||||
return area;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error adding questionnaire to security area", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a questionnaire from a security area
|
||||
*/
|
||||
@Transactional
|
||||
public boolean removeQuestionnaireFromSecurityArea(SecurityArea area, SecurityAreaQuestionnaire questionnaire) {
|
||||
try {
|
||||
if (area.getId() != null && area.getId() > 0) {
|
||||
area = em.find(SecurityArea.class, area.getId());
|
||||
}
|
||||
|
||||
if (questionnaire.getId() != null && questionnaire.getId() > 0) {
|
||||
questionnaire = em.find(SecurityAreaQuestionnaire.class, questionnaire.getId());
|
||||
}
|
||||
|
||||
if (area.getQuestionnaires() != null) {
|
||||
area.getQuestionnaires().remove(questionnaire);
|
||||
}
|
||||
|
||||
em.remove(questionnaire);
|
||||
em.merge(area);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error removing questionnaire from security area", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all available questionnaires that are not yet assigned to the security area
|
||||
*/
|
||||
public List<Questionaire> getAvailableQuestionnaires(SecurityArea area) {
|
||||
try {
|
||||
// Ensure the area is managed to safely access its associations
|
||||
if (area != null && area.getId() != null && area.getId() > 0) {
|
||||
area = em.find(SecurityArea.class, area.getId());
|
||||
}
|
||||
|
||||
// Get all questionnaires
|
||||
Query query = em.createQuery("SELECT q FROM Questionaire q ORDER BY q.name");
|
||||
List<Questionaire> allQuestionnaires = query.getResultList();
|
||||
|
||||
// Filter out questionnaires already assigned to this security area
|
||||
if (area != null && area.getQuestionnaires() != null && !area.getQuestionnaires().isEmpty()) {
|
||||
List<String> assignedNames = area.getQuestionnaires().stream()
|
||||
.map(SecurityAreaQuestionnaire::getName)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
|
||||
allQuestionnaires.removeIf(q -> assignedNames.contains(q.getName()));
|
||||
}
|
||||
|
||||
return allQuestionnaires;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error getting available questionnaires", e);
|
||||
return new java.util.ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
public SecurityArea reloadWithQuestionnaires(SecurityArea area) {
|
||||
if (area == null || area.getId() == null) {
|
||||
return area;
|
||||
}
|
||||
SecurityArea reloaded = em.find(SecurityArea.class, area.getId());
|
||||
Hibernate.initialize(reloaded.getQuestionnaires());
|
||||
Hibernate.initialize(reloaded.getSecurityDevices());
|
||||
Hibernate.initialize(reloaded.getDangerPoints());
|
||||
Hibernate.initialize(reloaded.getSwitchingDevices());
|
||||
return reloaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.security.SecurityDeviceCompany;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class SecurityDeviceCompanyManager extends AbstractManager<SecurityDeviceCompany>{
|
||||
|
||||
public final String FILE_NAME = "Hersteller.txt";
|
||||
|
||||
private static List<SecurityDeviceCompany> companies;
|
||||
private static boolean hasToReload = false;
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public SecurityDeviceCompanyManager() {
|
||||
super(SecurityDeviceCompany.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
public void loadFromFile() {
|
||||
int count = 0;
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
InputStream inputStream = classLoader.getResourceAsStream(FILE_NAME);
|
||||
try (InputStreamReader streamReader =
|
||||
new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||
BufferedReader reader = new BufferedReader(streamReader))
|
||||
{
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
SecurityDeviceCompany company = new SecurityDeviceCompany();
|
||||
company.setName(line);
|
||||
save(company);
|
||||
count++;
|
||||
}
|
||||
System.out.println("Loaded " + count + " SecurityDeviceCompanies from file");
|
||||
LOGGER.info("Loaded " + count + " SecurityDeviceCompanies from file");
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setHasToReload(){
|
||||
hasToReload = true;
|
||||
}
|
||||
|
||||
public void reloadCompanies(){
|
||||
companies = findAll();
|
||||
if (companies != null) {
|
||||
Collections.sort(companies);
|
||||
}
|
||||
}
|
||||
|
||||
public List<SecurityDeviceCompany> getCompanies(){
|
||||
if (hasToReload || companies == null) {
|
||||
reloadCompanies();
|
||||
}
|
||||
|
||||
return companies;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import model.security.SecurityDevice;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class SecurityDeviceManager extends AbstractManager<SecurityDevice>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public SecurityDeviceManager() {
|
||||
super(SecurityDevice.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(SecurityDevice device){
|
||||
Query query = em.createNativeQuery("DELETE FROM SECURITYDEVICE WHERE ID = " + device.getId());
|
||||
|
||||
int result = query.executeUpdate();
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.security.switching.SwitchingDevice;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class SwitchingDeviceManager extends AbstractManager<SwitchingDevice> {
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public SwitchingDeviceManager() {
|
||||
super(SwitchingDevice.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.questions;
|
||||
|
||||
import business.AbstractManager;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
import model.question.Question;
|
||||
import model.question.Questionaire;
|
||||
import model.security.SecurityDeviceCompany;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class QuestionaireManager extends AbstractManager<Questionaire> {
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public QuestionaireManager() {
|
||||
super(Questionaire.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
public List<Questionaire> loadAllWithQuestions() {
|
||||
List<Questionaire> loaded = findAll();
|
||||
|
||||
if (loaded != null) {
|
||||
loaded.forEach(l -> {
|
||||
Hibernate.initialize(l.getQuestions());
|
||||
});
|
||||
}
|
||||
return loaded;
|
||||
}
|
||||
|
||||
public List<Questionaire> loadAllGlobals(){
|
||||
TypedQuery<Questionaire> query = em.createNamedQuery(Questionaire.GET_FOR_ALL_REQUIRED, Questionaire.class);
|
||||
|
||||
try {
|
||||
List<Questionaire> loaded = query.getResultList();
|
||||
if (loaded != null && !loaded.isEmpty()) {
|
||||
loaded.forEach(q -> Hibernate.initialize(q.getQuestions()));
|
||||
}
|
||||
|
||||
return loaded;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public void loadAllFromFile(){
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
URL resource = classLoader.getResource("checklisten");
|
||||
if (resource == null) {
|
||||
LOGGER.error("Couldn't find checklisten folder!");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
File file = new File("/rundata/checklisten");
|
||||
File[] files = file.listFiles();
|
||||
|
||||
for (File f : files) {
|
||||
loadFromFile(f);
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
LOGGER.error(ex);
|
||||
} catch (Exception e){
|
||||
LOGGER.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadFromFile(File file) throws FileNotFoundException {
|
||||
LOGGER.debug("loading from file {}; {}", file, file.getAbsolutePath());
|
||||
int count = 0;
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
try ( InputStreamReader streamReader
|
||||
= new InputStreamReader(inputStream, StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(streamReader)) {
|
||||
String line;
|
||||
Questionaire questionaire = new Questionaire();
|
||||
questionaire.setQuestions(new ArrayList<>());
|
||||
String name = file.getName();
|
||||
name = name.replace(".txt", "");
|
||||
name = name.replace("_", " ");
|
||||
questionaire.setName(name);
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
count++;
|
||||
if (count == 1 && line.startsWith("GLOBAL")) {
|
||||
questionaire.setForAllRequired(true);
|
||||
count = 0;
|
||||
continue;
|
||||
}
|
||||
Question question = new Question();
|
||||
question.setQuestionaire(questionaire);
|
||||
question.setText(line);
|
||||
question.setPosition(count);
|
||||
question.setStandardValues(true);
|
||||
|
||||
questionaire.getQuestions().add(question);
|
||||
}
|
||||
|
||||
save(questionaire);
|
||||
LOGGER.info("Loaded " + count + " questions from " + file.getName());
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e);
|
||||
LOGGER.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteWithQuestions(Questionaire q) {
|
||||
if (q == null) {
|
||||
LOGGER.error("Tried to delete null");
|
||||
return false;
|
||||
}
|
||||
|
||||
Hibernate.initialize(q);
|
||||
Hibernate.isInitialized(q.getQuestions());
|
||||
|
||||
if (q.getQuestions() == null || q.getQuestions().isEmpty()) {
|
||||
return super.remove(q);
|
||||
}
|
||||
|
||||
List<Question> questions = q.getQuestions();
|
||||
q.setQuestions(null);
|
||||
em.merge(q);
|
||||
|
||||
questions.forEach(quest -> {
|
||||
quest.setQuestionaire(null);
|
||||
em.merge(quest);
|
||||
em.remove(quest);
|
||||
});
|
||||
|
||||
em.remove(q);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.tickets;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.user.PersonManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityGraph;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
import model.company.Company;
|
||||
import model.person.Person;
|
||||
import model.ticket.enums.Status;
|
||||
import model.ticket.Ticket;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class TicketManager extends AbstractManager<Ticket> {
|
||||
|
||||
public static final int BATCH_SIZE = 100;
|
||||
|
||||
@EJB
|
||||
PersonManager personManager;
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
private EntityManager em;
|
||||
|
||||
public TicketManager() {
|
||||
super(Ticket.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
public Long countByNumber(String number) {
|
||||
if (number == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TypedQuery<Long> query = getEntityManager().createNamedQuery(Ticket.CHECK_NUMBER_EXISTS, Long.class);
|
||||
query.setParameter("number", number);
|
||||
|
||||
try {
|
||||
return query.getSingleResult();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public List<Ticket> loadBatchOrderedByCreationDate() {
|
||||
List<Ticket> results = null;
|
||||
TypedQuery<Ticket> query = em.createNamedQuery(Ticket.GET_ALL_NEWEST, Ticket.class);
|
||||
query.setParameter("status", Status.CLOSED);
|
||||
query.setMaxResults(BATCH_SIZE);
|
||||
|
||||
try {
|
||||
results = query.getResultList();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public ArrayList<Ticket> loadAllForCompany(Company company) {
|
||||
ArrayList<Ticket> results = new ArrayList<>();
|
||||
if (company == null || company.getId() == null) {
|
||||
return results;
|
||||
}
|
||||
|
||||
TypedQuery<Ticket> query = em.createNamedQuery(Ticket.GET_BY_FOR_COMPANY, Ticket.class);
|
||||
query.setParameter("company", company);
|
||||
try {
|
||||
results = new ArrayList<>(query.getResultList());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public ArrayList<Ticket> loadAllForCompany(String id) {
|
||||
ArrayList<Ticket> results = new ArrayList<>();
|
||||
if (id == null || id.isBlank()) {
|
||||
return results;
|
||||
}
|
||||
Long compID;
|
||||
|
||||
try {
|
||||
compID = Long.valueOf(id);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return results;
|
||||
}
|
||||
|
||||
TypedQuery<Ticket> query = em.createNamedQuery(Ticket.GET_ALL_BY_COMPANYID, Ticket.class);
|
||||
query.setParameter("companyID", compID);
|
||||
try {
|
||||
results = new ArrayList<>(query.getResultList());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public ArrayList<Ticket> loadAllForCompanyWithQuestions(Company company) {
|
||||
ArrayList<Ticket> results = new ArrayList<>();
|
||||
if (company == null || company.getId() == null) {
|
||||
return results;
|
||||
}
|
||||
|
||||
TypedQuery<Ticket> query = em.createNamedQuery(Ticket.GET_BY_FOR_COMPANY, Ticket.class);
|
||||
query.setParameter("company", company);
|
||||
try {
|
||||
results = new ArrayList<>(query.getResultList());
|
||||
if (!results.isEmpty()) {
|
||||
results.stream().map(t -> t.getLocations())
|
||||
.flatMap(List::stream)
|
||||
.map(l -> l.getMachines())
|
||||
.flatMap(List::stream)
|
||||
.forEach(m -> {
|
||||
Hibernate.initialize(m.getSecurityAreas());
|
||||
m.getSecurityAreas().forEach(sa -> Hibernate.initialize(sa.getQuestionaires()));
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public boolean saveDelete(Ticket ticket) {
|
||||
if (ticket == null || ticket.getId() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//initTicket(ticket);
|
||||
|
||||
if (ticket.getWatchers() != null) {
|
||||
ticket = find(ticket.getId());
|
||||
Hibernate.initialize(ticket.getWatchers());
|
||||
for (Person person : ticket.getWatchers()) {
|
||||
personManager.refresh(person);
|
||||
Hibernate.initialize(person.getWatchlist());
|
||||
person.getWatchlist().remove(ticket);
|
||||
|
||||
personManager.save(person);
|
||||
}
|
||||
}
|
||||
|
||||
return remove(ticket);
|
||||
}
|
||||
|
||||
public List<Ticket> loadBatchOrderedByCreationDateByPerson(Person person) {
|
||||
List<Ticket> results = null;
|
||||
TypedQuery<Ticket> query = em.createNamedQuery(Ticket.GET_PERSONAL_ALL_NEWEST, Ticket.class);
|
||||
query.setParameter("owner", person);
|
||||
query.setMaxResults(BATCH_SIZE);
|
||||
|
||||
try {
|
||||
results = query.getResultList();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public List<Ticket> loadPersonalWatchlist(Person person) {
|
||||
List<Ticket> results = null;
|
||||
TypedQuery<Person> query = em.createNamedQuery(Person.FIND_BY_ID, Person.class);
|
||||
query.setParameter("id", person.getId());
|
||||
|
||||
try {
|
||||
Person loaded = query.getSingleResult();
|
||||
Hibernate.initialize(loaded.getWatchlist());
|
||||
results = loaded.getWatchlist();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public Ticket reloadWithWatchlist(Ticket toReload) {
|
||||
if (toReload == null || toReload.getId() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Ticket loaded = em.find(Ticket.class, toReload.getId());
|
||||
Hibernate.initialize(loaded.getWatchers());
|
||||
|
||||
return loaded;
|
||||
}
|
||||
|
||||
public Ticket loadByNumber(String number) {
|
||||
if (number == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TypedQuery<Ticket> query = getEntityManager().createNamedQuery(Ticket.GET_BY_NUMBER, Ticket.class);
|
||||
query.setParameter("number", number);
|
||||
|
||||
try {
|
||||
Ticket loaded = query.getSingleResult();
|
||||
initTicket(loaded);
|
||||
|
||||
return loaded;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimized fetch for protocol generation: uses JPA EntityGraph to pre-load the full graph
|
||||
* needed by ProtocolController without triggering many lazy loads.
|
||||
*/
|
||||
public Ticket fetchTicketGraphForProtocolsByNumber(String number) {
|
||||
if (number == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
TypedQuery<Ticket> query = getEntityManager().createQuery(
|
||||
"SELECT DISTINCT t FROM Ticket t " +
|
||||
"LEFT JOIN FETCH t.company c " +
|
||||
"LEFT JOIN FETCH c.addresses " +
|
||||
"LEFT JOIN FETCH t.serviceAddress " +
|
||||
"LEFT JOIN FETCH t.billingAddress " +
|
||||
"WHERE t.number = :number",
|
||||
Ticket.class);
|
||||
query.setParameter("number", number);
|
||||
Ticket loaded = query.getSingleResult();
|
||||
return loaded;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
// Fallback to safe loader with initialization
|
||||
return loadByNumber(number);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the full ticket graph needed for editing/protocols without using EntityGraph
|
||||
* to avoid MultipleBagFetchException. Loads the Ticket and initializes required associations.
|
||||
*/
|
||||
public Ticket fetchTicketProtocolGraphById(Long id) {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Ticket loaded = getEntityManager().find(Ticket.class, id);
|
||||
initTicket(loaded);
|
||||
return loaded;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant to fetch by ticket number without EntityGraph, delegating to the classic loader.
|
||||
*/
|
||||
public Ticket fetchTicketProtocolGraphByNumber(String number) {
|
||||
return loadByNumber(number);
|
||||
}
|
||||
|
||||
public void initTicket(Ticket ticket) {
|
||||
if (ticket == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Hibernate.initialize(ticket.getComments());
|
||||
Hibernate.initialize(ticket.getContacts());
|
||||
Hibernate.initialize(ticket.getInvoices());
|
||||
Hibernate.initialize(ticket.getLocations());
|
||||
Hibernate.initialize(ticket.getReports());
|
||||
Hibernate.initialize(ticket.getWatchers());
|
||||
Hibernate.initialize(ticket.getRequester());
|
||||
Hibernate.initialize(ticket.getCompany().getAddresses());
|
||||
if (ticket.getLocations() == null) {
|
||||
return;
|
||||
}
|
||||
ticket.getLocations().forEach(loc -> {
|
||||
Hibernate.initialize(loc.getMachines());
|
||||
if (loc.getMachines() == null) {
|
||||
return;
|
||||
}
|
||||
loc.getMachines().forEach(mac -> {
|
||||
Hibernate.initialize(mac);
|
||||
if (mac.getQuestionaires() == null) {
|
||||
return;
|
||||
}
|
||||
Hibernate.initialize(mac.getQuestionaires());
|
||||
mac.getQuestionaires().forEach(ques -> Hibernate.initialize(ques.getQuestions()));
|
||||
|
||||
Hibernate.initialize(mac.getSecurityAreas());
|
||||
|
||||
if (mac.getSecurityAreas() != null) {
|
||||
mac.getSecurityAreas().forEach(area -> {
|
||||
Hibernate.initialize(area);
|
||||
Hibernate.initialize(area.getDangerPoints());
|
||||
Hibernate.initialize(area.getSecurityDevices());
|
||||
Hibernate.initialize(area.getSwitchingDevices());
|
||||
Hibernate.initialize(area.getQuestionaires());
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.tickets.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.ticket.dataCopies.TicketMachine;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class TicketMachineManager extends AbstractManager<TicketMachine>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
private EntityManager em;
|
||||
|
||||
public TicketMachineManager() {
|
||||
super(TicketMachine.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.tickets.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.ticket.questions.TicketQuestion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class TicketQuestionManager extends AbstractManager<TicketQuestion> {
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
private EntityManager em;
|
||||
|
||||
public TicketQuestionManager() {
|
||||
super(TicketQuestion.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.tickets.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.ticket.questions.TicketQuestionaire;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class TicketQuestionaireManager extends AbstractManager<TicketQuestionaire>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
private EntityManager em;
|
||||
|
||||
public TicketQuestionaireManager() {
|
||||
super(TicketQuestionaire.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.tickets.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.ticket.dataCopies.TicketSecurityArea;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class TicketSecurityAreaManager extends AbstractManager<TicketSecurityArea> {
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
private EntityManager em;
|
||||
|
||||
public TicketSecurityAreaManager() {
|
||||
super(TicketSecurityArea.class);
|
||||
}
|
||||
|
||||
public TicketSecurityArea reloadWitchQuestionaires(TicketSecurityArea area) {
|
||||
if (area == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TicketSecurityArea reloaded = em.find(TicketSecurityArea.class, area.getId());
|
||||
Hibernate.initialize(reloaded.getQuestionaires());
|
||||
|
||||
return reloaded;
|
||||
}
|
||||
|
||||
public TicketSecurityArea reloadWithAll(TicketSecurityArea area) {
|
||||
if (area == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TicketSecurityArea reloaded = em.find(TicketSecurityArea.class, area.getId());
|
||||
reloaded.getQuestionaires().size();
|
||||
reloaded.getSecurityDevices().size();
|
||||
reloaded.getSwitchingDevices().size();
|
||||
reloaded.getDangerPoints().size();
|
||||
|
||||
return reloaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
}
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.tickets.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.ticket.questions.SecurityAreaQuestion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class TicketSecurityAreaQuestionManager extends AbstractManager<SecurityAreaQuestion> {
|
||||
|
||||
public TicketSecurityAreaQuestionManager() {
|
||||
super(SecurityAreaQuestion.class);
|
||||
}
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
private EntityManager em;
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.tickets.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.ticket.questions.SecurityAreaQuestionaire;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class TicketSecurityAreaQuestionaireManager extends AbstractManager<SecurityAreaQuestionaire> {
|
||||
|
||||
public TicketSecurityAreaQuestionaireManager() {
|
||||
super(SecurityAreaQuestionaire.class);
|
||||
}
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
private EntityManager em;
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package business.tickets.protocoll;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.files.Report;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class ProtocolManager extends AbstractManager<Report> {
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
private EntityManager em;
|
||||
|
||||
public ProtocolManager() {
|
||||
super(Report.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.user;
|
||||
|
||||
import business.company.CompanyManager;
|
||||
import business.company.CustomerManager;
|
||||
import business.company.LocationManager;
|
||||
import business.machine.MachineManager;
|
||||
import business.machine.SecurityDeviceCompanyManager;
|
||||
import business.questions.QuestionaireManager;
|
||||
import httpauthenticationmechanism.ManagedPerson;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.adresses.CompanyAddress;
|
||||
import model.company.Company;
|
||||
import model.company.Location;
|
||||
import model.company.Status;
|
||||
import model.customer.Customer;
|
||||
import model.machine.Machine;
|
||||
import model.machine.enums.MachineStatus;
|
||||
import model.machine.enums.MachineType;
|
||||
import model.person.Preferences;
|
||||
import model.person.Salt;
|
||||
import model.person.enums.Call;
|
||||
import model.person.enums.UserGroup;
|
||||
import model.security.SecurityArea;
|
||||
import model.security.enums.ApproachSpeed;
|
||||
import model.security.enums.MountingPosition;
|
||||
import model.security.enums.OverrunMeasurementType;
|
||||
import model.security.enums.ProtectionType;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Stateless
|
||||
@Named
|
||||
public class DemoManager {
|
||||
|
||||
protected final Logger LOGGER = LogManager.getLogger(DemoManager.class);
|
||||
|
||||
@EJB
|
||||
PersonManager personManager;
|
||||
|
||||
@EJB
|
||||
CompanyManager companyManager;
|
||||
|
||||
@EJB
|
||||
MachineManager machineManager;
|
||||
|
||||
@EJB
|
||||
LocationManager locationManager;
|
||||
|
||||
@EJB
|
||||
PasswordManager passwordManager;
|
||||
|
||||
@EJB
|
||||
SecurityDeviceCompanyManager securityDeviceCompanyManager;
|
||||
|
||||
@EJB
|
||||
CustomerManager customerManager;
|
||||
|
||||
@EJB
|
||||
QuestionaireManager questionaireManager;
|
||||
|
||||
@Inject
|
||||
ManagedPerson managedPerson;
|
||||
|
||||
/**
|
||||
* Creates a new instance of NewJSFManagedBean
|
||||
*/
|
||||
public DemoManager() {
|
||||
}
|
||||
|
||||
public void runDemos() {
|
||||
try {
|
||||
personManager.demo();
|
||||
managedPerson.getLogins();
|
||||
createDemoCompanies();
|
||||
securityDeviceCompanyManager.loadFromFile();
|
||||
questionaireManager.loadAllFromFile();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
LOGGER.error(e.getMessage());
|
||||
}
|
||||
|
||||
LOGGER.info("Created Demos from DemoManager!");
|
||||
System.out.println("Created Demos from DemoManager!");
|
||||
}
|
||||
|
||||
private void createDemoCompanies() {
|
||||
Company c1 = new Company();
|
||||
|
||||
c1.setKundenNr("Ger-120810");
|
||||
c1.setComment("Testfirma");
|
||||
c1.setHeaderInspection("Headertext gets implemented");
|
||||
c1.setHeaderService("Serviceheader text for all of you!");
|
||||
c1.setName("TestCompany");
|
||||
c1.setStatus(Status.ACTIVE);
|
||||
c1.setSteuerNr("858688");
|
||||
c1.setUmsatzSteuerID("7892346589");
|
||||
|
||||
List<CompanyAddress> addresses1 = new ArrayList<>();
|
||||
CompanyAddress ad1 = new CompanyAddress(
|
||||
c1,
|
||||
"Deutschland",
|
||||
"Vor dem crash",
|
||||
"12",
|
||||
null,
|
||||
121435,
|
||||
"Frankfurt",
|
||||
"Niensbergen",
|
||||
"Hanso Panso",
|
||||
"Nur hohe Rechnungen und tiefe Ansagen."
|
||||
);
|
||||
|
||||
CompanyAddress ad2 = new CompanyAddress(
|
||||
c1,
|
||||
"Östereich",
|
||||
"Vor dem Berg",
|
||||
"22",
|
||||
null,
|
||||
82316,
|
||||
"Stadthagen",
|
||||
"Krammberg",
|
||||
"Ösi Dösi",
|
||||
"Hohe Berge, niedriger IQ"
|
||||
);
|
||||
|
||||
addresses1.add(ad1);
|
||||
addresses1.add(ad2);
|
||||
|
||||
companyManager.create(c1);
|
||||
c1.setAddresses(new HashSet(addresses1));
|
||||
addLocationsAndMachines(c1);
|
||||
createContacts(c1);
|
||||
companyManager.save(c1);
|
||||
}
|
||||
|
||||
private void createContacts(Company company) {
|
||||
Salt salt = new Salt();
|
||||
Salt salt3 = new Salt();
|
||||
|
||||
Set<UserGroup> groupUser = new HashSet<>();
|
||||
groupUser.add(UserGroup.CUSTOMER);
|
||||
|
||||
Customer test = new Customer(
|
||||
"karl.kaufgern@test.de",
|
||||
(passwordManager.hashPassword("test".toCharArray(), salt.getSalt(), salt.getInterations())),
|
||||
salt,
|
||||
groupUser
|
||||
);
|
||||
|
||||
Preferences p1 = new Preferences();
|
||||
p1.setDefaultPreferences(test);
|
||||
|
||||
test.setFirstname("Karl");
|
||||
test.setLastname("Kaufgern");
|
||||
test.setMobile("0124584589");
|
||||
test.setFax("3445565675");
|
||||
test.setTelefon("042154585");
|
||||
test.setDevision("Einkauf");
|
||||
test.setActive(false);
|
||||
test.setCall(Call.HERR);
|
||||
test.setCompany(company);
|
||||
test.setPreferences(p1);
|
||||
|
||||
customerManager.save(test);
|
||||
|
||||
company.addCustomer(test);
|
||||
|
||||
Customer testInactive = new Customer(
|
||||
"lisa.lustig@test.de",
|
||||
(passwordManager.hashPassword("test".toCharArray(), salt3.getSalt(), salt3.getInterations())),
|
||||
salt3,
|
||||
groupUser
|
||||
);
|
||||
Preferences p3 = new Preferences();
|
||||
p3.setDefaultPreferences(testInactive);
|
||||
|
||||
testInactive.setFirstname("Lisa");
|
||||
testInactive.setLastname("Lustig");
|
||||
testInactive.setDevision("Maschinen");
|
||||
testInactive.setCompany(company);
|
||||
testInactive.setMobile("0124584589");
|
||||
testInactive.setFax("3445565675");
|
||||
testInactive.setTelefon("042154585");
|
||||
testInactive.setActive(false);
|
||||
testInactive.setCall(Call.FRAU);
|
||||
testInactive.setPreferences(p3);
|
||||
|
||||
customerManager.save(testInactive);
|
||||
|
||||
company.addCustomer(testInactive);
|
||||
}
|
||||
|
||||
private void addLocationsAndMachines(Company company) {
|
||||
Set<Location> locations = new HashSet<Location>();
|
||||
for (int i = 1; i < 6; i++) {
|
||||
Location loc = createLocation("Halle " + i);
|
||||
locationManager.create(loc);
|
||||
addMachines(loc);
|
||||
locations.add(loc);
|
||||
}
|
||||
|
||||
locations.forEach(l -> l.setCompany(company));
|
||||
company.setLocations(locations);
|
||||
}
|
||||
|
||||
private Location createLocation(String name) {
|
||||
Location location = new Location();
|
||||
location.setName(name);
|
||||
location.setComment("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut l");
|
||||
location.setKostenstelle("Lorem ipsum dolor");
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
private void addMachines(Location location) {
|
||||
List<Machine> machines = new ArrayList<>();
|
||||
|
||||
for (int i = 1; i < 5; i++) {
|
||||
Machine machine = createMachine("Maschine Demo " + i + " " + location.getName());
|
||||
machineManager.create(machine);
|
||||
machine.setLocation(location);
|
||||
machine.setSecurityArea(createAreas(machine));
|
||||
|
||||
machines.add(machine);
|
||||
}
|
||||
|
||||
location.setMachines(machines);
|
||||
}
|
||||
|
||||
private List<SecurityArea> createAreas(Machine machine) {
|
||||
List<SecurityArea> areas = new ArrayList<>();
|
||||
SecurityArea area1 = createLeftArea();
|
||||
SecurityArea area2 = createRightArea();
|
||||
|
||||
area1.setMachine(machine);
|
||||
area2.setMachine(machine);
|
||||
|
||||
areas.add(area1);
|
||||
areas.add(area2);
|
||||
|
||||
return areas;
|
||||
}
|
||||
|
||||
private SecurityArea createLeftArea() {
|
||||
SecurityArea area = new SecurityArea();
|
||||
|
||||
area.setName("Linke Ecke - Hand ab");
|
||||
area.setProtectionType(ProtectionType.LS_MOBILE);
|
||||
area.setApproachSpeed(ApproachSpeed.SPEED_1_6);
|
||||
area.setMountingPosition(MountingPosition.FRONT);
|
||||
area.setOverrunMeasurementType(OverrunMeasurementType.AFTER_PROTECTIVE_DEVICE);
|
||||
area.setComment("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut l");
|
||||
area.setToolNr("Lorem ipsum dolor");
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
private SecurityArea createRightArea() {
|
||||
SecurityArea area = new SecurityArea();
|
||||
|
||||
area.setName("Rechte Ecke - Andere Hand weg");
|
||||
area.setApproachSpeed(ApproachSpeed.SPEED_1_6);
|
||||
area.setProtectionType(ProtectionType.DANGER_POINT_CLOCK);
|
||||
area.setMountingPosition(MountingPosition.FRONT);
|
||||
area.setOverrunMeasurementType(OverrunMeasurementType.AFTER_PROTECTIVE_DEVICE);
|
||||
area.setComment("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut l");
|
||||
area.setToolNr("Lorem ipsum dolor");
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
private Machine createMachine(String name) {
|
||||
Machine machine = new Machine();
|
||||
machine.setName(name);
|
||||
machine.setIndentifier("Lorem ipsum");
|
||||
machine.setCostCenter("Lorem ipsum");
|
||||
machine.setMachineNr("122-123-5565-1");
|
||||
machine.setModellType("Lorem ipsum");
|
||||
machine.setMachineType(MachineType.MECHANICALPRESS);
|
||||
machine.setMachineStatus(MachineStatus.ACTIVE);
|
||||
machine.setChangeYear(2020);
|
||||
machine.setBuildingYear(2015);
|
||||
|
||||
return machine;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.user;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.util.Arrays;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.PBEKeySpec;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import model.person.Password;
|
||||
import model.person.Salt;
|
||||
import model.person.Person;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@Named(value = "passwordManager")
|
||||
@Stateless
|
||||
public class PasswordManager implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4563304131856981259L;
|
||||
|
||||
final static Logger LOGGER = LogManager.getLogger(PasswordManager.class);
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
private EntityManager em;
|
||||
|
||||
//private Password password;
|
||||
private Person user;
|
||||
|
||||
private final int keyLength = 256;
|
||||
|
||||
public byte[] hashPassword(final char[] password, final byte[] salt, final int iterations) {
|
||||
try {
|
||||
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512");
|
||||
PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, this.keyLength);
|
||||
SecretKey key = skf.generateSecret(spec);
|
||||
//this.password = new Password(this.costumer, key.getEncoded());
|
||||
LOGGER.debug("Hash created!");
|
||||
return key.getEncoded();
|
||||
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
||||
LOGGER.error("Failure creating hash for with:" + e);
|
||||
return null;
|
||||
//throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] hashPasswordUser(final char[] password, Person user) {
|
||||
|
||||
if (user == null) {
|
||||
LOGGER.error("Tried to create hash for Nullcostumer!");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512");
|
||||
PBEKeySpec spec = new PBEKeySpec(password, user.getSalt().getSalt(), user.getSalt().getInterations(), keyLength);
|
||||
SecretKey key = skf.generateSecret(spec);
|
||||
LOGGER.debug("Hash created!");
|
||||
return key.getEncoded();
|
||||
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
||||
LOGGER.error("Failure creating hash for" + user.getEmail() + "with: " + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean passwordCheckEmail(final String email, final byte[] password) {
|
||||
TypedQuery<Person> query = em.createNamedQuery(Person.FIND_BY_EMAIL, Person.class);
|
||||
query.setParameter("email", email);
|
||||
try {
|
||||
Person user;
|
||||
user = query.getSingleResult();
|
||||
|
||||
boolean equals = Arrays.equals(password, user.getPassword().getPassword());
|
||||
|
||||
for (int i = 0; i < password.length; i++) {
|
||||
password[i] = 0;
|
||||
}
|
||||
|
||||
return equals;
|
||||
} catch (NoResultException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean passwordCheckCustomer(final Person user, final String password) {
|
||||
byte[] pw = hashPasswordUser(password.toCharArray(), user);
|
||||
|
||||
boolean equals = Arrays.equals(pw, user.getPassword().getPassword());
|
||||
|
||||
for (int i = 0; i < pw.length; i++) {
|
||||
pw[i] = 0;
|
||||
}
|
||||
|
||||
return equals;
|
||||
|
||||
}
|
||||
|
||||
public boolean changePassword(Person user, String newPassword, String oldPassword) {
|
||||
if (user == null) {
|
||||
LOGGER.error("Nullcostumer tried to change Password");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (passwordCheckCustomer(user, oldPassword)) {
|
||||
user = em.find(Person.class, user.getId());
|
||||
user.getPassword().setPassowrd(hashPasswordUser(newPassword.toCharArray(), user));
|
||||
LOGGER.info("Password changed for " + user.getEmail());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
em.merge(user);
|
||||
LOGGER.info("Password changed for " + user.getEmail());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Couldn't save new password to {} with {}", user.getEmail(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean resetPassword(Person user, String newPassword) {
|
||||
if (user == null) {
|
||||
LOGGER.error("Nullcostumer tried to change Password");
|
||||
return false;
|
||||
}
|
||||
|
||||
user = em.find(Person.class, user.getId());
|
||||
user.getPassword().setPassowrd(hashPasswordUser(newPassword.toCharArray(), user));
|
||||
LOGGER.info("Password changed for " + user.getEmail());
|
||||
|
||||
try {
|
||||
em.merge(user);
|
||||
LOGGER.info("Password changed for " + user.getEmail());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Couldn't save new password to {} with {}", user.getEmail(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] generateRandomPassword() {
|
||||
SecureRandom random = new SecureRandom();
|
||||
byte bytes[] = new byte[20];
|
||||
random.nextBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public Password gerateNewRandomPasswordClass(Person user) {
|
||||
Salt salt = user.getSalt();
|
||||
String pass = Arrays.toString(generateRandomPassword());
|
||||
return new Password(user, hashPassword(pass.toCharArray(), salt.getSalt(), salt.getInterations()));
|
||||
}
|
||||
|
||||
public byte[] hashToken(String token) {
|
||||
try {
|
||||
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
|
||||
byte[] test = "SuperTestSalz".getBytes();
|
||||
PBEKeySpec spec = new PBEKeySpec(token.toCharArray(), test, 200, this.keyLength);
|
||||
SecretKey key = skf.generateSecret(spec);
|
||||
LOGGER.debug("TokenHash created!");
|
||||
return key.getEncoded();
|
||||
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
||||
LOGGER.error("Failure creating tokenhash for " + token + " with: " + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Person getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(Person user) {
|
||||
this.user = user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.user;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.user.UserRoleAssignmentHelper;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.PersistenceContextType;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import controller.person.PersonController;
|
||||
import exception.InvalidEmailException;
|
||||
import exception.InvalidPasswordException;
|
||||
import exception.PersonInaktiveException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import model.person.Salt;
|
||||
import model.person.enums.TokenType;
|
||||
import model.person.Person;
|
||||
import model.person.Preferences;
|
||||
import model.person.enums.Call;
|
||||
import model.person.enums.UserGroup;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@Named
|
||||
@Stateless
|
||||
public class PersonManager extends AbstractManager<Person>{
|
||||
|
||||
private static final long serialVersionUID = -6581582446436303658L;
|
||||
|
||||
final static Logger LOGGER = LogManager.getLogger(PersonManager.class);
|
||||
|
||||
@EJB
|
||||
private PasswordManager passwordManager;
|
||||
|
||||
@Inject
|
||||
private PersonController userController;
|
||||
|
||||
@PersistenceContext(name = "pu_person", type = PersistenceContextType.EXTENDED)
|
||||
private EntityManager em;
|
||||
|
||||
public PersonManager(){
|
||||
super(Person.class);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void demo() {
|
||||
Salt salt = new Salt();
|
||||
Salt salt2 = new Salt();
|
||||
Salt salt3 = new Salt();
|
||||
|
||||
// Verwende UserRoleAssignmentHelper für konsistente Rollenzuweisung
|
||||
Set<UserGroup> groupUser = UserRoleAssignmentHelper.assignRolesHierarchically(UserGroup.USER);
|
||||
Set<UserGroup> adminUser = UserRoleAssignmentHelper.assignRolesHierarchically(UserGroup.ADMIN);
|
||||
|
||||
Person test = new Person(
|
||||
"v.jantscha@mss-failsafe.com",
|
||||
(passwordManager.hashPassword("SuperSonic3D!".toCharArray(), salt.getSalt(), salt.getInterations())),
|
||||
salt,
|
||||
groupUser
|
||||
);
|
||||
|
||||
Preferences p1 = new Preferences();
|
||||
p1.setDefaultPreferences(test);
|
||||
|
||||
test.setFirstname("Vitali");
|
||||
test.setLastname("Jantscha");
|
||||
test.setMobile("01621322382");
|
||||
test.setFax("");
|
||||
test.setTelefon("");
|
||||
test.setActive(true);
|
||||
test.setCall(Call.HERR);
|
||||
test.setPreferences(p1);
|
||||
em.persist(test);
|
||||
|
||||
Person testAdmin = new Person(
|
||||
"patrickplate@gmx.de",
|
||||
(passwordManager.hashPassword("SuperSonic3D!".toCharArray(), salt2.getSalt(), salt2.getInterations())),
|
||||
salt2,
|
||||
adminUser
|
||||
);
|
||||
Preferences p2 = new Preferences();
|
||||
p2.setDefaultPreferences(testAdmin);
|
||||
|
||||
testAdmin.setFirstname("Patrick");
|
||||
testAdmin.setLastname("Plate");
|
||||
testAdmin.setMobile("01626893144");
|
||||
testAdmin.setFax("");
|
||||
testAdmin.setTelefon("0421487398");
|
||||
testAdmin.setActive(true);
|
||||
testAdmin.setCall(Call.HERR);
|
||||
testAdmin.setPreferences(p2);
|
||||
em.persist(testAdmin);
|
||||
|
||||
Person testInactive = new Person(
|
||||
"inaktive@test.de",
|
||||
(passwordManager.hashPassword("test".toCharArray(), salt3.getSalt(), salt3.getInterations())),
|
||||
salt3,
|
||||
groupUser
|
||||
);
|
||||
Preferences p3 = new Preferences();
|
||||
p3.setDefaultPreferences(testInactive);
|
||||
|
||||
testInactive.setFirstname("Admin");
|
||||
testInactive.setLastname("Administratori");
|
||||
testInactive.setMobile("0124584589");
|
||||
testInactive.setFax("3445565675");
|
||||
testInactive.setTelefon("042154585");
|
||||
testInactive.setActive(false);
|
||||
testInactive.setCall(Call.HERR);
|
||||
testInactive.setPreferences(p3);
|
||||
em.persist(testInactive);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Person load(Person user) {
|
||||
try {
|
||||
Person loaded = this.em.find(Person.class, user.getId());
|
||||
Hibernate.initialize(loaded);
|
||||
Hibernate.initialize(loaded.getAssignTickets());
|
||||
Hibernate.initialize(loaded.getCreatedTickets());
|
||||
Hibernate.initialize(loaded.getUserGroups());
|
||||
|
||||
return loaded;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Person getActiveUser() {
|
||||
try {
|
||||
Person user = em.find(Person.class, userController.getActiveUser().getId());
|
||||
Hibernate.initialize(user);
|
||||
Hibernate.initialize(user.getAssignTickets());
|
||||
Hibernate.initialize(user.getCreatedTickets());
|
||||
Hibernate.initialize(user.getUserGroups());
|
||||
return user;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("couldn't load user: " + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Person getActiveUserWithWatchlist(){
|
||||
try {
|
||||
Person user = em.find(Person.class, userController.getActiveUser().getId());
|
||||
Hibernate.initialize(user.getWatchlist());
|
||||
return user;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("couldn't load user: " + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Person getPlainActiveUser() {
|
||||
try {
|
||||
Person user = em.find(Person.class, userController.getActiveUser().getId());
|
||||
return user;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("couldn't load user: " + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Person> getByEmail(String email) {
|
||||
try {
|
||||
Person person = this.em.createNamedQuery(Person.FIND_BY_EMAIL, Person.class)
|
||||
.setParameter("email", email).getSingleResult();
|
||||
|
||||
if (person != null) {
|
||||
person.getUserGroups().size();
|
||||
if (person.getCreatedTickets() != null) {
|
||||
person.getCreatedTickets().size();
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.of(person);
|
||||
} catch (Exception e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Person> getByLoginToken(String loginToken, TokenType tokenType) {
|
||||
Optional<Person> optional;
|
||||
try {
|
||||
|
||||
optional = Optional.of(this.em.createNamedQuery(Person.FIND_BY_TOKEN, Person.class)
|
||||
.setParameter("tokenHash", this.passwordManager.hashToken(loginToken))
|
||||
.setParameter("tokenType", tokenType)
|
||||
.setParameter("timestamp", Instant.now())
|
||||
.getSingleResult()
|
||||
);
|
||||
return optional;
|
||||
} catch (Exception e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public Person getByEmailAndPassword(String email, String password) {
|
||||
Person managedUser = getByEmail(email).orElseThrow(InvalidEmailException::new);
|
||||
LOGGER.debug("Loaded " + managedUser.getEmail());
|
||||
if (!passwordManager.passwordCheckCustomer(managedUser, password)) {
|
||||
throw new InvalidPasswordException();
|
||||
}
|
||||
if (!managedUser.isActive()) {
|
||||
throw new PersonInaktiveException();
|
||||
}
|
||||
userController.setActiveUser(managedUser);
|
||||
return managedUser;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean save(Person user) {
|
||||
if (user == null) {
|
||||
LOGGER.error("Tried to save null or Nullcustomer");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (user.getId() != null && user.getId() > 0) {
|
||||
em.merge(user);
|
||||
} else {
|
||||
em.persist(user);
|
||||
}
|
||||
LOGGER.info("Saved " + user.getEmail());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Tried to save " + user.getEmail() + " with error: " + e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String resetPassword() {
|
||||
//TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager(){
|
||||
return em;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.user;
|
||||
|
||||
import business.AbstractManager;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.person.Preferences;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Stateless
|
||||
public class PreferencesManager extends AbstractManager<Preferences>{
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
public PreferencesManager() {
|
||||
super(Preferences.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.user;
|
||||
|
||||
import java.time.Instant;
|
||||
import static java.time.temporal.ChronoUnit.DAYS;
|
||||
import static java.util.UUID.randomUUID;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import exception.InvalidEmailException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import model.person.Token;
|
||||
import model.person.enums.TokenType;
|
||||
import model.person.Person;
|
||||
|
||||
import java.util.Arrays;
|
||||
import static java.time.Instant.now;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Schedule;
|
||||
import javax.persistence.TypedQuery;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@Stateless
|
||||
public class TokenManager {
|
||||
|
||||
protected static final Logger LOGGER = LogManager.getLogger(TokenManager.class);
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
private EntityManager em;
|
||||
|
||||
@EJB
|
||||
PasswordManager passwordManager;
|
||||
|
||||
@EJB
|
||||
PersonManager customerManager;
|
||||
|
||||
public Token loadByRaw(String rawToken) {
|
||||
if (rawToken == null || rawToken.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TypedQuery<Token> query = em.createNamedQuery(Token.LOAD_BY_RAW, Token.class);
|
||||
query.setParameter("raw", rawToken);
|
||||
|
||||
try {
|
||||
return query.getSingleResult();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Couldn't find Token for {} with exception {}", rawToken, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String generatePWResetToken(final String email, final String ipAddress, final String description) {
|
||||
|
||||
String rawToken = randomUUID().toString();
|
||||
Instant expiration = now().plus(1, DAYS);
|
||||
TokenType type = TokenType.RESET_PASSWORD;
|
||||
|
||||
save(rawToken, email, ipAddress, description, type, expiration);
|
||||
|
||||
return rawToken;
|
||||
}
|
||||
|
||||
public String generate(final String email, final String ipAddress, final String description,
|
||||
final TokenType tokenType) {
|
||||
|
||||
String rawToken = randomUUID().toString();
|
||||
Instant expiration = now().plus(14, DAYS);
|
||||
|
||||
save(rawToken, email, ipAddress, description, tokenType, expiration);
|
||||
|
||||
return rawToken;
|
||||
}
|
||||
|
||||
public String generateFileToken(final String email, final String description) {
|
||||
|
||||
String rawToken = randomUUID().toString();
|
||||
Instant expiration = now().plus(3, DAYS);
|
||||
|
||||
save(rawToken, email, null, description, TokenType.FILE, expiration);
|
||||
|
||||
return rawToken;
|
||||
}
|
||||
|
||||
public void save(final String rawToken, final String email, final String ipAddress,
|
||||
final String description, final TokenType tokenType, final Instant expiration) {
|
||||
|
||||
Person user = this.customerManager.getByEmail(email)
|
||||
.orElseThrow(InvalidEmailException::new);
|
||||
|
||||
Token token = new Token();
|
||||
|
||||
token.setPerson(user);
|
||||
token.setTokenHash(rawToken);
|
||||
token.setExpiration(expiration);
|
||||
token.setDescription(description);
|
||||
token.setTokenType(tokenType);
|
||||
token.setIpAddress(ipAddress);
|
||||
user.addToken(token);
|
||||
|
||||
this.em.persist(user);
|
||||
}
|
||||
|
||||
public void remove(String token) {
|
||||
this.em.createNamedQuery(Token.REMOVE_TOKEN)
|
||||
.setParameter("tokenHash", token).executeUpdate();
|
||||
}
|
||||
|
||||
public void delete(Long id){
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Token t = em.find(Token.class, id);
|
||||
|
||||
if (t == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
em.remove(t);
|
||||
}
|
||||
|
||||
public void delete(Token token){
|
||||
if (token == null || token.getId() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete(token.getId());
|
||||
}
|
||||
|
||||
@Schedule(hour = "*", minute = "22")
|
||||
public void removeExspired() {
|
||||
LOGGER.info("Start to remove exspired tokens");
|
||||
this.em.createNamedQuery(Token.REMOVE_EXPIRED_TOKEN)
|
||||
.setParameter("timestamp", Instant.now())
|
||||
.executeUpdate();
|
||||
LOGGER.info("Finished removing exspired tokens");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package business.user;
|
||||
|
||||
import business.AbstractManager;
|
||||
import controller.person.PersonController;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import model.files.UserPicture;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Stateless
|
||||
public class UserPictureManager extends AbstractManager<UserPicture>{
|
||||
private UserPicture pic;
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
EntityManager em;
|
||||
|
||||
@Inject
|
||||
PersonController personController;
|
||||
|
||||
public UserPictureManager() {
|
||||
super(UserPicture.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
|
||||
public UserPicture getPic() {
|
||||
return pic;
|
||||
}
|
||||
|
||||
public void setPic(UserPicture pic) {
|
||||
this.pic = pic;
|
||||
}
|
||||
|
||||
public UserPicture findWithData(Long id){
|
||||
UserPicture pic = find(id);
|
||||
|
||||
if (pic == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int i = pic.getFileData().length;
|
||||
|
||||
return pic;
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package business.user;
|
||||
|
||||
import model.person.enums.UserGroup;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Hilfsmethoden für die hierarchische Rollenzuweisung bei Benutzern.
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
public class UserRoleAssignmentHelper {
|
||||
|
||||
/**
|
||||
* Erstellt ein Set von UserGroups basierend auf der Hauptrolle.
|
||||
* Implementiert hierarchische Rollenzuweisung:
|
||||
* - ADMIN: erhält USER, SUPERUSER, ADMIN
|
||||
* - SUPERUSER: erhält USER, SUPERUSER
|
||||
* - USER: erhält nur USER
|
||||
* - CUSTOMER: erhält nur CUSTOMER
|
||||
*
|
||||
* @param primaryRole Die Hauptrolle des Benutzers
|
||||
* @return Set mit allen zugewiesenen Rollen
|
||||
*/
|
||||
public static Set<UserGroup> assignRolesHierarchically(UserGroup primaryRole) {
|
||||
Set<UserGroup> roles = new HashSet<>();
|
||||
|
||||
switch (primaryRole) {
|
||||
case ADMIN:
|
||||
// Admin erhält alle Rollen: USER, SUPERUSER, ADMIN
|
||||
roles.add(UserGroup.USER);
|
||||
roles.add(UserGroup.SUPERUSER);
|
||||
roles.add(UserGroup.ADMIN);
|
||||
break;
|
||||
case SUPERUSER:
|
||||
// Superuser erhält USER und SUPERUSER Rollen
|
||||
roles.add(UserGroup.USER);
|
||||
roles.add(UserGroup.SUPERUSER);
|
||||
break;
|
||||
case USER:
|
||||
// User erhält nur USER Rolle
|
||||
roles.add(UserGroup.USER);
|
||||
break;
|
||||
case CUSTOMER:
|
||||
// Customer erhält nur CUSTOMER Rolle
|
||||
roles.add(UserGroup.CUSTOMER);
|
||||
break;
|
||||
default:
|
||||
// Fallback: Standard USER Rolle
|
||||
roles.add(UserGroup.USER);
|
||||
break;
|
||||
}
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt ein Set von UserGroups basierend auf der Hauptrolle als String.
|
||||
*
|
||||
* @param primaryRoleString Die Hauptrolle als String
|
||||
* @return Set mit allen zugewiesenen Rollen
|
||||
*/
|
||||
public static Set<UserGroup> assignRolesHierarchically(String primaryRoleString) {
|
||||
if (primaryRoleString == null || primaryRoleString.isEmpty()) {
|
||||
return assignRolesHierarchically(UserGroup.USER);
|
||||
}
|
||||
|
||||
try {
|
||||
UserGroup primaryRole = UserGroup.valueOf(primaryRoleString.toUpperCase());
|
||||
return assignRolesHierarchically(primaryRole);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Fallback bei ungültiger Rolle
|
||||
return assignRolesHierarchically(UserGroup.USER);
|
||||
}
|
||||
}
|
||||
}
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
package business.user;
|
||||
|
||||
import business.AbstractManager;
|
||||
import model.person.Person;
|
||||
import model.person.enums.UserGroup;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Singleton;
|
||||
import javax.ejb.Startup;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Startup-Service zur einmaligen Validierung und Korrektur von Benutzerrollen beim Anwendungsstart.
|
||||
* Überprüft alle bestehenden Benutzer in der Datenbank und korrigiert fehlerhafte Rollenzuweisungen.
|
||||
* Nach dem initialen Startup wird davon ausgegangen, dass neue Benutzer korrekt mit ihren Rollen erstellt werden.
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@Named
|
||||
@Singleton
|
||||
@Startup
|
||||
public class UserRoleValidationManager extends AbstractManager<Person> {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(UserRoleValidationManager.class);
|
||||
|
||||
@PersistenceContext(name = "pu_person")
|
||||
private EntityManager em;
|
||||
|
||||
public UserRoleValidationManager() {
|
||||
super(Person.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wird automatisch beim Anwendungsstart ausgeführt.
|
||||
* Validiert und korrigiert alle Benutzerrollen in der Datenbank.
|
||||
*/
|
||||
@PostConstruct
|
||||
@Transactional
|
||||
public void validateRolesOnStartup() {
|
||||
LOGGER.info("=== Anwendungsstart: Benutzerrollenvalidierung wird gestartet ===");
|
||||
|
||||
try {
|
||||
int correctedUsersCount = validateAndCorrectAllUserRoles();
|
||||
|
||||
if (correctedUsersCount > 0) {
|
||||
LOGGER.warn("Beim Anwendungsstart wurden {} Benutzer mit fehlerhaften Rollen korrigiert.", correctedUsersCount);
|
||||
} else {
|
||||
LOGGER.info("Alle Benutzerrollen sind korrekt. Keine Korrekturen erforderlich.");
|
||||
}
|
||||
|
||||
LOGGER.info("=== Benutzerrollenvalidierung beim Anwendungsstart abgeschlossen ===");
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Fehler bei der Benutzerrollenvalidierung beim Anwendungsstart: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Überprüft alle Benutzer in der Datenbank und korrigiert ihre Rollen falls nötig.
|
||||
* Diese Methode wird hauptsächlich beim Anwendungsstart verwendet.
|
||||
*
|
||||
* @return Anzahl der korrigierten Benutzer
|
||||
*/
|
||||
@Transactional
|
||||
public int validateAndCorrectAllUserRoles() {
|
||||
LOGGER.debug("Lade alle Benutzer für Rollenvalidierung...");
|
||||
|
||||
List<Person> allUsers = getAllUsers();
|
||||
int correctedUsersCount = 0;
|
||||
|
||||
LOGGER.info("Validiere Rollen für {} Benutzer...", allUsers.size());
|
||||
|
||||
for (Person user : allUsers) {
|
||||
if (validateAndCorrectUserRole(user)) {
|
||||
correctedUsersCount++;
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info("Benutzerrollenvalidierung abgeschlossen. {} Benutzer wurden korrigiert.", correctedUsersCount);
|
||||
return correctedUsersCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validiert und korrigiert die Rollen eines einzelnen Benutzers.
|
||||
*
|
||||
* @param user Der zu überprüfende Benutzer
|
||||
* @return true wenn Korrekturen vorgenommen wurden, false wenn keine nötig waren
|
||||
*/
|
||||
@Transactional
|
||||
public boolean validateAndCorrectUserRole(Person user) {
|
||||
if (user == null || user.getUserGroups() == null || user.getUserGroups().isEmpty()) {
|
||||
LOGGER.warn("Benutzer {} hat keine Rollen zugewiesen. Standard USER-Rolle wird vergeben.",
|
||||
user != null ? user.getEmail() : "null");
|
||||
|
||||
if (user != null) {
|
||||
Set<UserGroup> defaultRoles = UserRoleAssignmentHelper.assignRolesHierarchically(UserGroup.USER);
|
||||
user.setUserGroups(defaultRoles);
|
||||
em.merge(user);
|
||||
LOGGER.info("Standard USER-Rolle für Benutzer {} vergeben.", user.getEmail());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Bestimme die höchste Rolle des Benutzers
|
||||
UserGroup highestRole = determineHighestRole(user.getUserGroups());
|
||||
|
||||
// Erstelle das korrekte Rollenset basierend auf der höchsten Rolle
|
||||
Set<UserGroup> correctRoles = UserRoleAssignmentHelper.assignRolesHierarchically(highestRole);
|
||||
|
||||
// Vergleiche aktuelle Rollen mit korrekten Rollen
|
||||
if (!user.getUserGroups().equals(correctRoles)) {
|
||||
LOGGER.info("Korrigiere Rollen für Benutzer {}. Alte Rollen: {}, Neue Rollen: {}",
|
||||
user.getEmail(), user.getUserGroups(), correctRoles);
|
||||
|
||||
user.setUserGroups(correctRoles);
|
||||
em.merge(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bestimmt die höchste Rolle aus einem Set von UserGroups.
|
||||
* Hierarchie: ADMIN > SUPERUSER > USER > CUSTOMER
|
||||
*
|
||||
* @param userGroups Set der Benutzerrollen
|
||||
* @return Die höchste gefundene Rolle
|
||||
*/
|
||||
private UserGroup determineHighestRole(Set<UserGroup> userGroups) {
|
||||
if (userGroups.contains(UserGroup.ADMIN)) {
|
||||
return UserGroup.ADMIN;
|
||||
} else if (userGroups.contains(UserGroup.SUPERUSER)) {
|
||||
return UserGroup.SUPERUSER;
|
||||
} else if (userGroups.contains(UserGroup.USER)) {
|
||||
return UserGroup.USER;
|
||||
} else if (userGroups.contains(UserGroup.CUSTOMER)) {
|
||||
return UserGroup.CUSTOMER;
|
||||
} else {
|
||||
// Fallback: USER als Standardrolle
|
||||
return UserGroup.USER;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt alle Benutzer aus der Datenbank.
|
||||
*
|
||||
* @return Liste aller Benutzer
|
||||
*/
|
||||
private List<Person> getAllUsers() {
|
||||
TypedQuery<Person> query = em.createQuery("SELECT p FROM Person p", Person.class);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Findet alle Benutzer ohne korrekte Rollenzuweisung.
|
||||
*
|
||||
* @return Liste der Benutzer mit fehlerhaften Rollen
|
||||
*/
|
||||
public List<Person> findUsersWithIncorrectRoles() {
|
||||
List<Person> allUsers = getAllUsers();
|
||||
return allUsers.stream()
|
||||
.filter(user -> {
|
||||
if (user.getUserGroups() == null || user.getUserGroups().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
UserGroup highestRole = determineHighestRole(user.getUserGroups());
|
||||
Set<UserGroup> correctRoles = UserRoleAssignmentHelper.assignRolesHierarchically(highestRole);
|
||||
return !user.getUserGroups().equals(correctRoles);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager getEntityManager() {
|
||||
return em;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,381 @@
|
||||
package controller;
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import business.AbstractManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.itextpdf.io.font.constants.StandardFonts;
|
||||
import com.itextpdf.io.image.ImageData;
|
||||
import com.itextpdf.io.image.ImageDataFactory;
|
||||
import com.itextpdf.kernel.colors.ColorConstants;
|
||||
import com.itextpdf.kernel.font.PdfFontFactory;
|
||||
import com.itextpdf.layout.Document;
|
||||
import com.itextpdf.layout.borders.Border;
|
||||
import com.itextpdf.layout.element.*;
|
||||
import com.itextpdf.layout.properties.TextAlignment;
|
||||
import com.itextpdf.layout.properties.VerticalAlignment;
|
||||
import model.AbstractEntity;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bouncycastle.util.test.Test;
|
||||
import org.primefaces.PrimeFaces;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
* @param <ENT>
|
||||
*/
|
||||
public abstract class AbstractController<ENT extends AbstractEntity> implements Serializable {
|
||||
|
||||
protected final Logger LOGGER = LogManager.getLogger(this.getClass());
|
||||
|
||||
public final static String SUCCESS_TITLE = "Erfolg!";
|
||||
public final static String SUCCESS_MESSAGE = "Aktion wurde erfolgreich ausgeführt";
|
||||
public final static String ERROR_TITLE = "Fehler!";
|
||||
public final static String ERROR_MESSAGE = "Es ist ein Fehler aufgetreten, bitte versuchen Sie es erneut!";
|
||||
|
||||
public final static String LOGO_PATH = "/rundata/logo.png";
|
||||
|
||||
protected final String FONT_BOLD = StandardFonts.HELVETICA_BOLD;
|
||||
protected final String FONT_NORMAL = StandardFonts.HELVETICA;
|
||||
|
||||
private ENT selected;
|
||||
private ENT created;
|
||||
private List<ENT> entities;
|
||||
|
||||
private static final long serialVersionUID = -5908716187853409719L;
|
||||
|
||||
public AbstractController() {
|
||||
entities = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void refrehSelected(){
|
||||
if (selected == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
selected = getManager().refresh(selected);
|
||||
}
|
||||
|
||||
protected abstract AbstractManager<ENT> getManager();
|
||||
|
||||
protected void sendInfoMessage(String title, String message) {
|
||||
FacesMessage facesMessage = new FacesMessage(
|
||||
FacesMessage.SEVERITY_INFO, title, message);
|
||||
addMessage(facesMessage);
|
||||
}
|
||||
|
||||
protected void sendWarnMessage(String title, String message) {
|
||||
FacesMessage facesMessage = new FacesMessage(
|
||||
FacesMessage.SEVERITY_WARN, title, message);
|
||||
addMessage(facesMessage);
|
||||
}
|
||||
|
||||
protected void sendErrorMessage(String title, String message) {
|
||||
FacesMessage facesMessage = new FacesMessage(
|
||||
FacesMessage.SEVERITY_ERROR, title, message);
|
||||
addMessage(facesMessage);
|
||||
}
|
||||
|
||||
protected void sendFatalMessage(String title, String message) {
|
||||
FacesMessage facesMessage = new FacesMessage(
|
||||
FacesMessage.SEVERITY_FATAL, title, message);
|
||||
addMessage(facesMessage);
|
||||
}
|
||||
|
||||
private void addMessage(FacesMessage message) {
|
||||
FacesContext.getCurrentInstance().addMessage(null, message);
|
||||
}
|
||||
|
||||
protected void errorMessage() {
|
||||
sendErrorMessage(ERROR_TITLE, ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
protected void successMessage() {
|
||||
sendInfoMessage(SUCCESS_TITLE, SUCCESS_MESSAGE);
|
||||
}
|
||||
|
||||
protected void closeDialogs(String... widgets){
|
||||
PrimeFaces current = PrimeFaces.current();
|
||||
for(String widget : widgets){
|
||||
current.executeScript("PF('"+ widget + "').hide()");
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void clearEntries();
|
||||
|
||||
protected Long createFakeID(Collection<ENT> col){
|
||||
Long out = -1L;
|
||||
|
||||
if (col == null) {
|
||||
return out;
|
||||
}
|
||||
|
||||
if (col.isEmpty()) {
|
||||
return out;
|
||||
}
|
||||
|
||||
Optional<ENT> min = col.stream().min((l1, l2) -> Long.compare(l1.getId(), l2.getId()));
|
||||
|
||||
if (min.isEmpty() || min.get().getId() > 0L) {
|
||||
return out;
|
||||
}
|
||||
|
||||
out = min.get().getId() - 1L;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
protected Image loadCompanyLogo() {
|
||||
ImageData data;
|
||||
try {
|
||||
data = ImageDataFactory.create(LOGO_PATH);
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Image(data);
|
||||
}
|
||||
|
||||
protected Table generateSorroundingTable(String header, float maxWidth) throws IOException {
|
||||
// Creating a table
|
||||
float[] pointColumnWidths = {maxWidth};
|
||||
Table table = new Table(pointColumnWidths, true);
|
||||
if (header == null || header.isEmpty()) {
|
||||
return table;
|
||||
}
|
||||
|
||||
Text text = new Text(header);
|
||||
text.setFont(PdfFontFactory.createFont(FONT_BOLD));
|
||||
text.setFontSize(12F);
|
||||
Paragraph p = new Paragraph(text);
|
||||
|
||||
table.addHeaderCell(new Cell().add(p).setBorderBottom(Border.NO_BORDER));
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
protected Cell generateInnerTable(Text header, boolean last, String... values) throws IOException {
|
||||
Cell cell = new Cell();
|
||||
cell.setBorderTop(Border.NO_BORDER);
|
||||
if (!last) {
|
||||
cell.setBorderBottom(Border.NO_BORDER);
|
||||
}
|
||||
|
||||
float[] pointColumnWidths = {270F, 270F};
|
||||
Table table = new Table(pointColumnWidths);
|
||||
|
||||
header.setFont(PdfFontFactory.createFont(FONT_NORMAL));
|
||||
header.setFontSize(11F);
|
||||
Paragraph p = new Paragraph(header);
|
||||
table.addHeaderCell(new Cell().add(p).setBorder(Border.NO_BORDER));
|
||||
table.addHeaderCell(new Cell().setBorder(Border.NO_BORDER));
|
||||
|
||||
table.setBorder(Border.NO_BORDER);
|
||||
|
||||
boolean isGray = true;
|
||||
|
||||
for (int i = 0; i + 1 < values.length; i = i + 2) {
|
||||
if (values[i] == null || values[i].isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
addInnerCells(table, values[i], values[i + 1], isGray);
|
||||
isGray = !isGray;
|
||||
}
|
||||
|
||||
cell.add(table);
|
||||
return cell;
|
||||
}
|
||||
|
||||
protected Cell generateInnerTable(Text header, int nrColumns, boolean last, String... values) throws IOException {
|
||||
Cell outputCell = new Cell();
|
||||
outputCell.setBorderTop(Border.NO_BORDER);
|
||||
if (!last) {
|
||||
outputCell.setBorderBottom(Border.NO_BORDER);
|
||||
}
|
||||
|
||||
// calculate column widths
|
||||
float[] pointColumnWidths = new float[nrColumns];
|
||||
Arrays.fill(pointColumnWidths, 540F / nrColumns);
|
||||
|
||||
Table table = new Table(pointColumnWidths);
|
||||
|
||||
header.setFont(PdfFontFactory.createFont(FONT_NORMAL));
|
||||
header.setFontSize(11F);
|
||||
Paragraph p = new Paragraph(header);
|
||||
table.addHeaderCell(new Cell().add(p).setBorder(Border.NO_BORDER));
|
||||
for (int i = 0; i < nrColumns - 1; i++) {
|
||||
table.addHeaderCell(new Cell().setBorder(Border.NO_BORDER));
|
||||
}
|
||||
|
||||
if (values.length < nrColumns) {
|
||||
return outputCell;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nrColumns; i++) {
|
||||
Text headerText = new Text(values[i]);
|
||||
Cell cell1 = new Cell();
|
||||
cell1.setBorder(Border.NO_BORDER);
|
||||
headerText.setFont(PdfFontFactory.createFont(FONT_BOLD));
|
||||
headerText.setFontSize(11F);
|
||||
Paragraph p1 = new Paragraph(headerText);
|
||||
cell1.add(p1);
|
||||
table.addHeaderCell(cell1);
|
||||
}
|
||||
|
||||
table.setBorder(Border.NO_BORDER);
|
||||
|
||||
boolean isGray = true;
|
||||
|
||||
// add inner cells for n columns
|
||||
for (int i = nrColumns; i + nrColumns <= values.length; i = i + nrColumns) {
|
||||
String[] strings = new String[nrColumns - 1];
|
||||
System.arraycopy(values, i + 1, strings, 0, nrColumns - 1);
|
||||
addInnerCells(table, values[i], isGray, strings);
|
||||
isGray = !isGray;
|
||||
}
|
||||
|
||||
outputCell.add(table);
|
||||
return outputCell;
|
||||
}
|
||||
|
||||
protected void addInnerCells(Table table, String name, String value, boolean isGray) throws IOException {
|
||||
if (table == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Cell cell1 = new Cell();
|
||||
cell1.setBorder(Border.NO_BORDER);
|
||||
Text t1 = new Text(name != null ? name : " ");
|
||||
t1.setFont(PdfFontFactory.createFont(FONT_NORMAL));
|
||||
t1.setFontSize(8F);
|
||||
Paragraph p1 = new Paragraph(t1);
|
||||
p1.setMultipliedLeading(1F);
|
||||
cell1.add(p1);
|
||||
|
||||
Cell cell2 = new Cell();
|
||||
cell2.setBorder(Border.NO_BORDER);
|
||||
Text t2 = new Text(value != null ? value : "-/-");
|
||||
t2.setFont(PdfFontFactory.createFont(FONT_NORMAL));
|
||||
t2.setFontSize(8F);
|
||||
Paragraph p2 = new Paragraph(t2);
|
||||
p2.setMultipliedLeading(1F);
|
||||
cell2.add(p2);
|
||||
|
||||
if (isGray) {
|
||||
cell1.setBackgroundColor(ColorConstants.LIGHT_GRAY, 0.248F);
|
||||
cell2.setBackgroundColor(ColorConstants.LIGHT_GRAY, 0.248F);
|
||||
}
|
||||
|
||||
table.addCell(cell1);
|
||||
table.addCell(cell2);
|
||||
}
|
||||
|
||||
protected void addInnerCells(Table table, String name, boolean isGray, String... values) throws IOException {
|
||||
if (table == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Cell cell1 = new Cell();
|
||||
cell1.setBorder(Border.NO_BORDER);
|
||||
Text t1 = new Text(name != null ? name : " ");
|
||||
t1.setFont(PdfFontFactory.createFont(FONT_NORMAL));
|
||||
t1.setFontSize(8F);
|
||||
Paragraph p1 = new Paragraph(t1);
|
||||
p1.setMultipliedLeading(1F);
|
||||
cell1.add(p1);
|
||||
if (isGray) {
|
||||
cell1.setBackgroundColor(ColorConstants.LIGHT_GRAY, 0.248F);
|
||||
}
|
||||
table.addCell(cell1);
|
||||
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
Cell cell = new Cell();
|
||||
cell.setBorder(Border.NO_BORDER);
|
||||
Text t2 = new Text(values[i] != null ? values[i] : "-/-");
|
||||
t2.setFont(PdfFontFactory.createFont(FONT_NORMAL));
|
||||
t2.setFontSize(8F);
|
||||
Paragraph p2 = new Paragraph(t2);
|
||||
p2.setMultipliedLeading(1F);
|
||||
cell.add(p2);
|
||||
|
||||
if (isGray) {
|
||||
cell.setBackgroundColor(ColorConstants.LIGHT_GRAY, 0.248F);
|
||||
}
|
||||
|
||||
table.addCell(cell);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addPagenumbers(Document document, String ticketNr, Image nextPagesCompanyLogo) throws Exception {
|
||||
int numberOfPages = document.getPdfDocument().getNumberOfPages();
|
||||
LOGGER.info("Found pages {}", numberOfPages);
|
||||
nextPagesCompanyLogo.scale(0.09F, 0.09F);
|
||||
|
||||
for (int i = 1; i <= numberOfPages; i++) {
|
||||
// Write aligned text to the specified by parameters point
|
||||
Text text = new Text(String.format("%s - Seite %s/%s", ticketNr, i, numberOfPages));
|
||||
text.setFont(PdfFontFactory.createFont(FONT_NORMAL));
|
||||
text.setFontSize(8F);
|
||||
Paragraph p = new Paragraph(text);
|
||||
|
||||
if (i > 1) {
|
||||
nextPagesCompanyLogo.setFixedPosition(i, 394F, 796F);
|
||||
document.add(nextPagesCompanyLogo);
|
||||
}
|
||||
|
||||
document.showTextAligned(p,
|
||||
559, 30, i, TextAlignment.RIGHT, VerticalAlignment.TOP, 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected HttpServletRequest getRequest(FacesContext context) {
|
||||
return (HttpServletRequest) context.getExternalContext().getRequest();
|
||||
}
|
||||
|
||||
protected HttpServletResponse getResponse(FacesContext context) {
|
||||
return (HttpServletResponse) context.getExternalContext().getResponse();
|
||||
}
|
||||
|
||||
public ENT getSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void setSelected(ENT selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
public ENT getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(ENT created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public List<ENT> getEntities() {
|
||||
return entities;
|
||||
}
|
||||
|
||||
public void setEntities(List<ENT> entities) {
|
||||
this.entities = entities;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Named;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@RequestScoped
|
||||
public class TimeController {
|
||||
|
||||
private static final DateTimeFormatter GERMAN_DATE_FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||
private static final DateTimeFormatter GERMAN_DATETIME_FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss");
|
||||
|
||||
public String germanDateString(LocalDate localDate) {
|
||||
if (localDate == null) {
|
||||
return "";
|
||||
}
|
||||
return localDate.format(GERMAN_DATE_FORMATTER);
|
||||
}
|
||||
|
||||
public String germanDateString(LocalDateTime localDateTime) {
|
||||
if (localDateTime == null) {
|
||||
return "";
|
||||
}
|
||||
return localDateTime.format(GERMAN_DATETIME_FORMATTER);
|
||||
}
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
package controller.admin;
|
||||
|
||||
import business.user.PasswordManager;
|
||||
import business.user.PersonManager;
|
||||
import controller.AbstractController;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Named;
|
||||
import model.person.Person;
|
||||
|
||||
/**
|
||||
* Controller für das Admin-Passwort-Reset-Interface.
|
||||
* Ermöglicht Administratoren das Zurücksetzen von Benutzerpasswörtern
|
||||
* und das Setzen neuer Passwörter für alle Benutzer im System.
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class AdminPasswordResetController extends AbstractController<Person> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* E-Mail-Adresse des Benutzers, dessen Passwort zurückgesetzt werden soll.
|
||||
*/
|
||||
private String userEmail;
|
||||
|
||||
/**
|
||||
* Neues Passwort, das für den ausgewählten Benutzer gesetzt werden soll.
|
||||
*/
|
||||
private String newPassword;
|
||||
|
||||
/**
|
||||
* Bestätigung des neuen Passworts zur Vermeidung von Tippfehlern.
|
||||
*/
|
||||
private String confirmPassword;
|
||||
|
||||
/**
|
||||
* Der ausgewählte Benutzer, dessen Passwort zurückgesetzt wird.
|
||||
*/
|
||||
private Person selectedUser;
|
||||
|
||||
/**
|
||||
* Liste aller verfügbaren Benutzer für die Auswahl.
|
||||
*/
|
||||
private List<Person> allUsers;
|
||||
|
||||
@EJB
|
||||
private PersonManager personManager;
|
||||
|
||||
@EJB
|
||||
private PasswordManager passwordManager;
|
||||
|
||||
/**
|
||||
* Sucht einen Benutzer anhand der E-Mail-Adresse.
|
||||
* Lädt den Benutzer und bereitet ihn für das Passwort-Reset vor.
|
||||
*/
|
||||
public void searchUser() {
|
||||
if (userEmail == null || userEmail.trim().isEmpty()) {
|
||||
sendErrorMessage("Fehler", "Bitte geben Sie eine E-Mail-Adresse ein.");
|
||||
selectedUser = null;
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<Person> user = personManager.getByEmail(userEmail.trim());
|
||||
if (user.isEmpty()) {
|
||||
sendErrorMessage("Fehler", "Kein Benutzer mit der E-Mail-Adresse '" + userEmail + "' gefunden.");
|
||||
selectedUser = null;
|
||||
return;
|
||||
}
|
||||
|
||||
selectedUser = user.get();
|
||||
sendInfoMessage("Erfolg", "Benutzer '" + selectedUser.getFirstname() + " " +
|
||||
selectedUser.getLastname() + "' gefunden.");
|
||||
|
||||
// Passwort-Felder zurücksetzen
|
||||
newPassword = null;
|
||||
confirmPassword = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt das Passwort für den ausgewählten Benutzer zurück.
|
||||
* Validiert die Eingaben und aktualisiert das Passwort in der Datenbank.
|
||||
*/
|
||||
public void resetPassword() {
|
||||
if (selectedUser == null) {
|
||||
sendErrorMessage("Fehler", "Bitte wählen Sie zuerst einen Benutzer aus.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPassword == null || newPassword.trim().isEmpty()) {
|
||||
sendErrorMessage("Fehler", "Bitte geben Sie ein neues Passwort ein.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPassword.length() < 6) {
|
||||
sendErrorMessage("Fehler", "Das Passwort muss mindestens 6 Zeichen lang sein.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!newPassword.equals(confirmPassword)) {
|
||||
sendErrorMessage("Fehler", "Die Passwort-Bestätigung stimmt nicht überein.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Passwort über den PasswordManager zurücksetzen
|
||||
boolean success = passwordManager.resetPassword(selectedUser, newPassword);
|
||||
|
||||
if (success) {
|
||||
sendInfoMessage("Erfolg", "Passwort für Benutzer '" + selectedUser.getEmail() +
|
||||
"' wurde erfolgreich zurückgesetzt.");
|
||||
|
||||
// Eingaben zurücksetzen
|
||||
clearEntries();
|
||||
} else {
|
||||
sendErrorMessage("Fehler", "Fehler beim Zurücksetzen des Passworts. Bitte versuchen Sie es erneut.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Fehler beim Zurücksetzen des Passworts für Benutzer: " + selectedUser.getEmail(), e);
|
||||
sendErrorMessage("Fehler", "Ein unerwarteter Fehler ist aufgetreten. Bitte versuchen Sie es erneut.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt alle Benutzer für die Dropdown-Auswahl.
|
||||
* @return Liste aller Benutzer im System
|
||||
*/
|
||||
public List<Person> getAllUsers() {
|
||||
if (allUsers == null) {
|
||||
allUsers = personManager.findAll();
|
||||
}
|
||||
return allUsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt das Passwort direkt für einen aus der Liste ausgewählten Benutzer.
|
||||
*/
|
||||
public void setPasswordForSelectedUser() {
|
||||
if (selectedUser == null) {
|
||||
sendErrorMessage("Fehler", "Bitte wählen Sie einen Benutzer aus der Liste aus.");
|
||||
return;
|
||||
}
|
||||
|
||||
// E-Mail-Feld mit der Auswahl synchronisieren
|
||||
userEmail = selectedUser.getEmail();
|
||||
|
||||
// Passwort-Felder zurücksetzen
|
||||
newPassword = null;
|
||||
confirmPassword = null;
|
||||
|
||||
sendInfoMessage("Info", "Benutzer '" + selectedUser.getFirstname() + " " +
|
||||
selectedUser.getLastname() + "' ausgewählt.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
userEmail = null;
|
||||
newPassword = null;
|
||||
confirmPassword = null;
|
||||
selectedUser = null;
|
||||
allUsers = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PersonManager getManager() {
|
||||
return personManager;
|
||||
}
|
||||
|
||||
// Getter und Setter
|
||||
public String getUserEmail() {
|
||||
return userEmail;
|
||||
}
|
||||
|
||||
public void setUserEmail(String userEmail) {
|
||||
this.userEmail = userEmail;
|
||||
}
|
||||
|
||||
public String getNewPassword() {
|
||||
return newPassword;
|
||||
}
|
||||
|
||||
public void setNewPassword(String newPassword) {
|
||||
this.newPassword = newPassword;
|
||||
}
|
||||
|
||||
public String getConfirmPassword() {
|
||||
return confirmPassword;
|
||||
}
|
||||
|
||||
public void setConfirmPassword(String confirmPassword) {
|
||||
this.confirmPassword = confirmPassword;
|
||||
}
|
||||
|
||||
public Person getSelectedUser() {
|
||||
return selectedUser;
|
||||
}
|
||||
|
||||
public void setSelectedUser(Person selectedUser) {
|
||||
this.selectedUser = selectedUser;
|
||||
}
|
||||
|
||||
public void setAllUsers(List<Person> allUsers) {
|
||||
this.allUsers = allUsers;
|
||||
}
|
||||
}
|
||||
+349
@@ -0,0 +1,349 @@
|
||||
package controller.admin;
|
||||
|
||||
import business.user.PersonManager;
|
||||
import controller.AbstractController;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Named;
|
||||
import model.person.Person;
|
||||
import model.person.enums.UserGroup;
|
||||
|
||||
/**
|
||||
* Controller für das Admin-Interface zum Sperren und Löschen von Benutzern.
|
||||
* Ermöglicht Administratoren das Verwalten von Benutzerkonten durch:
|
||||
* - Sperren/Entsperren von Benutzern (active/inactive setzen)
|
||||
* - Vollständiges Löschen von Benutzerkonten
|
||||
* - Suche und Anzeige von Benutzerdaten
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class AdminUserManagementController extends AbstractController<Person> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* E-Mail-Adresse des zu verwaltenden Benutzers.
|
||||
*/
|
||||
private String userEmail;
|
||||
|
||||
/**
|
||||
* Der ausgewählte Benutzer für Verwaltungsaktionen.
|
||||
*/
|
||||
private Person selectedUser;
|
||||
|
||||
/**
|
||||
* Liste aller verfügbaren Benutzer für die Auswahl.
|
||||
*/
|
||||
private List<Person> allUsers;
|
||||
|
||||
/**
|
||||
* Bestätigungstext für Löschaktionen.
|
||||
*/
|
||||
private String confirmationText;
|
||||
|
||||
@EJB
|
||||
private PersonManager personManager;
|
||||
|
||||
/**
|
||||
* Sucht einen Benutzer anhand der E-Mail-Adresse.
|
||||
* Lädt den Benutzer und bereitet ihn für Verwaltungsaktionen vor.
|
||||
*/
|
||||
public void searchUser() {
|
||||
if (userEmail == null || userEmail.trim().isEmpty()) {
|
||||
sendErrorMessage("Fehler", "Bitte geben Sie eine E-Mail-Adresse ein.");
|
||||
selectedUser = null;
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<Person> user = personManager.getByEmail(userEmail.trim());
|
||||
if (user.isEmpty()) {
|
||||
sendErrorMessage("Fehler", "Kein Benutzer mit der E-Mail-Adresse '" + userEmail + "' gefunden.");
|
||||
selectedUser = null;
|
||||
return;
|
||||
}
|
||||
|
||||
selectedUser = user.get();
|
||||
sendInfoMessage("Erfolg", "Benutzer '" + selectedUser.getFirstname() + " " +
|
||||
selectedUser.getLastname() + "' gefunden.");
|
||||
|
||||
// Bestätigungstext zurücksetzen
|
||||
confirmationText = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sperrt einen Benutzer (setzt active = false).
|
||||
* Der Benutzer kann sich nicht mehr am System anmelden.
|
||||
*/
|
||||
public void blockUser() {
|
||||
if (selectedUser == null) {
|
||||
sendErrorMessage("Fehler", "Bitte wählen Sie zuerst einen Benutzer aus.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!selectedUser.isActive()) {
|
||||
sendWarnMessage("Hinweis", "Benutzer '" + selectedUser.getEmail() + "' ist bereits gesperrt.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
selectedUser.setActive(false);
|
||||
personManager.save(selectedUser);
|
||||
|
||||
sendInfoMessage("Erfolg", "Benutzer '" + selectedUser.getEmail() +
|
||||
"' wurde erfolgreich gesperrt. Der Benutzer kann sich nicht mehr anmelden.");
|
||||
|
||||
LOGGER.info("Admin blocked user: " + selectedUser.getEmail());
|
||||
|
||||
// Benutzer neu laden um LazyInitializationException zu vermeiden
|
||||
refreshSelectedUser();
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Fehler beim Sperren des Benutzers: " + selectedUser.getEmail(), e);
|
||||
sendErrorMessage("Fehler", "Ein Fehler ist beim Sperren des Benutzers aufgetreten.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entsperrt einen Benutzer (setzt active = true).
|
||||
* Der Benutzer kann sich wieder am System anmelden.
|
||||
*/
|
||||
public void unblockUser() {
|
||||
if (selectedUser == null) {
|
||||
sendErrorMessage("Fehler", "Bitte wählen Sie zuerst einen Benutzer aus.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedUser.isActive()) {
|
||||
sendWarnMessage("Hinweis", "Benutzer '" + selectedUser.getEmail() + "' ist bereits aktiv.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
selectedUser.setActive(true);
|
||||
personManager.save(selectedUser);
|
||||
|
||||
sendInfoMessage("Erfolg", "Benutzer '" + selectedUser.getEmail() +
|
||||
"' wurde erfolgreich entsperrt. Der Benutzer kann sich wieder anmelden.");
|
||||
|
||||
LOGGER.info("Admin unblocked user: " + selectedUser.getEmail());
|
||||
|
||||
// Benutzer neu laden um LazyInitializationException zu vermeiden
|
||||
refreshSelectedUser();
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Fehler beim Entsperren des Benutzers: " + selectedUser.getEmail(), e);
|
||||
sendErrorMessage("Fehler", "Ein Fehler ist beim Entsperren des Benutzers aufgetreten.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deaktiviert einen Benutzer permanent (setzt active = false).
|
||||
* Dies ist sicherer als das vollständige Löschen, da Referenzen erhalten bleiben.
|
||||
* ACHTUNG: Diese Aktion sollte nur in Ausnahmefällen verwendet werden!
|
||||
*/
|
||||
public void deleteUser() {
|
||||
if (selectedUser == null) {
|
||||
sendErrorMessage("Fehler", "Bitte wählen Sie zuerst einen Benutzer aus.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Sicherheitscheck: Bestätigungstext muss exakt der E-Mail entsprechen
|
||||
if (confirmationText == null || !confirmationText.equals(selectedUser.getEmail())) {
|
||||
sendErrorMessage("Fehler", "Zur Bestätigung der Deaktivierung müssen Sie die E-Mail-Adresse '" +
|
||||
selectedUser.getEmail() + "' genau eingeben.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String deletedEmail = selectedUser.getEmail();
|
||||
String deletedName = selectedUser.getFirstname() + " " + selectedUser.getLastname();
|
||||
|
||||
// Benutzer permanent deaktivieren (sicherer als löschen)
|
||||
selectedUser.setActive(false);
|
||||
personManager.save(selectedUser);
|
||||
|
||||
sendInfoMessage("Erfolg", "Benutzer '" + deletedName + "' (" + deletedEmail +
|
||||
") wurde permanent deaktiviert. Der Benutzer kann sich nicht mehr anmelden.");
|
||||
|
||||
LOGGER.warn("Admin permanently deactivated user: " + deletedEmail + " (" + deletedName + ")");
|
||||
|
||||
// Eingaben zurücksetzen
|
||||
clearEntries();
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Fehler beim Deaktivieren des Benutzers: " + selectedUser.getEmail(), e);
|
||||
sendErrorMessage("Fehler", "Ein Fehler ist beim Deaktivieren des Benutzers aufgetreten.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt einen Benutzer aus der Liste für Verwaltungsaktionen.
|
||||
*/
|
||||
public void setUserFromList() {
|
||||
if (selectedUser == null) {
|
||||
sendErrorMessage("Fehler", "Bitte wählen Sie einen Benutzer aus der Liste aus.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Benutzer mit load() neu laden um userGroups korrekt zu initialisieren
|
||||
selectedUser = personManager.load(selectedUser);
|
||||
|
||||
if (selectedUser == null) {
|
||||
sendErrorMessage("Fehler", "Benutzer konnte nicht geladen werden.");
|
||||
return;
|
||||
}
|
||||
|
||||
// E-Mail-Feld mit der Auswahl synchronisieren
|
||||
userEmail = selectedUser.getEmail();
|
||||
|
||||
// Bestätigungstext zurücksetzen
|
||||
confirmationText = null;
|
||||
|
||||
sendInfoMessage("Info", "Benutzer '" + selectedUser.getFirstname() + " " +
|
||||
selectedUser.getLastname() + "' für Verwaltung ausgewählt.");
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Fehler beim Laden des ausgewählten Benutzers: " + (selectedUser != null ? selectedUser.getEmail() : "null"), e);
|
||||
sendErrorMessage("Fehler", "Fehler beim Laden der Benutzerdaten.");
|
||||
selectedUser = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt eine sichere String-Darstellung der Benutzergruppen zurück.
|
||||
* Verhindert LazyInitializationException durch sichere Behandlung der Collection.
|
||||
* @param user Der Benutzer
|
||||
* @return Komma-getrennte Liste der Benutzergruppen oder "Nicht verfügbar"
|
||||
*/
|
||||
public String getUserGroupsAsString(Person user) {
|
||||
if (user == null) {
|
||||
return "Nicht verfügbar";
|
||||
}
|
||||
|
||||
try {
|
||||
Set<UserGroup> groups = user.getUserGroups();
|
||||
|
||||
// Prüfe auf null ohne isEmpty() zu verwenden (vermeidet Lazy Loading)
|
||||
if (groups == null) {
|
||||
return "Keine Gruppen";
|
||||
}
|
||||
|
||||
// Verwende Iterator um Lazy Loading zu vermeiden
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
|
||||
for (UserGroup group : groups) {
|
||||
if (!first) {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append(group.toString());
|
||||
first = false;
|
||||
}
|
||||
|
||||
// Falls keine Gruppen durchlaufen wurden
|
||||
if (first) {
|
||||
return "Keine Gruppen";
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
||||
} catch (Exception e) {
|
||||
// Logge nur als DEBUG statt WARN um Log-Spam zu reduzieren
|
||||
LOGGER.debug("Could not load user groups for user: " + user.getEmail(), e);
|
||||
return "Nicht verfügbar";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt einen Benutzer mit allen Beziehungen neu aus der Datenbank.
|
||||
* Stellt sicher, dass lazy-loaded Collections verfügbar sind.
|
||||
*/
|
||||
private void refreshSelectedUser() {
|
||||
if (selectedUser != null) {
|
||||
try {
|
||||
// Benutzer mit allen Beziehungen neu laden
|
||||
selectedUser = personManager.load(selectedUser);
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Could not refresh selected user: " + selectedUser.getEmail(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt alle Benutzer für die Dropdown-Auswahl.
|
||||
* @return Liste aller Benutzer im System
|
||||
*/
|
||||
public List<Person> getAllUsers() {
|
||||
if (allUsers == null) {
|
||||
allUsers = personManager.findAll();
|
||||
}
|
||||
return allUsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Status-Text für einen Benutzer zurück.
|
||||
* @param user Der Benutzer
|
||||
* @return "Aktiv" oder "Gesperrt"
|
||||
*/
|
||||
public String getUserStatus(Person user) {
|
||||
return user != null && user.isActive() ? "Aktiv" : "Gesperrt";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die CSS-Klasse für den Status zurück.
|
||||
* @param user Der Benutzer
|
||||
* @return CSS-Klasse für Styling
|
||||
*/
|
||||
public String getUserStatusClass(Person user) {
|
||||
return user != null && user.isActive() ? "ui-button-success" : "ui-button-danger";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
userEmail = null;
|
||||
selectedUser = null;
|
||||
allUsers = null;
|
||||
confirmationText = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PersonManager getManager() {
|
||||
return personManager;
|
||||
}
|
||||
|
||||
// Getter und Setter
|
||||
public String getUserEmail() {
|
||||
return userEmail;
|
||||
}
|
||||
|
||||
public void setUserEmail(String userEmail) {
|
||||
this.userEmail = userEmail;
|
||||
}
|
||||
|
||||
public Person getSelectedUser() {
|
||||
return selectedUser;
|
||||
}
|
||||
|
||||
public void setSelectedUser(Person selectedUser) {
|
||||
this.selectedUser = selectedUser;
|
||||
}
|
||||
|
||||
public void setAllUsers(List<Person> allUsers) {
|
||||
this.allUsers = allUsers;
|
||||
}
|
||||
|
||||
public String getConfirmationText() {
|
||||
return confirmationText;
|
||||
}
|
||||
|
||||
public void setConfirmationText(String confirmationText) {
|
||||
this.confirmationText = confirmationText;
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
package controller.admin;
|
||||
|
||||
import business.user.PasswordManager;
|
||||
import business.user.PersonManager;
|
||||
import business.user.UserRoleAssignmentHelper;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Named;
|
||||
import model.person.Person;
|
||||
import model.person.Preferences;
|
||||
import model.person.Salt;
|
||||
import model.person.Password;
|
||||
import model.person.enums.UserGroup;
|
||||
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class CreateUserController implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Person user = new Person();
|
||||
private String password;
|
||||
private String selectedGroup; // "USER" or "ADMIN"
|
||||
|
||||
@EJB
|
||||
private PersonManager personManager;
|
||||
|
||||
@EJB
|
||||
private PasswordManager passwordManager;
|
||||
|
||||
public Person getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(Person user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getSelectedGroup() {
|
||||
return selectedGroup;
|
||||
}
|
||||
|
||||
public void setSelectedGroup(String selectedGroup) {
|
||||
this.selectedGroup = selectedGroup;
|
||||
}
|
||||
|
||||
public void createUser() {
|
||||
Salt salt = new Salt();
|
||||
byte[] hashedPassword = passwordManager.hashPassword(
|
||||
password.toCharArray(),
|
||||
salt.getSalt(),
|
||||
salt.getInterations()
|
||||
);
|
||||
|
||||
// Verwende hierarchische Rollenzuweisung über Helper
|
||||
Set<UserGroup> groups = UserRoleAssignmentHelper.assignRolesHierarchically(selectedGroup);
|
||||
|
||||
// Erstelle einen neuen Benutzer mit dem korrekten Konstruktor
|
||||
Person newUser = new Person(user.getEmail(), hashedPassword, salt, groups);
|
||||
|
||||
// Übertrage die anderen Eigenschaften vom Formular
|
||||
newUser.setFirstname(user.getFirstname());
|
||||
newUser.setLastname(user.getLastname());
|
||||
newUser.setMobile(user.getMobile());
|
||||
newUser.setFax(user.getFax());
|
||||
newUser.setTelefon(user.getTelefon());
|
||||
newUser.setActive(true);
|
||||
newUser.setCall(user.getCall());
|
||||
newUser.setTitle(user.getTitle());
|
||||
|
||||
// Erstelle Preferences
|
||||
Preferences preferences = new Preferences();
|
||||
preferences.setDefaultPreferences(newUser);
|
||||
newUser.setPreferences(preferences);
|
||||
|
||||
// Speichere den neuen Benutzer
|
||||
boolean saved = personManager.save(newUser);
|
||||
|
||||
if (saved) {
|
||||
FacesContext.getCurrentInstance().addMessage(null,
|
||||
new FacesMessage(FacesMessage.SEVERITY_INFO, "Erfolg", "Benutzer " + newUser.getEmail() + " wurde erstellt."));
|
||||
// Setze Formular zurück
|
||||
user = new Person();
|
||||
password = null;
|
||||
selectedGroup = null;
|
||||
} else {
|
||||
FacesContext.getCurrentInstance().addMessage(null,
|
||||
new FacesMessage(FacesMessage.SEVERITY_ERROR, "Fehler", "Benutzer konnte nicht erstellt werden. Überprüfen Sie die Logdateien für mehr Informationen."));
|
||||
}
|
||||
}
|
||||
}
|
||||
+325
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package controller.adresses;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.addresses.CompanyAddressManager;
|
||||
import business.addresses.LocationAddressManager;
|
||||
import controller.AbstractController;
|
||||
import controller.company.CompanyController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.adresses.Address;
|
||||
import model.adresses.CompanyAddress;
|
||||
import model.adresses.LocationAddress;
|
||||
import model.company.Company;
|
||||
import model.company.Location;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@ViewScoped
|
||||
@Named
|
||||
public class AddressController extends AbstractController<Address> {
|
||||
|
||||
@EJB
|
||||
CompanyAddressManager companyAddressManager;
|
||||
|
||||
@EJB
|
||||
LocationAddressManager locationAddressManager;
|
||||
|
||||
@Inject
|
||||
CompanyController companyController;
|
||||
|
||||
//Firma
|
||||
private Company company;
|
||||
|
||||
//Standort
|
||||
private Location location;
|
||||
|
||||
//Land
|
||||
private String country;
|
||||
|
||||
//Straßenname
|
||||
private String street;
|
||||
|
||||
//Hausnummer
|
||||
private String number;
|
||||
|
||||
//Zusatz
|
||||
private String extra;
|
||||
|
||||
//PLZ
|
||||
private Integer postnumber;
|
||||
|
||||
//Bundesland
|
||||
private String county;
|
||||
|
||||
//Ort
|
||||
private String place;
|
||||
|
||||
//Ansprechpartner
|
||||
private String contact;
|
||||
|
||||
//Kommentar
|
||||
private String comment;
|
||||
|
||||
private List<CompanyAddress> companyAddresses;
|
||||
private List<LocationAddress> locationAddresses;
|
||||
|
||||
private CompanyAddress selectedCompanyAddress;
|
||||
private LocationAddress selectedLocationAddress;
|
||||
|
||||
public AddressController() {
|
||||
companyAddresses = new ArrayList<>();
|
||||
locationAddresses = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void setCompanyToAll(Company selected) {
|
||||
if (companyAddresses == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
companyAddresses.forEach(c -> c.setCompany(selected));
|
||||
}
|
||||
|
||||
public void clearNegativIDsFromComps() {
|
||||
if (companyAddresses == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
companyAddresses.stream()
|
||||
.filter(c -> c.getId() < 0)
|
||||
.forEach(c -> c.setId(null));
|
||||
}
|
||||
|
||||
public void setLocationToAll(Location selected) {
|
||||
if (companyAddresses == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
locationAddresses.forEach(c -> c.setLocation(selected));
|
||||
}
|
||||
|
||||
public void createAddToCompany() {
|
||||
LOGGER.info("createAddToCompany");
|
||||
|
||||
CompanyAddress address = new CompanyAddress(null, country, street, number, extra, postnumber, county, place, contact, comment);
|
||||
address.setId(new Long((companyAddresses.size() + 1) * (-1)));
|
||||
companyAddresses.add(address);
|
||||
|
||||
sendInfoMessage("Erfolg", "Addresse wurde hinzugefügt!");
|
||||
clearCreation();
|
||||
}
|
||||
|
||||
public void selectToEdit() {
|
||||
if (selectedCompanyAddress == null) {
|
||||
LOGGER.error("selected Company address is null");
|
||||
sendErrorMessage("Fehler", "Es ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut!");
|
||||
return;
|
||||
}
|
||||
|
||||
this.company = selectedCompanyAddress.getCompany();
|
||||
this.country = selectedCompanyAddress.getCountry();
|
||||
this.street = selectedCompanyAddress.getStreet();
|
||||
this.number = selectedCompanyAddress.getNumber();
|
||||
this.extra = selectedCompanyAddress.getExtra();
|
||||
this.postnumber = selectedCompanyAddress.getPostnumber();
|
||||
this.county = selectedCompanyAddress.getCounty();
|
||||
this.place = selectedCompanyAddress.getPlace();
|
||||
this.comment = selectedCompanyAddress.getComment();
|
||||
this.contact = selectedCompanyAddress.getContact();
|
||||
}
|
||||
|
||||
public void editToCompany() {
|
||||
LOGGER.info("editToCompany");
|
||||
|
||||
selectedCompanyAddress.setCountry(country);
|
||||
selectedCompanyAddress.setStreet(street);
|
||||
selectedCompanyAddress.setNumber(number);
|
||||
selectedCompanyAddress.setExtra(extra);
|
||||
selectedCompanyAddress.setPostnumber(postnumber);
|
||||
selectedCompanyAddress.setCounty(county);
|
||||
selectedCompanyAddress.setPlace(place);
|
||||
selectedCompanyAddress.setComment(comment);
|
||||
selectedCompanyAddress.setContact(contact);
|
||||
|
||||
sendInfoMessage("Erfolg", "Addresse wurde bearbeitet!");
|
||||
clearCreation();
|
||||
}
|
||||
|
||||
public void deleteSelected() {
|
||||
if (selectedCompanyAddress == null || companyAddresses.isEmpty()) {
|
||||
sendErrorMessage("Fehler", "Es ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut!");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < companyAddresses.size(); i++) {
|
||||
CompanyAddress add = companyAddresses.get(i);
|
||||
if (add.getId().equals(selectedCompanyAddress.getId())) {
|
||||
companyAddresses.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
sendInfoMessage("Erfolg", "Adresse wurde gelöscht!");
|
||||
clearCreation();
|
||||
}
|
||||
|
||||
public void clearCreation() {
|
||||
this.company = null;
|
||||
this.location = null;
|
||||
this.country = null;
|
||||
this.street = null;
|
||||
this.number = null;
|
||||
this.extra = null;
|
||||
this.postnumber = null;
|
||||
this.county = null;
|
||||
this.place = null;
|
||||
this.comment = null;
|
||||
this.contact = null;
|
||||
this.selectedCompanyAddress = null;
|
||||
this.selectedLocationAddress = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
clearCreation();
|
||||
this.companyAddresses.clear();
|
||||
this.locationAddresses.clear();
|
||||
this.selectedCompanyAddress = null;
|
||||
this.selectedLocationAddress = null;
|
||||
}
|
||||
|
||||
public Company getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public String getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public void setContact(String contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public CompanyAddress getSelectedCompanyAddress() {
|
||||
return selectedCompanyAddress;
|
||||
}
|
||||
|
||||
public void setSelectedCompanyAddress(CompanyAddress selectedCompanyAddress) {
|
||||
this.selectedCompanyAddress = selectedCompanyAddress;
|
||||
}
|
||||
|
||||
public LocationAddress getSelectedLocationAddress() {
|
||||
return selectedLocationAddress;
|
||||
}
|
||||
|
||||
public void setSelectedLocationAddress(LocationAddress selectedLocationAddress) {
|
||||
this.selectedLocationAddress = selectedLocationAddress;
|
||||
}
|
||||
|
||||
public void setCompany(Company company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(String number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getExtra() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
public void setExtra(String extra) {
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
public Integer getPostnumber() {
|
||||
return postnumber;
|
||||
}
|
||||
|
||||
public void setPostnumber(Integer postnumber) {
|
||||
this.postnumber = postnumber;
|
||||
}
|
||||
|
||||
public String getCounty() {
|
||||
return county;
|
||||
}
|
||||
|
||||
public void setCounty(String county) {
|
||||
this.county = county;
|
||||
}
|
||||
|
||||
public String getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
public void setPlace(String place) {
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
public List<CompanyAddress> getCompanyAddresses() {
|
||||
return companyAddresses;
|
||||
}
|
||||
|
||||
public void setCompanyAddresses(List<CompanyAddress> companyAddresses) {
|
||||
this.companyAddresses = companyAddresses;
|
||||
}
|
||||
|
||||
public List<LocationAddress> getLocationAddresses() {
|
||||
return locationAddresses;
|
||||
}
|
||||
|
||||
public void setLocationAddresses(List<LocationAddress> locationAddresses) {
|
||||
this.locationAddresses = locationAddresses;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Address> getManager() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package controller.company;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.company.CompanyManager;
|
||||
import controller.AbstractController;
|
||||
import controller.adresses.AddressController;
|
||||
import controller.machine.SecurityAreaController;
|
||||
import controller.person.PersonController;
|
||||
import controller.search.SearchController;
|
||||
import controller.tickets.TicketController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.transaction.Transactional;
|
||||
import model.adresses.CompanyAddress;
|
||||
import model.company.Company;
|
||||
import model.company.Location;
|
||||
import model.company.Status;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@Named
|
||||
@SessionScoped
|
||||
public class CompanyController extends AbstractController<Company> {
|
||||
|
||||
@Inject
|
||||
PersonController personController;
|
||||
|
||||
@Inject
|
||||
AddressController addressController;
|
||||
|
||||
@Inject
|
||||
CustomerController customerController;
|
||||
|
||||
@Inject
|
||||
LocationController locationController;
|
||||
|
||||
@Inject
|
||||
SecurityAreaController securityAreaController;
|
||||
|
||||
@Inject
|
||||
TicketController ticketController;
|
||||
|
||||
@Inject
|
||||
SearchController searchController;
|
||||
|
||||
@EJB
|
||||
CompanyManager companyManager;
|
||||
|
||||
private Company selected;
|
||||
|
||||
private List<Company> companíes;
|
||||
|
||||
//Vars of a company
|
||||
private String name;
|
||||
private String steuerNr;
|
||||
private String umsatzsteuerNr;
|
||||
private String comment;
|
||||
private ArrayList<CompanyAddress> addresses;
|
||||
private ArrayList<Location> locations;
|
||||
private String kundenNr;
|
||||
private String headerInspection;
|
||||
private String headerService;
|
||||
private Status status;
|
||||
|
||||
|
||||
|
||||
public CompanyController() {
|
||||
setCreated(new Company());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addFromSelected() {
|
||||
selected = companyManager.findWithAddresses(selected);
|
||||
refrehSelected();
|
||||
|
||||
addressController.setCompanyAddresses(new ArrayList<>(selected.getAddresses()));
|
||||
customerController.setCustomers(new ArrayList<>(selected.getCustomers()));
|
||||
if (selected.getLocations() == null) {
|
||||
selected.setLocations(new HashSet<>());
|
||||
}
|
||||
locationController.setLocations(new ArrayList<>(selected.getLocations()));
|
||||
securityAreaController.createMachineMenu();
|
||||
|
||||
name = selected.getName();
|
||||
steuerNr = selected.getSteuerNr();
|
||||
umsatzsteuerNr = selected.getUmsatzSteuerID();
|
||||
comment = selected.getComment();
|
||||
kundenNr = selected.getKundenNr();
|
||||
status = selected.getStatus();
|
||||
headerService = selected.getHeaderService();
|
||||
headerInspection = selected.getHeaderInspection();
|
||||
|
||||
ticketController.createSelectedLocations();
|
||||
searchController.setFromSelectedCompany();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addFromSelectedFromSearch() {
|
||||
selected = companyManager.findWithAddresses(selected);
|
||||
refrehSelected();
|
||||
|
||||
addressController.setCompanyAddresses(new ArrayList<>(selected.getAddresses()));
|
||||
customerController.setCustomers(new ArrayList<>(selected.getCustomers()));
|
||||
if (selected.getLocations() == null) {
|
||||
selected.setLocations(new HashSet<>());
|
||||
}
|
||||
locationController.setLocations(new ArrayList<>(selected.getLocations()));
|
||||
securityAreaController.createMachineMenu();
|
||||
|
||||
name = selected.getName();
|
||||
steuerNr = selected.getSteuerNr();
|
||||
umsatzsteuerNr = selected.getUmsatzSteuerID();
|
||||
comment = selected.getComment();
|
||||
kundenNr = selected.getKundenNr();
|
||||
status = selected.getStatus();
|
||||
headerService = selected.getHeaderService();
|
||||
headerInspection = selected.getHeaderInspection();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
LOGGER.info("Length of address lists {}", addressController.getCompanyAddresses().size());
|
||||
|
||||
if (selected != null && selected.getId() != null) {
|
||||
LOGGER.info("Update of " + selected.getName()
|
||||
+ " with ID " + selected.getId() + " initiated from "
|
||||
+ personController.getActiveUser());
|
||||
|
||||
addressController.setCompanyToAll(selected);
|
||||
|
||||
addressController.clearNegativIDsFromComps();
|
||||
selected.setAddresses(new HashSet(addressController.getCompanyAddresses()));
|
||||
|
||||
selected.setName(name);
|
||||
selected.setSteuerNr(steuerNr != null && steuerNr.isEmpty() ? null : steuerNr);
|
||||
selected.setUmsatzSteuerID(umsatzsteuerNr != null && umsatzsteuerNr.isBlank() ? null : umsatzsteuerNr);
|
||||
selected.setComment(comment);
|
||||
selected.setKundenNr(kundenNr);
|
||||
selected.setStatus(status);
|
||||
selected.setHeaderService(headerService);
|
||||
selected.setHeaderInspection(headerInspection);
|
||||
|
||||
try {
|
||||
companyManager.save(selected);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
sendErrorMessage("Fehler", "Es ist ein Fehler beim Speichern aufgetreten. \n bitte Versuchen Sie es erneut!");
|
||||
return;
|
||||
}
|
||||
|
||||
sendInfoMessage("Unternehmen geändert", "Das Unternemen mit dem Namen " + selected.getName() + " wurde geändert");
|
||||
clearEntries();
|
||||
|
||||
} else {
|
||||
|
||||
Company comp = new Company();
|
||||
addressController.clearNegativIDsFromComps();
|
||||
addressController.setCompanyToAll(comp);
|
||||
|
||||
comp.setAddresses(new HashSet(addressController.getCompanyAddresses()));
|
||||
comp.setName(name);
|
||||
comp.setSteuerNr(steuerNr != null && steuerNr.isEmpty() ? null : steuerNr);
|
||||
comp.setUmsatzSteuerID(umsatzsteuerNr != null && umsatzsteuerNr.isBlank() ? null : umsatzsteuerNr);
|
||||
comp.setComment(comment);
|
||||
comp.setKundenNr(kundenNr);
|
||||
comp.setStatus(status);
|
||||
comp.setHeaderService(headerService);
|
||||
comp.setHeaderInspection(headerInspection);
|
||||
|
||||
try {
|
||||
companyManager.save(comp);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
sendErrorMessage("Fehler", "Es ist ein Fehler beim Speichern aufgetreten. \n bitte Versuchen Sie es erneut!");
|
||||
return;
|
||||
}
|
||||
|
||||
clearEntries();
|
||||
|
||||
sendInfoMessage("Unternehmen erstellt", "Das Unternemen mit dem Namen " + comp.getName() + " wurde erstellt");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean saveSelected(){
|
||||
if (selected == null || selected.getId() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
companyManager.edit(selected);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void deleteSelected(){
|
||||
if (selected == null) {
|
||||
sendErrorMessage("Fehler", "Es ist ein Fehler beim Speichern aufgetreten. \n bitte Versuchen Sie es erneut!");
|
||||
clearEntries();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
companyManager.remove(selected);
|
||||
sendInfoMessage("Erfolg", "Firma \"" + selected.getName() + "\" wurde gelöscht!");
|
||||
clearEntries();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
sendErrorMessage("Fehler", "Es ist ein Fehler beim Speichern aufgetreten. \n bitte Versuchen Sie es erneut!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
name = "";
|
||||
steuerNr = "";
|
||||
umsatzsteuerNr = "";
|
||||
kundenNr = null;
|
||||
headerInspection = "";
|
||||
headerService = "";
|
||||
status = null;
|
||||
comment = null;
|
||||
|
||||
addressController.clearEntries();
|
||||
selected = null;
|
||||
}
|
||||
|
||||
public Company getCompanyByName(String name){
|
||||
if (name == null || name.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return companyManager.findCompanyByName(name);
|
||||
}
|
||||
|
||||
public Status[] getAllStatus() {
|
||||
return Status.values();
|
||||
}
|
||||
|
||||
public List<Status> allStatusAsList(){
|
||||
|
||||
return Arrays.asList(getAllStatus());
|
||||
}
|
||||
|
||||
public List<Company> getAllCompanys() {
|
||||
return companyManager.findAll();
|
||||
}
|
||||
|
||||
public void reloadCompanys() {
|
||||
this.companíes = companyManager.findAll();
|
||||
}
|
||||
|
||||
public List<Company> getCompanys() {
|
||||
if (companíes == null) {
|
||||
reloadCompanys();
|
||||
}
|
||||
return companíes;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getKundenNr() {
|
||||
return kundenNr;
|
||||
}
|
||||
|
||||
public void setKundenNr(String kundenNr) {
|
||||
this.kundenNr = kundenNr;
|
||||
}
|
||||
|
||||
public String getHeaderInspection() {
|
||||
return headerInspection;
|
||||
}
|
||||
|
||||
public void setHeaderInspection(String headerInspection) {
|
||||
this.headerInspection = headerInspection;
|
||||
}
|
||||
|
||||
public String getHeaderService() {
|
||||
return headerService;
|
||||
}
|
||||
|
||||
public void setHeaderService(String headerService) {
|
||||
this.headerService = headerService;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public String getSteuerNr() {
|
||||
return steuerNr;
|
||||
}
|
||||
|
||||
public void setSteuerNr(String steuerNr) {
|
||||
this.steuerNr = steuerNr;
|
||||
}
|
||||
|
||||
public String getUmsatzsteuerNr() {
|
||||
return umsatzsteuerNr;
|
||||
}
|
||||
|
||||
public void setUmsatzsteuerNr(String umsatzsteuerNr) {
|
||||
this.umsatzsteuerNr = umsatzsteuerNr;
|
||||
}
|
||||
|
||||
public List<Company> getCompaníes() {
|
||||
return companíes;
|
||||
}
|
||||
|
||||
public void setCompaníes(List<Company> companíes) {
|
||||
this.companíes = companíes;
|
||||
}
|
||||
|
||||
public ArrayList<CompanyAddress> getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public void setAddresses(ArrayList<CompanyAddress> addresses) {
|
||||
this.addresses = addresses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Company getSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(Company selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
public ArrayList<Location> getLocations() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
public void setLocations(ArrayList<Location> locations) {
|
||||
this.locations = locations;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Company> getManager() {
|
||||
return companyManager;
|
||||
}
|
||||
}
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.company;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.company.CompanyLogoManager;
|
||||
import business.company.CompanyManager;
|
||||
import controller.AbstractController;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import javax.ejb.EJB;
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.company.CompanyLogo;
|
||||
import model.files.Mime;
|
||||
import org.primefaces.event.FileUploadEvent;
|
||||
import org.primefaces.model.CroppedImage;
|
||||
import org.primefaces.model.DefaultStreamedContent;
|
||||
import org.primefaces.model.StreamedContent;
|
||||
import org.primefaces.model.file.UploadedFile;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@SessionScoped
|
||||
public class CompanyLogoController extends AbstractController<CompanyLogo> {
|
||||
@Inject
|
||||
CompanyController companyController;
|
||||
|
||||
@EJB
|
||||
CompanyManager companyManager;
|
||||
|
||||
@EJB
|
||||
CompanyLogoManager logoManager;
|
||||
|
||||
private CroppedImage croppedImage;
|
||||
|
||||
|
||||
public CompanyLogoController() {
|
||||
super();
|
||||
setSelected(new CompanyLogo());
|
||||
setCreated(new CompanyLogo());
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public void handleCreatedUpload(FileUploadEvent event) {
|
||||
UploadedFile file = event.getFile();
|
||||
|
||||
|
||||
|
||||
if (file != null && file.getContent() != null && file.getContent().length > 0 && file.getFileName() != null) {
|
||||
|
||||
if (createSaveLogo(file, true)) {
|
||||
sendInfoMessage("Erfolg", getCreated().getName() + " wurde hochgeladen!");
|
||||
} else {
|
||||
sendErrorMessage("Fehler", "Es ist ein Fehler aufgetreten. Bitte Versuchen Sie es erneut!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleSelectedUpload(FileUploadEvent event) {
|
||||
UploadedFile file = event.getFile();
|
||||
|
||||
if (file != null && file.getContent() != null && file.getContent().length > 0 && file.getFileName() != null) {
|
||||
|
||||
setData(getSelected(), file);
|
||||
|
||||
/*
|
||||
if (createSaveLogo(file, false)) {
|
||||
sendInfoMessage("Erfolg", getCreated().getName() + " wurde hochgeladen!");
|
||||
} else {
|
||||
sendErrorMessage("Fehler", "Es ist ein Fehler aufgetreten. Bitte Versuchen Sie es erneut!");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
public StreamedContent getUploaded(){
|
||||
System.out.println("getUpload");
|
||||
return DefaultStreamedContent.builder()
|
||||
.contentType(getCreated().getFileData() == null ? null : getCreated().getMime().getMimeType())
|
||||
.stream(() -> {
|
||||
if (getCreated() == null
|
||||
|| getCreated().getFileData()== null
|
||||
|| getCreated().getFileData().length == 0) {
|
||||
System.out.println("No output " + getCreated());
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println("GetCreated as output stream! " + getCreated().getName());
|
||||
return new ByteArrayInputStream(getCreated().getFileData());
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
public void crop() {
|
||||
getUploaded();
|
||||
if (this.croppedImage == null || this.croppedImage.getBytes() == null || this.croppedImage.getBytes().length == 0) {
|
||||
sendErrorMessage(ERROR_TITLE, ERROR_MESSAGE);
|
||||
}
|
||||
else {
|
||||
sendInfoMessage(SUCCESS_TITLE, SUCCESS_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public StreamedContent getCropped() {
|
||||
return DefaultStreamedContent.builder()
|
||||
.contentType(getCreated() == null ? null : getCreated().getMime().getMimeType())
|
||||
.stream(() -> {
|
||||
if (croppedImage == null
|
||||
|| croppedImage.getBytes() == null
|
||||
|| croppedImage.getBytes().length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new ByteArrayInputStream(this.croppedImage.getBytes());
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
private boolean createSaveLogo(UploadedFile file, boolean isCreated) {
|
||||
CompanyLogo logo;
|
||||
if (isCreated) {
|
||||
logo = getCreated();
|
||||
} else {
|
||||
logo = getSelected();
|
||||
}
|
||||
|
||||
setData(logo, file);
|
||||
|
||||
if (isCreated) {
|
||||
logo.setCompany(companyController.getCreated());
|
||||
companyController.getCreated().setCompanyLogo(logo);
|
||||
setCreated(logo);
|
||||
return true;
|
||||
}
|
||||
|
||||
logo.setCompany(companyController.getSelected());
|
||||
logoManager.save(logo);
|
||||
companyController.getSelected().setCompanyLogo(logo);
|
||||
setSelected(logo);
|
||||
|
||||
return companyController.saveSelected();
|
||||
}
|
||||
|
||||
private void setData(CompanyLogo picture, UploadedFile file) {
|
||||
picture.setName(file.getFileName());
|
||||
picture.setFileData(file.getContent());
|
||||
picture.setMime(Mime.getByMimeType(file.getContentType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<CompanyLogo> getManager() {
|
||||
return logoManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(new CompanyLogo());
|
||||
setCreated(new CompanyLogo());
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public CroppedImage getCroppedImage() {
|
||||
return croppedImage;
|
||||
}
|
||||
|
||||
public void setCroppedImage(CroppedImage croppedImage) {
|
||||
this.croppedImage = croppedImage;
|
||||
}
|
||||
}
|
||||
+236
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package controller.company;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.company.CustomerManager;
|
||||
import business.user.PasswordManager;
|
||||
import controller.AbstractController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import model.person.Password;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.customer.Customer;
|
||||
import model.person.Salt;
|
||||
import model.person.Token;
|
||||
import model.person.enums.Call;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@ViewScoped
|
||||
@Named
|
||||
public class CustomerController extends AbstractController<Customer>{
|
||||
|
||||
@Inject
|
||||
CompanyController companyController;
|
||||
|
||||
@EJB
|
||||
PasswordManager passwordManager;
|
||||
|
||||
private Customer selected;
|
||||
private List<Customer> customers;
|
||||
private Customer created;
|
||||
|
||||
@EJB
|
||||
CustomerManager customerManager;
|
||||
|
||||
public CustomerController() {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init(){
|
||||
selected = new Customer();
|
||||
created = new Customer();
|
||||
customers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addNewCustomer(){
|
||||
Customer cust = new Customer();
|
||||
|
||||
Long fakeId = createFakeID(customers);
|
||||
cust.setId(fakeId);
|
||||
|
||||
customers.add(cust);
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Ansprechpartner Nr. "+ (customers.indexOf(cust) + 1) + " wurde hinzugefügt!");
|
||||
}
|
||||
|
||||
public void removeCustomer(Customer customer){
|
||||
if (customer == null || customer.getId() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
int nr = customers.indexOf(customer);
|
||||
nr++;
|
||||
|
||||
if (customer.getId() > 0) {
|
||||
companyController.getSelected().getCustomers().remove(customer);
|
||||
companyController.saveSelected();
|
||||
customerManager.remove(customer);
|
||||
} else {
|
||||
customers.remove(customer);
|
||||
}
|
||||
|
||||
sendInfoMessage("Erfolg", "Ansprechpartner Nr. " + nr + " wurde entfernt.");
|
||||
}
|
||||
|
||||
public void saveAllToCompany(){
|
||||
companyController.saveSelected();
|
||||
|
||||
customers.stream().filter(cust -> (cust.getId() != null && cust.getId() <= 0)).forEachOrdered(cust -> {
|
||||
cust.setId(null);
|
||||
cust.setCompany(companyController.getSelected());
|
||||
cust.setTokens(new ArrayList<Token>());
|
||||
autoGeneratePasswordAndSalt(cust);
|
||||
});
|
||||
|
||||
customers.forEach(c-> {
|
||||
customerManager.save(c);
|
||||
});
|
||||
|
||||
|
||||
companyController.getSelected().setCustomers(new HashSet<>(customers));
|
||||
|
||||
companyController.saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Firma \"" + companyController.getSelected().getKundenNr() + "\" wurde gespeichert");
|
||||
|
||||
companyController.addFromSelected();
|
||||
}
|
||||
|
||||
private void autoGeneratePasswordAndSalt(Customer customer){
|
||||
Salt salt = new Salt();
|
||||
customer.setSalt(salt);
|
||||
|
||||
Password password = passwordManager.gerateNewRandomPasswordClass(customer);
|
||||
customer.setPassword(password);
|
||||
}
|
||||
|
||||
public void updateSelected(){
|
||||
if (selected == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
int index = customers.indexOf(selected);
|
||||
customers.remove(index);
|
||||
customers.add(index, selected);
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, selected.getEmail() + " wurde erfolgreich editiert.");
|
||||
|
||||
selected = new Customer();
|
||||
}
|
||||
|
||||
public void clearSelected(){
|
||||
selected = new Customer();
|
||||
}
|
||||
|
||||
public void saveToCompany(Customer customer){
|
||||
if (customer == null || customer.getId() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if (customer.getId() < 0) {
|
||||
customer.setId(null);
|
||||
}
|
||||
|
||||
customer.setCompany(companyController.getSelected());
|
||||
|
||||
if (customerManager.save(customer)) {
|
||||
companyController.getSelected().addCustomer(customer);
|
||||
if (companyController.saveSelected()) {
|
||||
sendInfoMessage(SUCCESS_TITLE, "Ansprechpartner Nr. " + customers.indexOf(customer) + 1 + " wurde gespeichert!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
errorMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
selected = new Customer();
|
||||
customers.clear();
|
||||
created = new Customer();
|
||||
companyController.clearEntries();
|
||||
}
|
||||
|
||||
public void clearCreated(){
|
||||
created = new Customer();
|
||||
}
|
||||
|
||||
public void addClearCreatedCustomer(){
|
||||
if (created.getEmail() != null) {
|
||||
Customer found = customerManager.findByEmail(created.getEmail());
|
||||
if(found != null){
|
||||
sendErrorMessage("Fehler", "Benutzer mit der Emailadresse \""+ created.getEmail() + "\" existiert bereits in der Firma \""+ found.getCompany().getKundenNr() + "\" !");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for(Customer c : customers){
|
||||
if (c.getEmail().equals(created.getEmail())) {
|
||||
sendErrorMessage("Fehler", "Benutzer mit der Emailadresse \""+ created.getEmail() + "\" existiert bereits in dieser Firma !");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Long fakeId = createFakeID(customers);
|
||||
created.setId(fakeId);
|
||||
|
||||
try {
|
||||
customers.add(created.clone());
|
||||
System.out.println(created.getCall() + " " + created.getTitle());
|
||||
sendInfoMessage(SUCCESS_TITLE, "Ansprechpartner \"" + created.getEmail() + "\" wurde erstellt!");
|
||||
created = new Customer();
|
||||
} catch (CloneNotSupportedException ex) {
|
||||
LOGGER.error(ex);
|
||||
errorMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public Call[] getCalls(){
|
||||
return Call.values();
|
||||
}
|
||||
|
||||
public Customer getSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void setSelected(Customer selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
public List<Customer> getCustomers() {
|
||||
return customers;
|
||||
}
|
||||
|
||||
public void setCustomers(List<Customer> customers) {
|
||||
this.customers = customers;
|
||||
}
|
||||
|
||||
public Customer getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Customer created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Customer> getManager() {
|
||||
return customerManager;
|
||||
}
|
||||
}
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package controller.company;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.company.CompanyManager;
|
||||
import business.company.LocationManager;
|
||||
import controller.AbstractController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.company.Company;
|
||||
import model.company.Location;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class LocationController extends AbstractController<Location> {
|
||||
|
||||
@Inject
|
||||
CompanyController companyController;
|
||||
|
||||
@Inject
|
||||
CustomerController customerController;
|
||||
|
||||
private Location selected;
|
||||
private Location created;
|
||||
private Location target;
|
||||
|
||||
@EJB
|
||||
LocationManager locationManager;
|
||||
|
||||
@EJB
|
||||
CompanyManager companyManager;
|
||||
|
||||
private Company company;
|
||||
|
||||
private List<Location> locations;
|
||||
|
||||
public LocationController() {
|
||||
}
|
||||
|
||||
public boolean renderTabs() {
|
||||
return locations != null && !locations.isEmpty();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (company == null || company.getId() == null || company.getId() < 0) {
|
||||
sendErrorMessage("Fehler", "Bitte wählen Sie eine Firma!");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean wasNew = selected.getId() == null;
|
||||
|
||||
if (selected.getCompany() == null) {
|
||||
selected.setCompany(company);
|
||||
}
|
||||
|
||||
if (locationManager.save(selected)) {
|
||||
company = companyManager.findWithLocations(company);
|
||||
company.addLocation(selected);
|
||||
|
||||
if (companyManager.save(company)) {
|
||||
sendInfoMessage("Erfolg", "Standort \"" + selected.getName() + "\" wurde erfolgreich gespeichert zu Firma \"" + company.getName() + "\" !");
|
||||
clearEntries();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
errorMessage();
|
||||
}
|
||||
|
||||
public void saveAllToCompany(){
|
||||
companyController.saveSelected();
|
||||
|
||||
locations.stream().filter(loc -> (loc.getId() != null && loc.getId() <= 0)).forEachOrdered(loc -> {
|
||||
loc.setId(null);
|
||||
loc.setCompany(companyController.getSelected());
|
||||
});
|
||||
|
||||
locations.forEach(l -> {
|
||||
locationManager.save(l);
|
||||
});
|
||||
|
||||
companyController.getSelected().setLocations(new HashSet<>(locations));
|
||||
|
||||
companyController.saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Firma \"" + companyController.getSelected().getKundenNr() + "\" wurde gespeichert");
|
||||
|
||||
companyController.addFromSelected();
|
||||
}
|
||||
|
||||
public void saveSelected(){
|
||||
locationManager.save(selected);
|
||||
locations.set(locations.indexOf(selected), selected);
|
||||
companyController.getSelected().setLocations(new HashSet<>(locations));
|
||||
companyController.saveSelected();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
void init() {
|
||||
selected = new Location();
|
||||
created = new Location();
|
||||
company = new Company();
|
||||
locations = new ArrayList<>();
|
||||
|
||||
if (companyController.getSelected() != null) {
|
||||
company = companyController.getSelected();
|
||||
locations = new ArrayList<>(company.getLocations());
|
||||
} else {
|
||||
companyController.clearEntries();
|
||||
}
|
||||
}
|
||||
|
||||
public void addNewLocation() {
|
||||
Location loc = new Location(created);
|
||||
|
||||
Long fakeId = createFakeID(locations);
|
||||
loc.setId(fakeId);
|
||||
locations.add(loc);
|
||||
|
||||
created = new Location();
|
||||
sendInfoMessage("Erfolg", "Standort Nr. " + locations.size() + " hinzugefügt.");
|
||||
}
|
||||
|
||||
public void editLocation(){
|
||||
if (selected == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Der Standort \"" + selected.getName() + "\" wurde bearbeitet");
|
||||
selected = new Location();
|
||||
}
|
||||
|
||||
public void removeCreateLocation(Location location){
|
||||
if (location == null || location.getId() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
int nr = locations.indexOf(location);
|
||||
nr++;
|
||||
|
||||
locations.remove(location);
|
||||
|
||||
if (location.getId() > 0) {
|
||||
companyController.getSelected().getLocations().remove(location);
|
||||
companyController.saveSelected();
|
||||
locationManager.remove(location);
|
||||
companyController.addFromSelected();
|
||||
}
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Standort Nr. " + nr + " wurde entfernt.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
this.init();
|
||||
target = null;
|
||||
companyController.clearEntries();
|
||||
}
|
||||
|
||||
public int getPos(Location location) {
|
||||
return locations.indexOf(location) + 1;
|
||||
}
|
||||
|
||||
public Company getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(Company company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public List<Location> getLocations() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
public void setLocations(List<Location> locations) {
|
||||
this.locations = locations;
|
||||
}
|
||||
|
||||
public Location getSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void setSelected(Location selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
public Location getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Location created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Location> getManager() {
|
||||
return locationManager;
|
||||
}
|
||||
|
||||
public Location getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(Location target) {
|
||||
this.target = target;
|
||||
}
|
||||
}
|
||||
+855
@@ -0,0 +1,855 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.company;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.company.CompanyManager;
|
||||
import business.company.LocationManager;
|
||||
import business.machine.MachineManager;
|
||||
import com.itextpdf.text.pdf.PdfReader;
|
||||
import com.itextpdf.text.pdf.parser.PdfTextExtractor;
|
||||
import controller.AbstractController;
|
||||
import controller.machine.SecurityDeviceCompanyController;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.adresses.CompanyAddress;
|
||||
import model.company.Company;
|
||||
import model.company.Location;
|
||||
import model.company.Status;
|
||||
import model.files.Mime;
|
||||
import model.machine.Machine;
|
||||
import model.machine.enums.MachineStatus;
|
||||
import model.machine.enums.MachineType;
|
||||
import model.machine.enums.Option;
|
||||
import model.machine.enums.norms.AOPD_AOPDDR;
|
||||
import model.machine.enums.norms.ArrayApproach;
|
||||
import model.machine.enums.norms.ControlParts;
|
||||
import model.security.DangerPoint;
|
||||
import model.security.MeasuringPoint;
|
||||
import model.security.SecurityArea;
|
||||
import model.security.SecurityDevice;
|
||||
import model.security.enums.ApproachSpeed;
|
||||
import model.security.enums.Component;
|
||||
import model.security.enums.DeviceRole;
|
||||
import model.security.enums.MountingPosition;
|
||||
import model.security.enums.MutingBlankingModus;
|
||||
import model.security.enums.MutingSignals;
|
||||
import model.security.enums.OverrunMeasurementType;
|
||||
import model.security.enums.ProtectionType;
|
||||
import model.security.enums.SecurityCategory;
|
||||
import model.security.enums.SecurityType;
|
||||
import model.security.enums.SfAlignment;
|
||||
import model.security.switching.SwitchingDevice;
|
||||
import org.primefaces.event.FileUploadEvent;
|
||||
import org.primefaces.event.FilesUploadEvent;
|
||||
import org.primefaces.model.file.UploadedFile;
|
||||
import org.primefaces.model.file.UploadedFiles;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class PdfReaderController extends AbstractController<Machine> {
|
||||
|
||||
public static final List<Mime> allowedFileTypes = Arrays.asList(Mime.PDF);
|
||||
public static final long sizeLimit = 20000000L;
|
||||
private static final Pattern streetPattern = Pattern.compile("^(.*[^0-9])(\\d+.*)$");
|
||||
private static final Pattern countyPattern = Pattern.compile("^(\\d+)([^0-9].*)$");
|
||||
private static final Pattern areaPattern = Pattern.compile("C\\.\\d+ .*");
|
||||
|
||||
@EJB
|
||||
MachineManager machineManager;
|
||||
|
||||
@EJB
|
||||
CompanyManager companyManager;
|
||||
|
||||
@EJB
|
||||
LocationManager locationManager;
|
||||
|
||||
@Inject
|
||||
LocationController locationController;
|
||||
|
||||
@Inject
|
||||
CompanyController companyController;
|
||||
|
||||
@Inject
|
||||
SecurityDeviceCompanyController securityDeviceCompanyController;
|
||||
|
||||
private UploadedFiles files;
|
||||
private String log;
|
||||
|
||||
public PdfReaderController() {
|
||||
super();
|
||||
setCreated(new Machine());
|
||||
setSelected(new Machine());
|
||||
log = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Machine> getManager() {
|
||||
return machineManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setCreated(new Machine());
|
||||
setSelected(new Machine());
|
||||
getEntities().clear();
|
||||
log = "";
|
||||
}
|
||||
|
||||
public void handleFilesUpload(FilesUploadEvent event) {
|
||||
for (UploadedFile f : event.getFiles().getFiles()) {
|
||||
sendErrorMessage(SUCCESS_TITLE, "Datei \"" + f.getFileName() + "\" wurde hochgeladen.");
|
||||
}
|
||||
|
||||
files = event.getFiles();
|
||||
Map<String, byte[]> data = createCompanyDataFromPDF();
|
||||
|
||||
readPDFDate(data);
|
||||
}
|
||||
|
||||
public void handleFileUpload(FileUploadEvent event) {
|
||||
List<UploadedFile> uploaded = new ArrayList<>();
|
||||
uploaded.add(event.getFile());
|
||||
files = new UploadedFiles(uploaded);
|
||||
|
||||
Map<String, byte[]> data = createCompanyDataFromPDF();
|
||||
|
||||
readPDFDate(data);
|
||||
}
|
||||
|
||||
private void readPDFDate(Map<String, byte[]> uploaded) {
|
||||
if (uploaded.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
uploaded.forEach((name, data) -> {
|
||||
sendInfoMessage("Lese " + name, "Starte das einlesen von den Daten von " + name);
|
||||
Location location;
|
||||
Machine created = null;
|
||||
Company company = null;
|
||||
|
||||
try {
|
||||
//Create Location and Machine
|
||||
PdfReader reader = new PdfReader(data);
|
||||
boolean isBeforeCompanyData = true;
|
||||
boolean isBeforeMachineData = true;
|
||||
String lines = PdfTextExtractor.getTextFromPage(reader, 1);
|
||||
//Check for ServiceProtocol
|
||||
Scanner scanner = new Scanner(lines);
|
||||
if (!checkForRightDocument(scanner, name)) {
|
||||
sendErrorMessage("Falsches Dokument", "Dokument \"" + name + "\" wird übersprungen");
|
||||
return;
|
||||
}
|
||||
|
||||
while (isBeforeCompanyData) {
|
||||
isBeforeCompanyData = !scanner.nextLine().startsWith("A.1");
|
||||
}
|
||||
|
||||
company = createCompanyFromPage(scanner);
|
||||
companyManager.save(company);
|
||||
//Hibernate.initialize(company);
|
||||
|
||||
if (company.getLocations() == null) {
|
||||
company.setLocations(new HashSet<>());
|
||||
}
|
||||
|
||||
String linesCopy = lines;
|
||||
location = createLocationFromPage(new Scanner(linesCopy), company.getLocations());
|
||||
|
||||
//Jump to machine data
|
||||
while (isBeforeMachineData) {
|
||||
isBeforeMachineData = !scanner.nextLine().startsWith("B.1");
|
||||
}
|
||||
created = createMachineFromPage(scanner);
|
||||
|
||||
location.addMachine(created);
|
||||
created.setLocation(location);
|
||||
|
||||
StringBuilder secDevData = new StringBuilder();
|
||||
|
||||
//Creation of Schutzbereiche starting with page 2
|
||||
//Last page is skipped; No valuable data
|
||||
for (int i = 2; i < reader.getNumberOfPages(); i++) {
|
||||
secDevData.append(PdfTextExtractor.getTextFromPage(reader, i));
|
||||
}
|
||||
scanner = new Scanner(secDevData.toString());
|
||||
//Give Area creation all pages
|
||||
List<SecurityArea> createdAreas = createSecurityAreasFromPage(scanner);
|
||||
|
||||
if (created.getSecurityArea() == null) {
|
||||
created.setSecurityArea(new ArrayList<>());
|
||||
}
|
||||
|
||||
created.getSecurityArea().addAll(createdAreas);
|
||||
for (SecurityArea area : created.getSecurityArea()) {
|
||||
area.setMachine(created);
|
||||
}
|
||||
|
||||
location.setCompany(company);
|
||||
//companyManager.refresh(company);
|
||||
company.addLocation(location);
|
||||
companyManager.save(company);
|
||||
} catch (IOException ex) {
|
||||
LOGGER.error(ex);
|
||||
sendErrorMessage(ERROR_TITLE, "Die Datei \"" + name + "\" konnte nicht gelesen werden!");
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
sendErrorMessage(ERROR_TITLE, "Die Datei \"" + name + "\" konnte nicht gelesen werden!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Das einlesen von den Daten von " + name + " war erfolgreich!");
|
||||
});
|
||||
}
|
||||
|
||||
private boolean checkForRightDocument(Scanner scanner, String name) {
|
||||
if (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (!line.startsWith("Leuze")) {
|
||||
LOGGER.error("Document didn't start with Leuze header");
|
||||
//sendErrorMessage(ERROR_TITLE, "Die Datei \"" + name + "\" konnte nicht gelesen werden, falscher Inhalt!");
|
||||
if (scanner.hasNextLine()) {
|
||||
if (!line.startsWith("Inspektionsprotokoll")) {
|
||||
LOGGER.error("Exspected \"Inspektionsprotokoll\" in second line");
|
||||
sendErrorMessage(ERROR_TITLE, "Die Datei \"" + name + "\" konnte nicht gelesen werden, falscher Inhalt!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
sendErrorMessage(ERROR_TITLE, "Die Datei \"" + name + "\" konnte nicht gelesen werden, falscher Inhalt!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sendErrorMessage(ERROR_TITLE, "Die Datei \"" + name + "\" konnte nicht gelesen werden, falscher Inhalt!");
|
||||
return false;
|
||||
}
|
||||
if (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (!line.startsWith("Inspektionsprotokoll")) {
|
||||
LOGGER.error("Exspected \"Inspektionsprotokoll\" in second line");
|
||||
sendErrorMessage(ERROR_TITLE, "Die Datei \"" + name + "\" konnte nicht gelesen werden, falscher Inhalt!");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
sendErrorMessage(ERROR_TITLE, "Die Datei \"" + name + "\" konnte nicht gelesen werden, falscher Inhalt!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private synchronized Company createCompanyFromPage(Scanner scanner) {
|
||||
Company output = new Company();
|
||||
output.setStatus(Status.ACTIVE);
|
||||
Company loaded = null;
|
||||
|
||||
String line = scanner.nextLine();
|
||||
line = line.replace("Firmenname", "").trim();
|
||||
loaded = companyController.getCompanyByName(line);
|
||||
if (loaded != null) {
|
||||
loaded = createAddressForCompany(scanner, loaded);
|
||||
return loaded;
|
||||
}
|
||||
output.setName(line);
|
||||
output = createAddressForCompany(scanner, output);
|
||||
|
||||
line = scanner.nextLine();
|
||||
line = line.replace("Kundennummer", "").trim();
|
||||
output.setKundenNr(line);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private Company createAddressForCompany(Scanner scanner, Company company) {
|
||||
if (company.getAddresses() == null) {
|
||||
company.setAddresses(new HashSet<>());
|
||||
|
||||
}
|
||||
String line = scanner.nextLine();
|
||||
String strNr = line.replace("Straße/Hsnr.", "").trim();
|
||||
|
||||
line = scanner.nextLine();
|
||||
String plzOrt = line.replace("Plz/Ort", "").trim();
|
||||
|
||||
line = scanner.nextLine();
|
||||
String country = line.replace("Staat", "").trim();
|
||||
|
||||
for (CompanyAddress add : company.getAddresses()) {
|
||||
if (!strNr.contains(add.getStreet())) {
|
||||
continue;
|
||||
}
|
||||
if (!strNr.contains(add.getNumber())) {
|
||||
continue;
|
||||
}
|
||||
if (!plzOrt.contains(add.getPostnumber().toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return company;
|
||||
}
|
||||
|
||||
CompanyAddress addr = new CompanyAddress();
|
||||
|
||||
addr.setCompany(company);
|
||||
Matcher streetMatcher = streetPattern.matcher(strNr);
|
||||
streetMatcher.find();
|
||||
addr.setStreet(streetMatcher.group(1));
|
||||
addr.setNumber(streetMatcher.group(2));
|
||||
|
||||
Matcher countyMachter = countyPattern.matcher(plzOrt);
|
||||
countyMachter.find();
|
||||
addr.setPostnumber(Integer.valueOf(countyMachter.group(1)));
|
||||
addr.setCounty(countyMachter.group(2));
|
||||
|
||||
addr.setPlace(addr.getCounty());
|
||||
addr.setCountry(country);
|
||||
|
||||
company.getAddresses().add(addr);
|
||||
|
||||
return company;
|
||||
}
|
||||
|
||||
private Machine createMachineFromPage(Scanner scanner) {
|
||||
Machine output = new Machine();
|
||||
output.setMachineStatus(MachineStatus.ACTIVE);
|
||||
String cleaned;
|
||||
String nullValue = "-/-";
|
||||
String line = scanner.nextLine();
|
||||
|
||||
System.out.println(line);
|
||||
|
||||
if (line.startsWith("Bezeichnung")) {
|
||||
cleaned = line.replace("Bezeichnung ", "").trim();
|
||||
output.setName(cleaned);
|
||||
//Skip Standort line
|
||||
scanner.nextLine();
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("Hersteller")) {
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("Maschinenart")) {
|
||||
cleaned = line.replace("Maschinenart", "").trim();
|
||||
output.setMachineType(MachineType.getByString(cleaned));
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("Modell/Typ")) {
|
||||
cleaned = line.replace("Modell/Typ ", "").trim();
|
||||
if (!cleaned.contains(nullValue)) {
|
||||
output.setModellType(cleaned);
|
||||
}
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("Maschinen-Nr.")) {
|
||||
cleaned = line.replace("Maschinen-Nr. ", "").trim();
|
||||
if (!cleaned.contains(nullValue)) {
|
||||
output.setMachineNr(cleaned);
|
||||
}
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("Inventar-Nr.")) {
|
||||
cleaned = line.replace("Inventar-Nr. ", "").trim();
|
||||
if (!cleaned.contains(nullValue)) {
|
||||
output.setInventarNr(cleaned);
|
||||
}
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("Kostenstelle")) {
|
||||
cleaned = line.replace("Kostenstelle ", "").trim();
|
||||
if (!cleaned.contains(nullValue)) {
|
||||
output.setCostCenter(cleaned);
|
||||
}
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("Baujahr")) {
|
||||
cleaned = line.replace("Baujahr ", "").trim();
|
||||
if (!cleaned.contains(nullValue)) {
|
||||
output.setBuildingYear(Integer.valueOf(cleaned));
|
||||
}
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("Umbau-Jahr")) {
|
||||
cleaned = line.replace("Umbau-Jahr ", "").trim();
|
||||
if (!cleaned.contains(nullValue)) {
|
||||
output.setChangeYear(Integer.valueOf(cleaned));
|
||||
}
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("B.2")) {
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("Norm 'sicherheitsbez. Teile einer Steuerung'")) {
|
||||
output.setControlParts(ControlParts.getFromString(line));
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("Norm 'Anordnung/ Annäherung'")) {
|
||||
output.setArrayApproach(ArrayApproach.getFromString(line));
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("Norm 'Anw. von AOPD/AOPDDR'")) {
|
||||
output.setAopd_aopddr(AOPD_AOPDDR.getFromString(line));
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
|
||||
if (line.startsWith("B.3")) {
|
||||
line = scanner.nextLine();
|
||||
while (!line.startsWith("Bemerkungen zur gesamten Maschine")) {
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
cleaned = line.replace("Bemerkungen zur gesamten Maschine ", "").trim();
|
||||
if (!cleaned.contains(nullValue)) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(cleaned);
|
||||
while (!(line = scanner.nextLine()).startsWith("Monat der n")) {
|
||||
builder.append(line);
|
||||
}
|
||||
|
||||
output.setComment(builder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private Location createLocationFromPage(Scanner scanner, Set<Location> loadedData) {
|
||||
String locName = null;
|
||||
while (locName == null && scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (line.startsWith("Maschinenstandort")) {
|
||||
locName = line.replace("Maschinenstandort ", "").trim();
|
||||
}
|
||||
}
|
||||
|
||||
Location location = null;
|
||||
if (!loadedData.isEmpty()) {
|
||||
for (Location loc : loadedData) {
|
||||
if (loc.getName().equals(locName)) {
|
||||
location = loc;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (location == null) {
|
||||
location = new Location();
|
||||
location.setName(locName);
|
||||
loadedData.add(location);
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
private List<SecurityArea> createSecurityAreasFromPage(Scanner scanner) {
|
||||
SecurityArea area = new SecurityArea();
|
||||
List<SecurityArea> output = new ArrayList<>();
|
||||
String line;
|
||||
|
||||
while (scanner.hasNextLine()) {
|
||||
line = scanner.nextLine();
|
||||
|
||||
//Skip headline
|
||||
if (line.startsWith("C. Schutzbereich")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Matcher areaMatcher = areaPattern.matcher(line);
|
||||
|
||||
//Start of a new Schutzbereich
|
||||
if (areaMatcher.find()) {
|
||||
area = new SecurityArea();
|
||||
area = extractSecurityAreaData(scanner, line, area);
|
||||
area.setSecurityDevices(new ArrayList<>());
|
||||
area.setDangerPoints(new ArrayList<>());
|
||||
area.setSwitchingDevices(new ArrayList<>());
|
||||
output.add(area);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//If there is one or Security Devices
|
||||
if (SecurityType.getByString(line) != null) {
|
||||
SecurityDevice dev = createSecurityDeviceFromPage(scanner, line);
|
||||
if (dev != null) {
|
||||
dev.setArea(area);
|
||||
area.getSecurityDevices().add(dev);
|
||||
}
|
||||
}
|
||||
|
||||
//If there is a Schaltkomponente(Switchingdevice)
|
||||
if (line.startsWith("Schaltkomponente:")) {
|
||||
SwitchingDevice swd = createSwitchingDeviceFromPage(scanner, line);
|
||||
if (swd != null) {
|
||||
swd.setArea(area);
|
||||
area.getSwitchingDevices().add(swd);
|
||||
}
|
||||
}
|
||||
//Gefahrenpunkte coming last
|
||||
if (line.startsWith("Gefahrpunkt:")) {
|
||||
DangerPoint dp = null;
|
||||
try {
|
||||
dp = createDangerPointFromPage(scanner, line, area.getSecurityDevices());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
if (dp != null) {
|
||||
dp.setSecurityArea(area);
|
||||
area.getDangerPoints().add(dp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
//Starts at position "C\\.\\d)" e.g.: "C.1" Header of SecurityArea
|
||||
private SecurityArea extractSecurityAreaData(Scanner scanner, String start, SecurityArea area) {
|
||||
start = start.replaceFirst("C\\.\\d+ ", "");
|
||||
start = start.replaceFirst("\\d+-\\d+ - Seite \\d+\\/\\d+", "");
|
||||
area.setName(start.trim());
|
||||
String line;
|
||||
scanner.nextLine();
|
||||
|
||||
//Next 5 lines contains data for area
|
||||
line = scanner.nextLine();
|
||||
area.setProtectionType(ProtectionType.getFromString(line));
|
||||
|
||||
line = scanner.nextLine();
|
||||
area.setMountingPosition(MountingPosition.getFromString(line));
|
||||
|
||||
line = scanner.nextLine().replace("Werkzeug-/ Vorrichtungsnr. ", "");
|
||||
if (!line.contains("-/-")) {
|
||||
area.setToolNr(line.replace("", ""));
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
area.setOverrunMeasurementType(OverrunMeasurementType.getFromString(line));
|
||||
|
||||
line = scanner.nextLine();
|
||||
area.setApproachSpeed(ApproachSpeed.getFromString(line));
|
||||
|
||||
System.out.println(area);
|
||||
return area;
|
||||
}
|
||||
|
||||
private SecurityDevice createSecurityDeviceFromPage(Scanner scanner, String line) {
|
||||
SecurityDevice output = new SecurityDevice();
|
||||
|
||||
System.out.println(line);
|
||||
|
||||
output.setType(SecurityType.getByString(line));
|
||||
output.setDescription(line.replace(output.getType().getName() + ":", "").trim());
|
||||
|
||||
//Creation of Manufacturer not so Easy for device
|
||||
line = scanner.nextLine();
|
||||
if (!line.startsWith("Hersteller")) {
|
||||
return null;
|
||||
}
|
||||
line = line.replace("Hersteller", "").trim();
|
||||
output.setCompany(securityDeviceCompanyController.getByName(line));
|
||||
|
||||
//Not clear if Role is printed on Laserscanner
|
||||
if (output.getType() != SecurityType.LASERRSCANNER) {
|
||||
line = scanner.nextLine();
|
||||
output.setDeviceRole(DeviceRole.getByString(line));
|
||||
}
|
||||
line = scanner.nextLine();
|
||||
|
||||
if (line.startsWith("Rolle")) {
|
||||
line = scanner.nextLine();
|
||||
}
|
||||
line = line.replace("Sicherheitskategorie / Typ", "").trim();
|
||||
output.setSecurityCategory(SecurityCategory.getByString(line));
|
||||
|
||||
line = scanner.nextLine();
|
||||
output.setSfAlignment(SfAlignment.getbyString(line));
|
||||
|
||||
line = scanner.nextLine();
|
||||
output.setMutingBlankingModus(MutingBlankingModus.getbyString(line));
|
||||
|
||||
line = scanner.nextLine();
|
||||
output.setMutingSignals(MutingSignals.getByString(line));
|
||||
|
||||
line = scanner.nextLine();
|
||||
line = line.replace("Serien-Nr(n). Sender/Optikteil/SK", "").trim();
|
||||
output.setSerialNrSender(line);
|
||||
|
||||
line = scanner.nextLine();
|
||||
line = line.replace("Serien-Nr(n). Empfänger/Refl.", "").trim();
|
||||
output.setSerialNrReceiver(line);
|
||||
|
||||
line = scanner.nextLine();
|
||||
output.seteSPE_Paramable(Option.getByString(line));
|
||||
|
||||
line = scanner.nextLine();
|
||||
line = line.replace("Identifikation der Konfiguration", "").trim();
|
||||
output.setConfigID(line);
|
||||
|
||||
line = scanner.nextLine();
|
||||
line = line.replace("RFID", "").trim();
|
||||
output.setRfid(line);
|
||||
|
||||
line = scanner.nextLine();
|
||||
output.setComponent(Component.getByString(line));
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Schutzfeldbreite (mm)", "").trim();
|
||||
output.setsFdWidth(Integer.valueOf(line.split(";")[0]));
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Vert.-SF: Höhe, Horiz.-SF: Tiefe (mm)", "").trim();
|
||||
output.setsFHeightDepth(Integer.valueOf(line));
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Höhe ob. Strahl ü. Bezugsebene (mm)", "").trim();
|
||||
output.setHeightTopRay(Integer.valueOf(line));
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Höhe SF ü. Bezugsebene (mm)", "").trim();
|
||||
output.setHeightOverReference(Integer.valueOf(line));
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Abstand zum Maschinentisch (mm)", "").trim();
|
||||
output.setDistanceTable(Integer.valueOf(line));
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Detektionsvermögen (mm) [=>C]", "").trim();
|
||||
output.setDetectionCapacity(Integer.valueOf(line));
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Ansprechzeit t1 (ms)", "").trim();
|
||||
output.setResponseTime(Integer.valueOf(line));
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private SwitchingDevice createSwitchingDeviceFromPage(Scanner scanner, String line) {
|
||||
SwitchingDevice output = new SwitchingDevice();
|
||||
|
||||
line = line.replace("Schaltkomponente:", "").trim();
|
||||
output.setDescription(line);
|
||||
|
||||
line = scanner.nextLine();
|
||||
line = line.replace("Hersteller", "").trim();
|
||||
output.setCompany(securityDeviceCompanyController.getByName(line));
|
||||
|
||||
line = scanner.nextLine();
|
||||
line = line.replace("Sicherheitskategorie / Typ", "").trim();
|
||||
output.setSecurityCategory(SecurityCategory.getByString(line));
|
||||
|
||||
line = scanner.nextLine();
|
||||
line = line.replace("Serien-Nr(n). Sender/Optikteil/SK", "").trim();
|
||||
output.setSerialNrSender(line);
|
||||
|
||||
line = scanner.nextLine();
|
||||
line = line.replace("Identifikation der Konfiguration", "").trim();
|
||||
output.setConfigID(line);
|
||||
|
||||
line = scanner.nextLine();
|
||||
output.setComponent(Component.getByString(line));
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Bemerkung", "").trim();
|
||||
output.setComment(line);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private DangerPoint createDangerPointFromPage(Scanner scanner, String line, List<SecurityDevice> devices) {
|
||||
DangerPoint dp = new DangerPoint();
|
||||
MeasuringPoint mp = new MeasuringPoint();
|
||||
dp.setMeasuringPoint(mp);
|
||||
mp.setDangerPoint(dp);
|
||||
|
||||
line = line.replace("Gefahrpunkt:", "").trim();
|
||||
dp.setDescription(line);
|
||||
|
||||
System.out.println(line);
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (line.matches("C\\.\\d+\\.\\d+.*")) {
|
||||
LOGGER.warn("Empty Dangerpoint {}", dp.getDescription());
|
||||
return null;
|
||||
}
|
||||
|
||||
for (SecurityDevice dev : devices) {
|
||||
if (line.contains(dev.getDescription())) {
|
||||
dp.setSecurityDevice(dev);
|
||||
}
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Ist-Abstand (mm)", "").trim();
|
||||
mp.setActualDistance(Integer.valueOf(line));
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Abstand lt. Angabe (mm)", "").trim();
|
||||
mp.setDistanceSpec(Integer.valueOf(line));
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Nachlaufzeit lt. Angabe (ms)", "").trim();
|
||||
mp.setFollowUpTimeSpec(Integer.valueOf(line));
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Nachlaufweg lt. Angabe (mm)", "").trim();
|
||||
mp.setFollowUpCoveredDistanceSpec(Integer.valueOf(line));
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("Höhe Gefahrpunkt (mm)", "").trim();
|
||||
mp.setHeight(Integer.valueOf(line));
|
||||
}
|
||||
|
||||
line = scanner.nextLine();
|
||||
if (!line.contains("-/-")) {
|
||||
line = line.replace("CRT/CRO (mm) - ersetzt formelbasierte Berechnung!", "").trim();
|
||||
mp.setCrtCro(Integer.valueOf(line));
|
||||
}
|
||||
|
||||
return dp;
|
||||
}
|
||||
|
||||
private Map<String, byte[]> createCompanyDataFromPDF() {
|
||||
Map<String, byte[]> output = new HashMap<>();
|
||||
for (UploadedFile f : files.getFiles()) {
|
||||
if (f.getContentType().contains("pdf")) {
|
||||
try {
|
||||
output.put(f.getFileName(), f.getInputStream().readAllBytes());
|
||||
} catch (IOException ex) {
|
||||
LOGGER.error(ex);
|
||||
sendErrorMessage(ERROR_TITLE, "Die Datei \"" + f.getFileName() + "\" konnte nicht gelesen werden!");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (f.getContentType().contains("zip")) {
|
||||
output.putAll(getFilesFromZip(f));
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private Map<String, byte[]> getFilesFromZip(UploadedFile f) {
|
||||
Map<String, byte[]> fileMap = new HashMap<>();
|
||||
|
||||
try {
|
||||
ZipInputStream zipStream = new ZipInputStream(f.getInputStream());
|
||||
ZipEntry zipEntry = zipStream.getNextEntry();
|
||||
while (zipEntry != null) {
|
||||
if (zipEntry.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (zipEntry.getName().toLowerCase().endsWith(".pdf")) {
|
||||
fileMap.put(zipEntry.getName(), zipStream.readAllBytes());
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
LOGGER.error(ex);
|
||||
return null;
|
||||
}
|
||||
|
||||
return fileMap;
|
||||
}
|
||||
|
||||
private File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
|
||||
File destFile = new File(destinationDir, zipEntry.getName());
|
||||
|
||||
String destDirPath = destinationDir.getCanonicalPath();
|
||||
String destFilePath = destFile.getCanonicalPath();
|
||||
|
||||
if (!destFilePath.startsWith(destDirPath + File.separator)) {
|
||||
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
|
||||
}
|
||||
|
||||
return destFile;
|
||||
}
|
||||
|
||||
public String getAllowedTypesRE() {
|
||||
StringBuilder output = new StringBuilder(allowedFileTypes.size() * 4);
|
||||
|
||||
output.append("/(\\.|\\/)(");
|
||||
|
||||
for (int i = 0; i < allowedFileTypes.size(); i++) {
|
||||
output.append(allowedFileTypes.get(i).getExtension());
|
||||
if (i < allowedFileTypes.size() - 1) {
|
||||
output.append('|');
|
||||
}
|
||||
}
|
||||
|
||||
output.append(")$/");
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
public static long getSizeLimit() {
|
||||
return sizeLimit;
|
||||
}
|
||||
|
||||
public UploadedFiles getFiles() {
|
||||
return files;
|
||||
}
|
||||
|
||||
public void setFiles(UploadedFiles files) {
|
||||
this.files = files;
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package controller.company;
|
||||
|
||||
import business.company.CompanyManager;
|
||||
import java.io.Serializable;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.inject.Named;
|
||||
import model.company.Company;
|
||||
|
||||
/**
|
||||
* Dieser Controller speichert die zuletzt ausgewählte Firma in der Benutzersitzung,
|
||||
* damit diese Information über mehrere Seiten hinweg erhalten bleibt.
|
||||
*/
|
||||
@Named
|
||||
@SessionScoped
|
||||
public class SessionCompanyController implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@EJB
|
||||
CompanyManager companyManager;
|
||||
|
||||
private Company selectedCompany;
|
||||
private Long selectedCompanyId;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
selectedCompany = null;
|
||||
selectedCompanyId = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert die ausgewählte Firma für die Benutzersitzung
|
||||
* @param company Die ausgewählte Firma
|
||||
*/
|
||||
public void setSelectedCompany(Company company) {
|
||||
this.selectedCompany = company;
|
||||
if (company != null) {
|
||||
this.selectedCompanyId = company.getId();
|
||||
} else {
|
||||
this.selectedCompanyId = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die ausgewählte Firma zurück. Wenn die Firma nicht vollständig geladen wurde,
|
||||
* wird sie aus der Datenbank neu geladen.
|
||||
* @return Die ausgewählte Firma oder null wenn keine ausgewählt wurde
|
||||
*/
|
||||
public Company getSelectedCompany() {
|
||||
if (selectedCompany == null && selectedCompanyId != null) {
|
||||
// Lade die Firma neu, falls notwendig
|
||||
selectedCompany = companyManager.find(selectedCompanyId);
|
||||
}
|
||||
return selectedCompany;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt zurück, ob eine Firma ausgewählt wurde
|
||||
* @return true wenn eine Firma ausgewählt wurde, sonst false
|
||||
*/
|
||||
public boolean hasSelectedCompany() {
|
||||
return selectedCompanyId != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht die ausgewählte Firma
|
||||
*/
|
||||
public void clearSelectedCompany() {
|
||||
selectedCompany = null;
|
||||
selectedCompanyId = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.machine.ContactManager;
|
||||
import controller.AbstractController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.machine.Contact;
|
||||
import model.machine.Manufacturer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class ContactController extends AbstractController<Contact>{
|
||||
|
||||
private static final String[] WIDGETS = {"dlgCreateCustomer", "dlgEditCustomer"};
|
||||
|
||||
@EJB
|
||||
ContactManager contactManager;
|
||||
|
||||
@Inject
|
||||
ManufacturerController manufacturerController;
|
||||
|
||||
public ContactController() {
|
||||
super();
|
||||
setSelected(new Contact());
|
||||
setCreated(new Contact());
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Contact> getManager() {
|
||||
return contactManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(new Contact());
|
||||
setCreated(new Contact());
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public void addFromCreated(){
|
||||
if (getCreated() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
Manufacturer manufacturer = manufacturerController.getSelected();
|
||||
|
||||
if (manufacturer == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
List<Contact> contacts = manufacturer.getContacts();
|
||||
if (contacts == null) {
|
||||
contacts = new ArrayList<>();
|
||||
}
|
||||
|
||||
Long id = createFakeID(contacts);
|
||||
|
||||
getCreated().setId(id);
|
||||
getCreated().setManufacturer(manufacturer);
|
||||
|
||||
contacts.add(getCreated());
|
||||
manufacturer.setContacts(contacts);
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Kontakt wurde erstellt!");
|
||||
clearCreated();
|
||||
|
||||
closeDialogs(WIDGETS);
|
||||
}
|
||||
|
||||
public void editSelected(){
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
closeDialogs(WIDGETS);
|
||||
return;
|
||||
}
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Kontakt wurde bearbeitet!");
|
||||
closeDialogs(WIDGETS);
|
||||
clearSelected();
|
||||
}
|
||||
|
||||
public void deleteSelected(){
|
||||
if (getSelected() == null || manufacturerController.getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
String message = String.format("Die Kontakt %s, %s, %s wurde erfolgreich entfernt", getSelected().getEmail(), getSelected().getLastname(), getSelected().getFirstname());
|
||||
manufacturerController.getSelected().getContacts().remove(getSelected());
|
||||
|
||||
if (getSelected().getId() != null && getSelected().getId() > 0) {
|
||||
contactManager.remove(getSelected());
|
||||
}
|
||||
|
||||
clearSelected();
|
||||
sendInfoMessage(SUCCESS_TITLE, message);
|
||||
}
|
||||
|
||||
public void save(){
|
||||
List<Contact> contacts = manufacturerController.getSelected().getContacts();
|
||||
|
||||
if (contacts == null || contacts.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
contacts.forEach(contact -> {
|
||||
if (contact.getId() != null && contact.getId() < 0) {
|
||||
contact.setId(null);
|
||||
}
|
||||
|
||||
contactManager.save(contact);
|
||||
});
|
||||
}
|
||||
|
||||
public void clearCreated(){
|
||||
setCreated(new Contact());
|
||||
}
|
||||
|
||||
public void clearSelected(){
|
||||
setSelected(new Contact());
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.machine.DangerPointManager;
|
||||
import controller.AbstractController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.security.DangerPoint;
|
||||
import model.security.MeasuringPoint;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class DangerPointController extends AbstractController<DangerPoint>{
|
||||
|
||||
private static final String[] WIDGETS = {"dlgCreDP", "dlgEditDP"};
|
||||
|
||||
@EJB
|
||||
DangerPointManager dangerPointManager;
|
||||
|
||||
@Inject
|
||||
SecurityDeviceController securityDeviceController;
|
||||
|
||||
@Inject
|
||||
SecurityAreaController securityAreaController;
|
||||
|
||||
public DangerPointController() {
|
||||
super();
|
||||
setSelected(new DangerPoint());
|
||||
getSelected().setMeasuringPoint(new MeasuringPoint());
|
||||
setCreated(new DangerPoint());
|
||||
getCreated().setMeasuringPoint(new MeasuringPoint());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<DangerPoint> getManager() {
|
||||
return dangerPointManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(new DangerPoint());
|
||||
getSelected().setMeasuringPoint(new MeasuringPoint());
|
||||
setCreated(new DangerPoint());
|
||||
getCreated().setMeasuringPoint(new MeasuringPoint());
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public void addFromCreated(){
|
||||
getCreated().setSecurityArea(securityAreaController.getSelected());
|
||||
dangerPointManager.save(getCreated());
|
||||
|
||||
List<DangerPoint> dangerPoints = securityAreaController.getSelected().getDangerPoints();
|
||||
|
||||
if (dangerPoints == null) {
|
||||
dangerPoints = new ArrayList<>();
|
||||
securityAreaController.getSelected().setDangerPoints(dangerPoints);
|
||||
}
|
||||
|
||||
dangerPoints.add(getCreated());
|
||||
securityAreaController.saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Gefahrenpunkt wurde hinzugefügt");
|
||||
|
||||
clearEntries();
|
||||
closeDialogs(WIDGETS);
|
||||
}
|
||||
|
||||
public void addFromSelected(){
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Gefahrenpunkt wurde bearbeitet");
|
||||
dangerPointManager.save(getSelected());
|
||||
clearEntries();
|
||||
closeDialogs(WIDGETS);
|
||||
}
|
||||
|
||||
public void copy(){
|
||||
DangerPoint dp = new DangerPoint(getSelected());
|
||||
dangerPointManager.save(dp);
|
||||
|
||||
List<DangerPoint> dangerPoints = securityAreaController.getSelected().getDangerPoints();
|
||||
|
||||
if (dangerPoints == null) {
|
||||
dangerPoints = new ArrayList<>();
|
||||
securityAreaController.getSelected().setDangerPoints(dangerPoints);
|
||||
}
|
||||
|
||||
dangerPoints.add(dp);
|
||||
securityAreaController.saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Gefahrenpunkt wurde kopiert");
|
||||
clearEntries();
|
||||
}
|
||||
|
||||
public void deleteSelected(){
|
||||
dangerPointManager.remove(getSelected());
|
||||
|
||||
List<DangerPoint> dangerPoints = securityAreaController.getSelected().getDangerPoints();
|
||||
|
||||
if (dangerPoints == null) {
|
||||
dangerPoints = new ArrayList<>();
|
||||
}
|
||||
|
||||
dangerPoints.remove(getSelected());
|
||||
securityAreaController.getSelected().setDangerPoints(dangerPoints);
|
||||
securityAreaController.saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Gefahrenpunkt wurde gelöscht");
|
||||
clearEntries();
|
||||
}
|
||||
|
||||
public void calcSecurityDistance(DangerPoint dp){
|
||||
if (dp == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package controller.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.company.CompanyManager;
|
||||
import business.company.LocationManager;
|
||||
import business.machine.MachineManager;
|
||||
import business.machine.ManufacturerManager;
|
||||
import controller.AbstractController;
|
||||
import controller.company.CompanyController;
|
||||
import controller.company.LocationController;
|
||||
import controller.company.SessionCompanyController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import model.machine.Machine;
|
||||
import model.machine.enums.MachineStatus;
|
||||
import model.machine.enums.MachineType;
|
||||
import model.machine.enums.norms.AOPD_AOPDDR;
|
||||
import model.machine.enums.norms.ArrayApproach;
|
||||
import model.machine.enums.norms.ControlParts;
|
||||
import model.company.Company;
|
||||
import model.company.Location;
|
||||
import model.machine.Manufacturer;
|
||||
import model.machine.enums.norms.NothaltElectric;
|
||||
import model.machine.enums.norms.NothaltGestaltung;
|
||||
import model.machine.enums.norms.NothaltVerriegel;
|
||||
import model.security.SecurityArea;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@ViewScoped
|
||||
@Named
|
||||
public class MachineController extends AbstractController<Machine> {
|
||||
|
||||
@Inject
|
||||
CompanyController companyController;
|
||||
|
||||
@Inject
|
||||
LocationController locationController;
|
||||
|
||||
@Inject
|
||||
SessionCompanyController sessionCompanyController;
|
||||
|
||||
@EJB
|
||||
LocationManager locationManager;
|
||||
|
||||
@EJB
|
||||
MachineManager machineManager;
|
||||
|
||||
@EJB
|
||||
ManufacturerManager manufacturerManager;
|
||||
|
||||
@EJB
|
||||
CompanyManager companyManager;
|
||||
|
||||
private String[] widgets = {"dlgMoveMac", "dlgEditMac", "dlgCreMac"};
|
||||
|
||||
public MachineController() {
|
||||
setSelected(new Machine());
|
||||
setCreated(new Machine());
|
||||
setEntities(new ArrayList<>());
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@Transactional
|
||||
public void init() {
|
||||
if (companyController != null && companyController.getSelected() != null) {
|
||||
companyController.addFromSelected();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(new Machine());
|
||||
setCreated(new Machine());
|
||||
getEntities().clear();
|
||||
companyController.clearEntries();
|
||||
locationController.clearEntries();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
locationController.getLocations()
|
||||
.stream()
|
||||
.map(Location::getMachines)
|
||||
.flatMap(List::stream)
|
||||
.forEach(mac -> {
|
||||
if (mac.getId() == null) {
|
||||
machineManager.create(mac);
|
||||
return;
|
||||
}
|
||||
if (mac.getId() < 0) {
|
||||
mac.setId(null);
|
||||
machineManager.create(mac);
|
||||
return;
|
||||
}
|
||||
machineManager.edit(mac);
|
||||
});
|
||||
|
||||
locationController.saveAllToCompany();
|
||||
companyController.saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Maschinen wurden gespeichert zu Firma \"" + companyController.getName() + "\"");
|
||||
clearEntries();
|
||||
}
|
||||
|
||||
public void removeManufacturerFromSelected(){
|
||||
if (getSelected() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
removeManufacturer(getSelected());
|
||||
}
|
||||
|
||||
public void moveMachineToLocation() {
|
||||
if (getSelected() == null || locationController.getTarget() == null) {
|
||||
errorMessage();
|
||||
closeDialogs(widgets);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!getSelected().getLocation().getMachines().remove(getSelected())){
|
||||
errorMessage();
|
||||
closeDialogs(widgets);
|
||||
return;
|
||||
}
|
||||
|
||||
getSelected().setLocation(locationController.getTarget());
|
||||
|
||||
if(!machineManager.save(getSelected())){
|
||||
errorMessage();
|
||||
getSelected().setLocation(locationController.getSelected());
|
||||
locationController.getSelected().addMachine(getSelected());
|
||||
closeDialogs(widgets);
|
||||
return;
|
||||
}
|
||||
|
||||
locationController.getTarget().addMachine(getSelected());
|
||||
|
||||
if(!locationManager.save(locationController.getTarget())){
|
||||
errorMessage();
|
||||
getSelected().setLocation(locationController.getSelected());
|
||||
locationController.getSelected().addMachine(getSelected());
|
||||
closeDialogs(widgets);
|
||||
return;
|
||||
}
|
||||
|
||||
locationController.saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Maschine wurden vorschoben zu Standort \"" + locationController.getTarget().getName() + "\"");
|
||||
locationController.setTarget(null);
|
||||
closeDialogs(widgets);
|
||||
}
|
||||
|
||||
public void removeManufacturerFromCreated(){
|
||||
if (getCreated() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
removeManufacturer(getCreated());
|
||||
}
|
||||
|
||||
private void removeManufacturer(Machine machine) {
|
||||
Manufacturer man = machine.getManufacturer();
|
||||
machine.setManufacturer(null);
|
||||
if (man == null) {
|
||||
return;
|
||||
}
|
||||
if (man.getId() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
man = manufacturerManager.reloadWithMachines(man);
|
||||
man.getMachines().remove(getCreated());
|
||||
|
||||
manufacturerManager.save(man);
|
||||
}
|
||||
|
||||
public void addMachineToLocation() {
|
||||
if (getCreated() == null || locationController.getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
Machine mac = new Machine(getCreated());
|
||||
mac.setLocation(locationController.getSelected());
|
||||
Long fakeId = createFakeID(locationController.getSelected().getMachines());
|
||||
mac.setId(fakeId);
|
||||
locationController.getSelected().addMachine(mac);
|
||||
|
||||
setCreated(new Machine());
|
||||
sendInfoMessage(SUCCESS_TITLE, "Maschine Nr. " + (locationController.getSelected().getMachines().indexOf(mac) + 1) + " wurde zu Standort \"" + locationController.getSelected().getName() + "\" hinzugefügt.");
|
||||
}
|
||||
|
||||
public void copySelectedMachineToLocation(){
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
if (locationController.getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
Machine copy = machineManager.copyMachine(getSelected());
|
||||
|
||||
if(copy != null){
|
||||
locationController.getSelected().addMachine(copy);
|
||||
locationController.saveSelected();
|
||||
successMessage();
|
||||
} else {
|
||||
errorMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public void editSelectedMachine() {
|
||||
sendInfoMessage(SUCCESS_TITLE, "Maschine Nr. \"" + (locationController.getSelected().getMachines().indexOf(getSelected()) + 1) + "\" wurde bei Standort \"" + locationController.getSelected().getName() + "\" geändert.");
|
||||
setSelected(new Machine());
|
||||
}
|
||||
|
||||
public boolean saveSelected(){
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getSelected().getId() == null || getSelected().getId() > 0) {
|
||||
machineManager.save(getSelected());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (getSelected().getId() < 0) {
|
||||
getSelected().setId(null);
|
||||
machineManager.save(getSelected());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void clearSelected() {
|
||||
setSelected(new Machine());
|
||||
}
|
||||
|
||||
public void deleteSelected() {
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
locationController.getSelected().getMachines().remove(getSelected());
|
||||
getSelected().getLocation().getMachines().remove(getSelected());
|
||||
locationManager.save(getSelected().getLocation());
|
||||
locationController.saveSelected();
|
||||
|
||||
getSelected().setLocation(null);
|
||||
saveSelected();
|
||||
|
||||
if (getSelected().getId() > 0) {
|
||||
if(machineManager.remove(getSelected())){
|
||||
companyController.addFromSelected();
|
||||
sendInfoMessage(SUCCESS_TITLE, "Machine \"" + getSelected().getName() + "\" wurde entfernt");
|
||||
} else {
|
||||
errorMessage();
|
||||
}
|
||||
}
|
||||
setSelected(new Machine());
|
||||
}
|
||||
|
||||
public void addSecurityAreaToSelected(SecurityArea area){
|
||||
if (area == null){
|
||||
LOGGER.error("Tried to add null to Machine");
|
||||
return;
|
||||
}
|
||||
|
||||
if (getSelected().getSecurityArea() == null){
|
||||
getSelected().setSecurityArea(new ArrayList<>());
|
||||
}
|
||||
|
||||
getSelected().getSecurityArea().add(area);
|
||||
}
|
||||
|
||||
public MachineStatus[] getAllStatus() {
|
||||
return MachineStatus.values();
|
||||
}
|
||||
|
||||
public MachineType[] getAllTypes() {
|
||||
return MachineType.values();
|
||||
}
|
||||
|
||||
public ControlParts[] getControlParts() {
|
||||
return ControlParts.values();
|
||||
}
|
||||
|
||||
public ArrayApproach[] getArrayApproach() {
|
||||
return ArrayApproach.values();
|
||||
}
|
||||
|
||||
public AOPD_AOPDDR[] getAopd_aopddr() {
|
||||
return AOPD_AOPDDR.values();
|
||||
}
|
||||
|
||||
public NothaltElectric[] getNothaltElectrics(){
|
||||
return NothaltElectric.values();
|
||||
}
|
||||
|
||||
public NothaltGestaltung[] getNothaltGestaltungs(){
|
||||
return NothaltGestaltung.values();
|
||||
}
|
||||
|
||||
public NothaltVerriegel[] getNothaltVerriegels(){
|
||||
return NothaltVerriegel.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Machine> getManager() {
|
||||
return machineManager;
|
||||
}
|
||||
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.machine.ManufacturerAddressManager;
|
||||
import controller.AbstractController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.machine.Manufacturer;
|
||||
import model.machine.ManufacturerAddress;
|
||||
import org.primefaces.PrimeFaces;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class ManufacturerAdressController extends AbstractController<ManufacturerAddress>{
|
||||
|
||||
private static final String[] WIDGETS = {"dlgAddAddress", "dlgEditAddress"};
|
||||
|
||||
@EJB
|
||||
ManufacturerAddressManager manufacturerAddressManager;
|
||||
|
||||
@Inject
|
||||
ManufacturerController manufacturerController;
|
||||
|
||||
public ManufacturerAdressController() {
|
||||
super();
|
||||
setSelected(new ManufacturerAddress());
|
||||
setCreated(new ManufacturerAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<ManufacturerAddress> getManager() {
|
||||
return manufacturerAddressManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(new ManufacturerAddress());
|
||||
setCreated(new ManufacturerAddress());
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public void deleteSelected(){
|
||||
if (getSelected() == null || manufacturerController.getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
String message = String.format("Die Adresse %s, %s, %s wurde erfolgreich entfernt",
|
||||
getSelected().getCountry(), getSelected().getStreet(), getSelected().getNumber());
|
||||
|
||||
manufacturerController.getSelected().getAdresses().remove(getSelected());
|
||||
|
||||
if (getSelected().getId() != null && getSelected().getId() > 0) {
|
||||
manufacturerAddressManager.remove(getSelected());
|
||||
}
|
||||
|
||||
setSelected(new ManufacturerAddress());
|
||||
sendInfoMessage(SUCCESS_TITLE, message);
|
||||
}
|
||||
|
||||
public void addToSelected(){
|
||||
if (getCreated() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
Manufacturer manufacturer = manufacturerController.getSelected();
|
||||
|
||||
if (manufacturer == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
List<ManufacturerAddress> addresses = manufacturer.getAdresses();
|
||||
if (addresses == null) {
|
||||
addresses = new ArrayList<>();
|
||||
}
|
||||
|
||||
Long id = createFakeID(addresses);
|
||||
|
||||
getCreated().setId(id);
|
||||
getCreated().setManufacturer(manufacturer);
|
||||
|
||||
addresses.add(getCreated());
|
||||
manufacturer.setAdresses(addresses);
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Adresse wurde erstellt!");
|
||||
setCreated(new ManufacturerAddress());
|
||||
closeDialogs(WIDGETS);
|
||||
}
|
||||
|
||||
public void editSelected(){
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
closeDialogs(WIDGETS);
|
||||
return;
|
||||
}
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Adresse wurde bearbeitet!");
|
||||
closeDialogs(WIDGETS);
|
||||
setSelected(new ManufacturerAddress());
|
||||
}
|
||||
|
||||
public void save(){
|
||||
List<ManufacturerAddress> addresses = manufacturerController.getSelected().getAdresses();
|
||||
|
||||
if (addresses == null || addresses.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
addresses.forEach(addr -> {
|
||||
if (addr.getId() != null && addr.getId() < 0) {
|
||||
addr.setId(null);
|
||||
}
|
||||
|
||||
manufacturerAddressManager.save(addr);
|
||||
});
|
||||
}
|
||||
}
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.machine.MachineManager;
|
||||
import business.machine.ManufacturerManager;
|
||||
import controller.AbstractController;
|
||||
import controller.tickets.machine.TicketMachineController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.machine.Manufacturer;
|
||||
import model.machine.Machine;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class ManufacturerController extends AbstractController<Manufacturer>{
|
||||
|
||||
private static final String[] WIDGETS = {"dlgEditComp", "dlgEditComp2"};
|
||||
|
||||
@EJB
|
||||
ManufacturerManager manufacturerManager;
|
||||
|
||||
@EJB
|
||||
MachineManager machineManager;
|
||||
|
||||
@Inject
|
||||
ContactController contactController;
|
||||
|
||||
@Inject
|
||||
ManufacturerAdressController adressController;
|
||||
|
||||
@Inject
|
||||
MachineController machineController;
|
||||
|
||||
@Inject
|
||||
TicketMachineController ticketMachineController;
|
||||
|
||||
private static List<Manufacturer> allManufacturers;
|
||||
|
||||
public ManufacturerController() {
|
||||
setSelected(new Manufacturer());
|
||||
setCreated(new Manufacturer());
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public void loadFromSelected(){
|
||||
if (getSelected() == null || getSelected().getId() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
setSelected(manufacturerManager.reload(getSelected()));
|
||||
closeDialogs(WIDGETS);
|
||||
}
|
||||
|
||||
public void loadFromSelectedAddToMachine(){
|
||||
if (getSelected() == null || getSelected().getId() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
Manufacturer man = machineController.getCreated().getManufacturer();
|
||||
|
||||
if (man != null && man.getId() != null) {
|
||||
machineController.removeManufacturerFromSelected();
|
||||
}
|
||||
|
||||
setSelected(manufacturerManager.reloadWithMachines(getSelected()));
|
||||
machineController.getSelected().setManufacturer(getSelected());
|
||||
|
||||
List<Machine> machines = getSelected().getMachines();
|
||||
if (machines == null) {
|
||||
machines = new ArrayList<>();
|
||||
}
|
||||
|
||||
machines.add(machineController.getSelected());
|
||||
closeDialogs(WIDGETS);
|
||||
}
|
||||
|
||||
public void loadFromSelectedAddToCreatedMachine(){
|
||||
if (getSelected() == null || getSelected().getId() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
Manufacturer man = machineController.getCreated().getManufacturer();
|
||||
|
||||
if (man != null && man.getId() != null) {
|
||||
machineController.removeManufacturerFromCreated();
|
||||
}
|
||||
|
||||
setSelected(manufacturerManager.reloadWithMachines(getSelected()));
|
||||
machineController.getCreated().setManufacturer(getSelected());
|
||||
|
||||
List<Machine> machines = getSelected().getMachines();
|
||||
if (machines == null) {
|
||||
machines = new ArrayList<>();
|
||||
}
|
||||
|
||||
machines.add(machineController.getSelected());
|
||||
closeDialogs(WIDGETS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Manufacturer> getManager() {
|
||||
return manufacturerManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(new Manufacturer());
|
||||
setCreated(new Manufacturer());
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public void saveSelected(){
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
if (getSelected().getId() == null) {
|
||||
if (getSelected().getAdresses() != null) {
|
||||
getSelected().getAdresses().forEach(addr -> addr.setId(null));
|
||||
}
|
||||
if (getSelected().getContacts() != null) {
|
||||
getSelected().getContacts().forEach(contact -> contact.setId(null));
|
||||
}
|
||||
} else {
|
||||
adressController.save();
|
||||
contactController.save();
|
||||
}
|
||||
|
||||
boolean saved = manufacturerManager.save(getSelected());
|
||||
|
||||
if (saved) {
|
||||
refreshAllManufacturers();
|
||||
sendInfoMessage(SUCCESS_TITLE, "Die Firma \"" + getSelected().getName() + "\" wurde erfolgreich gespeichert!");
|
||||
} else {
|
||||
errorMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteSelected(){
|
||||
if (getSelected() == null || getSelected().getId() == null || getSelected().getId() < 0) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
setSelected(manufacturerManager.reloadWithMachines(getSelected()));
|
||||
String message = String.format("Der Hersteller %s wurde gelöscht. %d Maschinen sind nun ohne Hersteller!", getSelected().getName(), getSelected().getMachines() != null ? getSelected().getMachines().size() : 0);
|
||||
|
||||
if (getSelected().getMachines() != null) {
|
||||
getSelected().getMachines().forEach(mac -> {
|
||||
mac.setManufacturer(null);
|
||||
machineManager.save(mac);
|
||||
});
|
||||
}
|
||||
|
||||
manufacturerManager.remove(getSelected());
|
||||
sendInfoMessage(SUCCESS_TITLE, message);
|
||||
clearEntries();
|
||||
refreshAllManufacturers();
|
||||
}
|
||||
|
||||
public void refreshAllManufacturers(){
|
||||
allManufacturers = manufacturerManager.findAll();
|
||||
}
|
||||
|
||||
public List<Manufacturer> getAllManufacturers() {
|
||||
if (allManufacturers == null) {
|
||||
refreshAllManufacturers();
|
||||
}
|
||||
return allManufacturers;
|
||||
}
|
||||
}
|
||||
+428
@@ -0,0 +1,428 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package controller.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.machine.DangerPointManager;
|
||||
import business.machine.SecurityAreaManager;
|
||||
import business.machine.SecurityDeviceManager;
|
||||
import business.machine.SwitchingDeviceManager;
|
||||
import business.questions.QuestionaireManager;
|
||||
import controller.AbstractController;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import controller.company.CompanyController;
|
||||
import controller.company.LocationController;
|
||||
import controller.company.SessionCompanyController;
|
||||
import model.company.Company;
|
||||
import model.machine.Machine;
|
||||
import model.security.SecurityArea;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.primefaces.model.DefaultTreeNode;
|
||||
import org.primefaces.model.TreeNode;
|
||||
import org.primefaces.model.menu.DefaultSubMenu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import model.security.enums.MountingPosition;
|
||||
import model.security.enums.OverrunMeasurementType;
|
||||
import model.security.enums.ProtectionType;
|
||||
import model.company.Location;
|
||||
import model.security.enums.ApproachSpeed;
|
||||
import model.security.DangerPoint;
|
||||
import model.question.Questionaire;
|
||||
import model.security.SecurityAreaQuestionnaire;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@ViewScoped
|
||||
@Named
|
||||
public class SecurityAreaController extends AbstractController<SecurityArea>{
|
||||
|
||||
@EJB
|
||||
SecurityAreaManager securityAreaManager;
|
||||
|
||||
@EJB
|
||||
SecurityDeviceManager deviceManager;
|
||||
|
||||
@EJB
|
||||
DangerPointManager dangerPointManager;
|
||||
|
||||
@EJB
|
||||
SwitchingDeviceManager switchingDeviceManager;
|
||||
|
||||
@EJB
|
||||
QuestionaireManager questionaireManager;
|
||||
|
||||
@Inject
|
||||
MachineController machineController;
|
||||
|
||||
@Inject
|
||||
LocationController locationController;
|
||||
|
||||
@Inject
|
||||
SecurityDeviceController securityDeviceController;
|
||||
|
||||
@Inject
|
||||
CompanyController companyController;
|
||||
|
||||
@Inject
|
||||
SessionCompanyController sessionCompanyController;
|
||||
|
||||
private TreeNode root;
|
||||
private TreeNode selectedNode;
|
||||
|
||||
private Machine machine;
|
||||
|
||||
// Questionnaire-specific properties
|
||||
private Questionaire selectedQuestionnaire;
|
||||
private SecurityAreaQuestionnaire selectedSecurityAreaQuestionnaire;
|
||||
private List<Questionaire> availableQuestionnaires;
|
||||
|
||||
public SecurityAreaController() {
|
||||
setSelected(new SecurityArea());
|
||||
setCreated(new SecurityArea());
|
||||
setEntities(new ArrayList<>());
|
||||
}
|
||||
|
||||
public void save(){
|
||||
securityDeviceController.save();
|
||||
List<SecurityArea> newOnes = new ArrayList<>();
|
||||
companyController.getSelected().getLocations()
|
||||
.stream()
|
||||
.map(loc -> loc.getMachines())
|
||||
.flatMap(List::stream)
|
||||
.map(mac -> mac.getSecurityArea())
|
||||
.flatMap(List::stream)
|
||||
.filter(area -> area.getId() != null && area.getId() < 0)
|
||||
.forEach(area -> {
|
||||
area.setId(null);
|
||||
newOnes.add(area);
|
||||
//securityAreaManager.save(area);
|
||||
});
|
||||
|
||||
securityAreaManager.saveAll(newOnes);
|
||||
|
||||
companyController.saveSelected();
|
||||
sendInfoMessage(SUCCESS_TITLE, "Änderungen wurden gespeichert!");
|
||||
}
|
||||
|
||||
public void addAreaToMachine(){
|
||||
if (getCreated() == null || machineController.getSelected() == null) {
|
||||
errorMessage();
|
||||
LOGGER.error("getCreated {}, getSelected {}", getCreated(), machineController.getSelected());
|
||||
return;
|
||||
}
|
||||
|
||||
getCreated().setMachine(machineController.getSelected());
|
||||
securityAreaManager.save(getCreated());
|
||||
|
||||
machineController.addSecurityAreaToSelected(getCreated());
|
||||
machineController.saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Schutzbereich \"" + getCreated().getName() + "\" wurde erfolgreich zur " +
|
||||
"Maschine \"" + machineController.getSelected().getName() + "\" hinzugefügt!");
|
||||
clearEntries();
|
||||
}
|
||||
|
||||
public void deleteSelected(){
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
if (getSelected().getId() == null || getSelected().getId() < 0) {
|
||||
machineController.getSelected().getSecurityArea().remove(getSelected());
|
||||
sendInfoMessage(SUCCESS_TITLE, "Schutzbereich \"" + getSelected().getName() + "\" wurde erfolgreich von " +
|
||||
"Maschine \"" + machineController.getSelected().getName() + "\" entfernt!");
|
||||
return;
|
||||
}
|
||||
|
||||
machineController.getSelected().getSecurityArea().remove(getSelected());
|
||||
machineController.saveSelected();
|
||||
|
||||
if (getSelected().getSwitchingDevices() != null) {
|
||||
// Referenzen auf Schutzbereich entfernen
|
||||
getSelected().getSwitchingDevices().forEach(device -> device.setArea(null));
|
||||
switchingDeviceManager.removeAllIn(getSelected().getSwitchingDevices());
|
||||
getSelected().setSwitchingDevices(null);
|
||||
}
|
||||
|
||||
if (getSelected().getDangerPoints() != null) {
|
||||
// Referenzen auf Schutzbereich entfernen
|
||||
getSelected().getDangerPoints().forEach(point -> point.setSecurityArea(null));
|
||||
List<DangerPoint> dps = getSelected().getDangerPoints();
|
||||
getSelected().setDangerPoints(null);
|
||||
dangerPointManager.removeAllIn(dps);
|
||||
}
|
||||
|
||||
if (getSelected().getSecurityDevices() != null) {
|
||||
// Referenzen auf Schutzbereich entfernen
|
||||
getSelected().getSecurityDevices().forEach(device -> device.setArea(null));
|
||||
deviceManager.removeAllIn(getSelected().getSecurityDevices());
|
||||
getSelected().setSecurityDevices(null);
|
||||
}
|
||||
|
||||
System.out.println(getSelected().getId());
|
||||
getSelected().setMachine(null);
|
||||
securityAreaManager.delete(getSelected());
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Schutzbereich \"" + getSelected().getName() + "\" wurde erfolgreich von " +
|
||||
"Maschine \"" + machineController.getSelected().getName() + "\" entfernt!");
|
||||
setSelected(new SecurityArea());
|
||||
}
|
||||
|
||||
public void editSelected(){
|
||||
LOGGER.info("Mac: {}, Area: {}", machineController.getSelected(), getSelected());
|
||||
sendInfoMessage(SUCCESS_TITLE, "Schutzbereich \"" + getSelected().getName() + "\" wurde erfolgreich an " +
|
||||
"Maschine \"" + machineController.getSelected().getName() + "\" geändert!");
|
||||
clearEntries();
|
||||
}
|
||||
|
||||
public void saveSelected(){
|
||||
securityAreaManager.save(getSelected());
|
||||
}
|
||||
|
||||
public void createMachineMenu(){
|
||||
if (companyController.getSelected() == null){
|
||||
return;
|
||||
}
|
||||
root = new DefaultTreeNode(companyController.getSelected(), null);
|
||||
|
||||
List<Location> locations = locationController.getLocations();
|
||||
List<DefaultSubMenu> subMenus = new ArrayList<>(locations.size());
|
||||
|
||||
for (Location location : locations){
|
||||
TreeNode locNode = new DefaultTreeNode(location, root);
|
||||
locNode.setSelectable(false);
|
||||
if (location.getMachines() == null){
|
||||
continue;
|
||||
}
|
||||
for (Machine machine : location.getMachines()){
|
||||
new DefaultTreeNode(machine, locNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addMachineFromMenu(Machine machine){
|
||||
machineController.setSelected(machine);
|
||||
locationController.setSelected(machine.getLocation());
|
||||
}
|
||||
|
||||
public void cloneToSelectedMachine(){
|
||||
LOGGER.info(machineController.getSelected());
|
||||
SecurityArea area = securityAreaManager.cloneArea(getSelected());
|
||||
|
||||
// Explizit den Namen des geklonten Bereichs setzen, um zu verhindern, dass er zurückgesetzt wird
|
||||
String originalName = getSelected().getName();
|
||||
area.setName(originalName + " (Kopie)");
|
||||
|
||||
area.setMachine(machineController.getSelected());
|
||||
|
||||
// Schutzeinrichtungen neu verknüpfen, falls vorhanden
|
||||
if (area.getSecurityDevices() != null && !area.getSecurityDevices().isEmpty()) {
|
||||
area.getSecurityDevices().forEach(device -> {
|
||||
device.setId(null); // Neue ID für Kopien erzwingen
|
||||
device.setArea(area); // Referenz aktualisieren
|
||||
});
|
||||
}
|
||||
|
||||
// Gefahrenstellen neu verknüpfen, falls vorhanden
|
||||
if (area.getDangerPoints() != null && !area.getDangerPoints().isEmpty()) {
|
||||
area.getDangerPoints().forEach(point -> {
|
||||
point.setId(null); // Neue ID für Kopien erzwingen
|
||||
point.setSecurityArea(area); // Referenz aktualisieren
|
||||
});
|
||||
}
|
||||
|
||||
// Schaltgeräte neu verknüpfen, falls vorhanden
|
||||
if (area.getSwitchingDevices() != null && !area.getSwitchingDevices().isEmpty()) {
|
||||
area.getSwitchingDevices().forEach(device -> {
|
||||
device.setId(null); // Neue ID für Kopien erzwingen
|
||||
device.setArea(area); // Referenz aktualisieren
|
||||
});
|
||||
}
|
||||
|
||||
// Speichern des komplett aktualisierten Schutzbereichs
|
||||
securityAreaManager.save(area);
|
||||
machineController.getSelected().getSecurityArea().add(area);
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Sicherheitsbereich \""+ area.getName() +"\" wurde erfolgreich zu Maschine \"" + machineController.getSelected().getName() + "\" hinzugefügt!");
|
||||
}
|
||||
|
||||
// Questionnaire Management Methods
|
||||
|
||||
/**
|
||||
* Adds a questionnaire to the selected security area
|
||||
*/
|
||||
@Transactional
|
||||
public void addQuestionnaireToArea() {
|
||||
if (getSelected() == null || selectedQuestionnaire == null) {
|
||||
sendErrorMessage("Fehler", "Bitte wählen Sie einen Schutzbereich und einen Fragebogen aus!");
|
||||
return;
|
||||
}
|
||||
|
||||
SecurityArea area = securityAreaManager.addQuestionnaireToSecurityArea(getSelected(), selectedQuestionnaire);
|
||||
if (area != null) {
|
||||
refrehSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Fragebogen \"" + selectedQuestionnaire.getName() +
|
||||
"\" wurde erfolgreich zu Schutzbereich \"" + getSelected().getName() + "\" hinzugefügt!");
|
||||
selectedQuestionnaire = null;
|
||||
//refreshAvailableQuestionnaires();
|
||||
} else {
|
||||
sendErrorMessage("Fehler", "Fragebogen konnte nicht hinzugefügt werden!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a questionnaire from the selected security area
|
||||
*/
|
||||
public void removeQuestionnaireFromArea() {
|
||||
if (getSelected() == null || selectedSecurityAreaQuestionnaire == null) {
|
||||
sendErrorMessage("Fehler", "Bitte wählen Sie einen Schutzbereich und einen zu entfernenden Fragebogen aus!");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean success = securityAreaManager.removeQuestionnaireFromSecurityArea(getSelected(), selectedSecurityAreaQuestionnaire);
|
||||
if (success) {
|
||||
sendInfoMessage(SUCCESS_TITLE, "Fragebogen \"" + selectedSecurityAreaQuestionnaire.getName() +
|
||||
"\" wurde erfolgreich von Schutzbereich \"" + getSelected().getName() + "\" entfernt!");
|
||||
selectedSecurityAreaQuestionnaire = null;
|
||||
refreshAvailableQuestionnaires();
|
||||
} else {
|
||||
sendErrorMessage("Fehler", "Fragebogen konnte nicht entfernt werden!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the list of available questionnaires
|
||||
*/
|
||||
public void refreshAvailableQuestionnaires() {
|
||||
if (getSelected() != null) {
|
||||
availableQuestionnaires = securityAreaManager.getAvailableQuestionnaires(getSelected());
|
||||
} else {
|
||||
availableQuestionnaires = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares questionnaire dialog for adding
|
||||
*/
|
||||
public void prepareAddQuestionnaire() {
|
||||
selectedQuestionnaire = null;
|
||||
refreshAvailableQuestionnaires();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares questionnaire dialog for editing
|
||||
*/
|
||||
public void prepareEditQuestionnaire(SecurityAreaQuestionnaire questionnaire) {
|
||||
selectedSecurityAreaQuestionnaire = questionnaire;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(new SecurityArea());
|
||||
getEntities().clear();
|
||||
setCreated(new SecurityArea());
|
||||
selectedQuestionnaire = null;
|
||||
selectedSecurityAreaQuestionnaire = null;
|
||||
availableQuestionnaires = null;
|
||||
}
|
||||
|
||||
public TreeNode getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public void setRoot(TreeNode root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
public TreeNode getSelectedNode() {
|
||||
return selectedNode;
|
||||
}
|
||||
|
||||
public void setSelectedNode(TreeNode selectedNode) {
|
||||
this.selectedNode = selectedNode;
|
||||
if (selectedNode != null){
|
||||
addMachineFromMenu((Machine) selectedNode.getData());
|
||||
} else {
|
||||
machineController.setSelected(null);
|
||||
locationController.setSelected(null);
|
||||
}
|
||||
}
|
||||
|
||||
public ProtectionType[] getProtectionTypes(){
|
||||
return ProtectionType.values();
|
||||
}
|
||||
|
||||
public MountingPosition[] getMountingPositions(){
|
||||
return MountingPosition.values();
|
||||
}
|
||||
|
||||
public OverrunMeasurementType[] getOverrunMeasurementTypes(){
|
||||
return OverrunMeasurementType.values();
|
||||
}
|
||||
|
||||
public ApproachSpeed[] getApproachSpeeds(){
|
||||
return ApproachSpeed.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<SecurityArea> getManager() {
|
||||
return securityAreaManager;
|
||||
}
|
||||
|
||||
public Machine getMachine() {
|
||||
return machine;
|
||||
}
|
||||
|
||||
public void setMachine(Machine machine) {
|
||||
this.machine = machine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(SecurityArea selected) {
|
||||
super.setSelected(selected);
|
||||
}
|
||||
|
||||
// Questionnaire Getters and Setters
|
||||
|
||||
public Questionaire getSelectedQuestionnaire() {
|
||||
return selectedQuestionnaire;
|
||||
}
|
||||
|
||||
public void setSelectedQuestionnaire(Questionaire selectedQuestionnaire) {
|
||||
this.selectedQuestionnaire = selectedQuestionnaire;
|
||||
}
|
||||
|
||||
public SecurityAreaQuestionnaire getSelectedSecurityAreaQuestionnaire() {
|
||||
return selectedSecurityAreaQuestionnaire;
|
||||
}
|
||||
|
||||
public void setSelectedSecurityAreaQuestionnaire(SecurityAreaQuestionnaire selectedSecurityAreaQuestionnaire) {
|
||||
this.selectedSecurityAreaQuestionnaire = selectedSecurityAreaQuestionnaire;
|
||||
}
|
||||
|
||||
public List<Questionaire> getAvailableQuestionnaires() {
|
||||
if (availableQuestionnaires == null) {
|
||||
refreshAvailableQuestionnaires();
|
||||
}
|
||||
return availableQuestionnaires;
|
||||
}
|
||||
|
||||
public void setAvailableQuestionnaires(List<Questionaire> availableQuestionnaires) {
|
||||
this.availableQuestionnaires = availableQuestionnaires;
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.machine.SecurityDeviceCompanyManager;
|
||||
import controller.AbstractController;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Named;
|
||||
import model.security.SecurityDeviceCompany;
|
||||
import org.primefaces.PrimeFaces;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class SecurityDeviceCompanyController extends AbstractController<SecurityDeviceCompany>{
|
||||
|
||||
@EJB
|
||||
SecurityDeviceCompanyManager securityDeviceCompanyManager;
|
||||
|
||||
public SecurityDeviceCompanyController() {
|
||||
super();
|
||||
setSelected(new SecurityDeviceCompany());
|
||||
setCreated(new SecurityDeviceCompany());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<SecurityDeviceCompany> getManager() {
|
||||
return securityDeviceCompanyManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(new SecurityDeviceCompany());
|
||||
getEntities().clear();
|
||||
setCreated(new SecurityDeviceCompany());
|
||||
}
|
||||
|
||||
public List<SecurityDeviceCompany> getAllCompanies(){
|
||||
return securityDeviceCompanyManager.getCompanies();
|
||||
}
|
||||
|
||||
public SecurityDeviceCompany getByName(String name){
|
||||
if (name == null || name.contains("-/-")) {
|
||||
return null;
|
||||
}
|
||||
for(SecurityDeviceCompany comp : getAllCompanies()){
|
||||
if (comp.getName().contains(name)) {
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void saveSelected(){
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
boolean saved = securityDeviceCompanyManager.save(getSelected());
|
||||
securityDeviceCompanyManager.reloadCompanies();
|
||||
|
||||
if (saved) {
|
||||
sendInfoMessage(SUCCESS_TITLE, getSelected().getName() + " wurde erfolgreich gespeichert!");
|
||||
} else {
|
||||
errorMessage();
|
||||
}
|
||||
|
||||
setSelected(new SecurityDeviceCompany());
|
||||
closeDialogs();
|
||||
}
|
||||
|
||||
public void deleteSelected(){
|
||||
if (getSelected() == null || getSelected().getId() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean success = securityDeviceCompanyManager.remove(getSelected());
|
||||
if (success) {
|
||||
sendInfoMessage(SUCCESS_TITLE, getSelected().getName() + " wurde erfolgreich gelöscht");
|
||||
closeDialogs();
|
||||
getAllCompanies().remove(getSelected());
|
||||
setSelected(new SecurityDeviceCompany());
|
||||
} else {
|
||||
errorMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private void closeDialogs(){
|
||||
PrimeFaces current = PrimeFaces.current();
|
||||
current.executeScript("PF('dlgEditComp').hide()");
|
||||
current.executeScript("PF('dlgFindComp').hide()");
|
||||
current.executeScript("PF('dlgDelComp').hide()");
|
||||
}
|
||||
|
||||
public SecurityDeviceCompany getCompany(Long id){
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
return securityDeviceCompanyManager.find(id);
|
||||
}
|
||||
}
|
||||
+412
@@ -0,0 +1,412 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.machine.SecurityDeviceManager;
|
||||
import controller.AbstractController;
|
||||
import controller.company.CompanyController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.security.SecurityDevice;
|
||||
import model.company.Location;
|
||||
import model.machine.Machine;
|
||||
import model.machine.enums.Option;
|
||||
import model.security.DangerPoint;
|
||||
import model.security.SecurityArea;
|
||||
import model.security.SecurityDeviceCompany;
|
||||
import model.security.enums.BuildType;
|
||||
import model.security.enums.Component;
|
||||
import model.security.enums.DeviceRole;
|
||||
import model.security.enums.MutingBlankingModus;
|
||||
import model.security.enums.MutingSignals;
|
||||
import model.security.enums.NotHaltContact;
|
||||
import model.security.enums.NotHaltType;
|
||||
import model.security.enums.Principle;
|
||||
import model.security.enums.SecurityCategory;
|
||||
import model.security.enums.SecurityType;
|
||||
import model.security.enums.SfAlignment;
|
||||
import model.security.enums.StopCategory;
|
||||
import org.primefaces.PrimeFaces;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class SecurityDeviceController extends AbstractController<SecurityDevice> {
|
||||
|
||||
private static final String[] WIDGETS = {"dlgCreDev", "dlgEditDev"};
|
||||
|
||||
@Inject
|
||||
SecurityAreaController areaController;
|
||||
|
||||
@Inject
|
||||
CompanyController companyController;
|
||||
|
||||
@Inject
|
||||
SecurityDeviceCompanyController securityDeviceCompanyController;
|
||||
|
||||
@EJB
|
||||
SecurityDeviceManager deviceManager;
|
||||
@Named
|
||||
@Inject
|
||||
private SecurityAreaController securityAreaController;
|
||||
|
||||
public SecurityDeviceController() {
|
||||
setSelected(new SecurityDevice());
|
||||
setCreated(new SecurityDevice());
|
||||
setEntities(new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(new SecurityDevice());
|
||||
setCreated(new SecurityDevice());
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
//Get ALL SecurityDevices from all Machines and Locations
|
||||
//check for negativ id and save
|
||||
List<SecurityDevice> toSaves = new ArrayList<>();
|
||||
|
||||
companyController.getSelected().getLocations()
|
||||
.stream()
|
||||
.map(Location::getMachines)
|
||||
.flatMap(List::stream)
|
||||
.map(Machine::getSecurityArea)
|
||||
.flatMap(List::stream)
|
||||
.filter(area -> area.getSecurityDevices() != null)
|
||||
.map(SecurityArea::getSecurityDevices)
|
||||
.flatMap(List::stream)
|
||||
.forEach(dev -> {
|
||||
dev = checkCorrectNegativID(dev);
|
||||
toSaves.add(dev);
|
||||
LOGGER.info("dev {}; width2: {}", dev.getDescription(), dev.getsFdWidthTwo());
|
||||
//deviceManager.save(dev);
|
||||
});
|
||||
|
||||
deviceManager.saveAll(toSaves);
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Alle Sicherheitsgeräte wurden gespeichert für \""
|
||||
+ companyController.getSelected().getName() + "\"");
|
||||
}
|
||||
|
||||
public boolean hasRole() {
|
||||
if (getSelected().getType() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (getSelected().getType() != SecurityType.LASERRSCANNER);
|
||||
}
|
||||
|
||||
public boolean createdHasRole() {
|
||||
if (getCreated() == null || getCreated().getType() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (getCreated().getType()) {
|
||||
case DOOR_SECURITY_SWITCH:
|
||||
case NOT_HALT_BEFEHLSGERAET:
|
||||
case LASERRSCANNER:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean createdIsStandardView() {
|
||||
if (getCreated() == null || getCreated().getType() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (getCreated().getType()) {
|
||||
case DOOR_SECURITY_SWITCH:
|
||||
case NOT_HALT_BEFEHLSGERAET:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean selectedIsStandardView() {
|
||||
if (getSelected() == null || getSelected().getType() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (getSelected().getType()) {
|
||||
case DOOR_SECURITY_SWITCH:
|
||||
case NOT_HALT_BEFEHLSGERAET:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean createdIsSecuritySwitch(){
|
||||
if (getCreated() == null || getCreated().getType() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getCreated().getType() == SecurityType.DOOR_SECURITY_SWITCH;
|
||||
}
|
||||
|
||||
public boolean selectedIsSecuritySwitch(){
|
||||
if (getSelected() == null || getSelected().getType() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getSelected().getType() == SecurityType.DOOR_SECURITY_SWITCH;
|
||||
}
|
||||
|
||||
public boolean createdIsNothalt() {
|
||||
if (getCreated() == null || getCreated().getType() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getCreated().getType() == SecurityType.NOT_HALT_BEFEHLSGERAET;
|
||||
}
|
||||
|
||||
public boolean selectedIsNothalt() {
|
||||
if (getSelected() == null || getSelected().getType() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getSelected().getType() == SecurityType.NOT_HALT_BEFEHLSGERAET;
|
||||
}
|
||||
|
||||
private SecurityDevice checkCorrectNegativID(SecurityDevice dev) {
|
||||
if (dev.getId() != null && dev.getId() < 0) {
|
||||
dev.setId(null);
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
public void saveSelected() {
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
setSelected(checkCorrectNegativID(getSelected()));
|
||||
deviceManager.save(getSelected());
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Sicherheitsgerät wurde gespeichert!");
|
||||
setSelected(new SecurityDevice());
|
||||
}
|
||||
|
||||
public void cloneToSelectedArea() {
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
if (areaController.getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
SecurityDevice device = new SecurityDevice(getSelected());
|
||||
device.setArea(areaController.getSelected());
|
||||
|
||||
areaController.getSelected().getSecurityDevices().add(device);
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, getSelected().getType() + " wurde kopiert!");
|
||||
}
|
||||
|
||||
public void editSelected() {
|
||||
PrimeFaces current = PrimeFaces.current();
|
||||
current.executeScript("PF('dlgEditDev').hide()");
|
||||
}
|
||||
|
||||
public void deleteSelected() {
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
SecurityArea area = areaController.getSelected();
|
||||
boolean bound = false;
|
||||
|
||||
for(DangerPoint dp : area.getDangerPoints()){
|
||||
if (dp.getSecurityDevice().equals(getSelected())) {
|
||||
bound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (bound) {
|
||||
sendErrorMessage(ERROR_TITLE, "Schutzeinrichtung an Gefahrenpunkt gebunden.\r\n Zuerst den Gefahrenpunkt einer anderen Schutzeinrichtung zuweisen oder löschen!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String message = "Sicherheitsgerät wurde gelöscht!";
|
||||
|
||||
if (getSelected().getId() == null || getSelected().getId() < 0) {
|
||||
setSelected(new SecurityDevice());
|
||||
sendInfoMessage(SUCCESS_TITLE, message);
|
||||
LOGGER.info("removed unsaved SecurityDevice");
|
||||
return;
|
||||
}
|
||||
|
||||
setSelected(deviceManager.refresh(getSelected()));
|
||||
Integer toRemove = null;
|
||||
|
||||
for(int i=0; i < areaController.getSelected().getSecurityDevices().size(); i++){
|
||||
SecurityDevice device = areaController.getSelected().getSecurityDevices().get(i);
|
||||
if (device.getId() != null && device.getId().equals(getSelected().getId())) {
|
||||
toRemove = i;
|
||||
}
|
||||
}
|
||||
if (toRemove == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
areaController.getSelected().getSecurityDevices().remove(toRemove.intValue());
|
||||
areaController.saveSelected();
|
||||
|
||||
SecurityDeviceCompany comp = getSelected().getCompany();
|
||||
securityDeviceCompanyController.setSelected(comp);
|
||||
comp.getSecurityDevices().remove(getSelected());
|
||||
securityDeviceCompanyController.saveSelected();
|
||||
|
||||
getSelected().setCompany(null);
|
||||
getSelected().setArea(null);
|
||||
|
||||
boolean deleted = deviceManager.remove(getSelected());
|
||||
|
||||
if (deleted) {
|
||||
//areaController.getSelected().getSecurityDevices().remove(getSelected());
|
||||
//areaController.saveSelected();
|
||||
LOGGER.info("removed SecurityDevice with {}", getSelected().getId());
|
||||
setSelected(new SecurityDevice());
|
||||
sendInfoMessage(SUCCESS_TITLE, message);
|
||||
} else {
|
||||
sendErrorMessage(ERROR_TITLE, "Konnte Gerät nicht löschen. Gefahrenpunkt verbunden??");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void addFromCreated() {
|
||||
if (getCreated() == null || areaController.getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
getCreated().setArea(areaController.getSelected());
|
||||
deviceManager.save(getCreated());
|
||||
|
||||
List<SecurityDevice> devices = areaController.getSelected().getSecurityDevices();
|
||||
|
||||
if (devices == null) {
|
||||
devices = new ArrayList<>();
|
||||
}
|
||||
|
||||
devices.add(getCreated());
|
||||
areaController.getSelected().setSecurityDevices(devices);
|
||||
areaController.saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, getCreated().getType() + " wurde erfolgreich für den Sicherheitsbereich \"" + areaController.getSelected().getName() + "\" erstellt!");
|
||||
|
||||
clearEntries();
|
||||
closeDialogs(WIDGETS);
|
||||
}
|
||||
|
||||
public void addFromSelected() {
|
||||
if (getSelected() == null || areaController.getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
deviceManager.save(getSelected());
|
||||
sendInfoMessage(SUCCESS_TITLE, getCreated().getType() + " wurde erfolgreich für den Sicherheitsbereich \"" + areaController.getSelected().getName() + "\" bearbeitet!");
|
||||
|
||||
clearEntries();
|
||||
closeDialogs(WIDGETS);
|
||||
}
|
||||
|
||||
public SecurityDevice getDevice(Long id) {
|
||||
if (id == null || areaController.getSelected() == null) {
|
||||
return null;
|
||||
}
|
||||
if (areaController.getSelected().getSecurityDevices() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (SecurityDevice device : areaController.getSelected().getSecurityDevices()) {
|
||||
if (device.getId().equals(id)) {
|
||||
return device;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public SecurityType[] getSecurityTypes() {
|
||||
return SecurityType.values();
|
||||
}
|
||||
|
||||
public BuildType[] getBuildTypes() {
|
||||
return BuildType.values();
|
||||
}
|
||||
|
||||
public Principle[] getPrinciples(){
|
||||
return Principle.values();
|
||||
}
|
||||
|
||||
public NotHaltType[] getHaltTypes(){
|
||||
return NotHaltType.values();
|
||||
}
|
||||
|
||||
public DeviceRole[] getDeviceRoles() {
|
||||
return DeviceRole.values();
|
||||
}
|
||||
|
||||
public SecurityCategory[] getSecurityCategorys() {
|
||||
return SecurityCategory.values();
|
||||
}
|
||||
|
||||
public SfAlignment[] getSfAlignments() {
|
||||
return SfAlignment.values();
|
||||
}
|
||||
|
||||
public MutingBlankingModus[] getMutingBlankingModuses() {
|
||||
return MutingBlankingModus.values();
|
||||
}
|
||||
|
||||
public MutingSignals[] getMutingSignals() {
|
||||
return MutingSignals.values();
|
||||
}
|
||||
|
||||
public Option[] getEspeParambles() {
|
||||
return Option.values();
|
||||
}
|
||||
|
||||
public Component[] getComponents() {
|
||||
return Component.values();
|
||||
}
|
||||
|
||||
public StopCategory[] getStopCategorys(){
|
||||
return StopCategory.values();
|
||||
}
|
||||
|
||||
public NotHaltContact[] getNotHaltContact(){
|
||||
return NotHaltContact.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<SecurityDevice> getManager() {
|
||||
return deviceManager;
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.machine.SwitchingDeviceManager;
|
||||
import controller.AbstractController;
|
||||
import static controller.AbstractController.SUCCESS_TITLE;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.security.switching.SwitchingDevice;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class SwitchingDeviceController extends AbstractController<SwitchingDevice>{
|
||||
|
||||
private static final String[] WIDGETS = {"dlgCreSD", "dlgEditSD"};
|
||||
|
||||
@EJB
|
||||
SwitchingDeviceManager switchingDeviceManager;
|
||||
|
||||
@Inject
|
||||
SecurityAreaController securityAreaController;
|
||||
|
||||
public SwitchingDeviceController() {
|
||||
super();
|
||||
setSelected(new SwitchingDevice());
|
||||
setCreated(new SwitchingDevice());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<SwitchingDevice> getManager() {
|
||||
return switchingDeviceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(new SwitchingDevice());
|
||||
setCreated(new SwitchingDevice());
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public void addFromCreated(){
|
||||
getCreated().setArea(securityAreaController.getSelected());
|
||||
switchingDeviceManager.save(getCreated());
|
||||
|
||||
List<SwitchingDevice> devices = securityAreaController.getSelected().getSwitchingDevices();
|
||||
|
||||
if (devices == null) {
|
||||
devices = new ArrayList<>();
|
||||
securityAreaController.getSelected().setSwitchingDevices(devices);
|
||||
}
|
||||
|
||||
devices.add(getCreated());
|
||||
securityAreaController.saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Schaltkomponente wurde hinzugefügt");
|
||||
|
||||
clearEntries();
|
||||
closeDialogs(WIDGETS);
|
||||
}
|
||||
|
||||
public void addFromSelected(){
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Schaltkomponente wurde bearbeitet");
|
||||
switchingDeviceManager.save(getSelected());
|
||||
clearEntries();
|
||||
closeDialogs(WIDGETS);
|
||||
}
|
||||
|
||||
public void copy(){
|
||||
SwitchingDevice dp = new SwitchingDevice(getSelected());
|
||||
switchingDeviceManager.save(dp);
|
||||
|
||||
List<SwitchingDevice> devices = securityAreaController.getSelected().getSwitchingDevices();
|
||||
|
||||
if (devices == null) {
|
||||
devices = new ArrayList<>();
|
||||
securityAreaController.getSelected().setSwitchingDevices(devices);
|
||||
}
|
||||
|
||||
devices.add(dp);
|
||||
securityAreaController.saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Schaltkomponente wurde kopiert");
|
||||
clearEntries();
|
||||
}
|
||||
|
||||
public void deleteSelected(){
|
||||
switchingDeviceManager.remove(getSelected());
|
||||
|
||||
List<SwitchingDevice> devices = securityAreaController.getSelected().getSwitchingDevices();
|
||||
|
||||
if (devices == null) {
|
||||
devices = new ArrayList<>();
|
||||
}
|
||||
|
||||
devices.remove(getSelected());
|
||||
securityAreaController.saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Schaltkomponente wurde gelöscht");
|
||||
clearEntries();
|
||||
}
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.person;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.PasswordResetEJB;
|
||||
import business.user.PasswordManager;
|
||||
import business.user.PersonManager;
|
||||
import business.user.TokenManager;
|
||||
import controller.AbstractController;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Named;
|
||||
import model.person.Person;
|
||||
import model.person.Token;
|
||||
import model.person.enums.TokenType;
|
||||
import org.omnifaces.cdi.Param;
|
||||
import static org.omnifaces.util.Faces.redirect;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class PasswordresetController extends AbstractController<Token>{
|
||||
|
||||
@Param(name = "token")
|
||||
private String tokenID;
|
||||
|
||||
private String email;
|
||||
private String password;
|
||||
private Token loaded;
|
||||
|
||||
private boolean valid = false;
|
||||
|
||||
@EJB
|
||||
private TokenManager tokenManager;
|
||||
|
||||
@EJB
|
||||
private PasswordManager passwordManager;
|
||||
|
||||
@EJB
|
||||
private PersonManager personManager;
|
||||
|
||||
@EJB
|
||||
private PasswordResetEJB passwordResetManager;
|
||||
|
||||
@PostConstruct
|
||||
private void checkToken() {
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
String path = getRequest(context).getRequestURI();
|
||||
|
||||
if (path == null || !path.contains("passwordreset.xhtml")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tokenID == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
loaded = tokenManager.loadByRaw(tokenID);
|
||||
if (loaded == null) {
|
||||
LOGGER.error("couldn't find token for {}", tokenID);
|
||||
redirect("error.xhtml");
|
||||
return;
|
||||
}
|
||||
|
||||
valid = true;
|
||||
}
|
||||
|
||||
public boolean isValid(){
|
||||
if (!valid) {
|
||||
redirect("error.xhtml");
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void sendResetEmail(){
|
||||
if (email == null || email.isBlank()) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<Person> loadedPerson = personManager.getByEmail(email);
|
||||
|
||||
if (loadedPerson.isEmpty()) {
|
||||
sendErrorMessage(ERROR_TITLE, "Kein Benutzer für diese Emailadresse!");
|
||||
return;
|
||||
}
|
||||
Person p = loadedPerson.get();
|
||||
String name = p.getFirstname() + " " + p.getLastname();
|
||||
String token = tokenManager.generatePWResetToken(email, "ip", "PW Reset Token");
|
||||
|
||||
if (token == null || token.isBlank()) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if(passwordResetManager.sendPasswordResetEmail(email, name, "http://plate.software:8080/mss/passwordreset.xhtml?token=" + token)) {
|
||||
successMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
errorMessage();
|
||||
}
|
||||
|
||||
public String resetPassword(){
|
||||
if (!valid || loaded == null) {
|
||||
return "error.xhtml";
|
||||
}
|
||||
|
||||
if(passwordManager.resetPassword(loaded.getPerson(), password)) {
|
||||
sendInfoMessage(SUCCESS_TITLE, "Ihr Passwort wurde geändert");
|
||||
tokenManager.delete(loaded);
|
||||
} else {
|
||||
errorMessage();
|
||||
}
|
||||
|
||||
return "index.xhtml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Token> getManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
email = null;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
package controller.person;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.user.DemoManager;
|
||||
import business.user.PersonManager;
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.security.enterprise.AuthenticationStatus;
|
||||
import javax.security.enterprise.SecurityContext;
|
||||
import javax.security.enterprise.credential.Password;
|
||||
import javax.security.enterprise.credential.UsernamePasswordCredential;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import controller.AbstractController;
|
||||
import exception.InvalidEmailException;
|
||||
import exception.InvalidPasswordException;
|
||||
import exception.PersonInaktiveException;
|
||||
import httpauthenticationmechanism.ManagedPerson;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import model.person.Person;
|
||||
|
||||
import static javax.security.enterprise.AuthenticationStatus.SEND_FAILURE;
|
||||
import static javax.security.enterprise.AuthenticationStatus.SUCCESS;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.ejb.EJB;
|
||||
import static javax.security.enterprise.authentication.mechanism.http.AuthenticationParameters.withParams;
|
||||
import static org.omnifaces.util.Faces.redirect;
|
||||
import model.files.UserPicture;
|
||||
import model.person.enums.UserGroup;
|
||||
import org.omnifaces.util.Faces;
|
||||
import org.primefaces.model.DefaultStreamedContent;
|
||||
import org.primefaces.model.StreamedContent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@Named
|
||||
@SessionScoped
|
||||
public class PersonController extends AbstractController<Person> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2257766986862616262L;
|
||||
private String username;
|
||||
private String password;
|
||||
private boolean rememberMe = false;
|
||||
|
||||
private String id;
|
||||
|
||||
@Inject
|
||||
SecurityContext securityContext;
|
||||
|
||||
@Inject
|
||||
PreferencesController preferencesController;
|
||||
|
||||
@Inject
|
||||
ManagedPerson managedPerson;
|
||||
|
||||
private Person activePerson;
|
||||
|
||||
@EJB
|
||||
PersonManager personManager;
|
||||
|
||||
public PersonController() {
|
||||
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void register(){
|
||||
id = managedPerson.addController(this);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
private void unregister(){
|
||||
managedPerson.removeController(id);
|
||||
}
|
||||
|
||||
public String submit() {
|
||||
|
||||
try {
|
||||
// credential that want to be validate was UsernamePasswordCredential
|
||||
UsernamePasswordCredential credential = new UsernamePasswordCredential(username, new Password(password));
|
||||
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
String cont = getRequest(context).getParameter("continue");
|
||||
String path = getRequest(context).getRequestURI();
|
||||
|
||||
System.out.println(path);
|
||||
|
||||
// this will call our security configuration to authorize the user
|
||||
AuthenticationStatus status = securityContext.authenticate(
|
||||
getRequest(context),
|
||||
getResponse(context),
|
||||
withParams()
|
||||
.credential(credential)
|
||||
.newAuthentication(cont == null)
|
||||
.rememberMe(rememberMe)
|
||||
);
|
||||
|
||||
// When logged in choose the right page by class. When more then one group
|
||||
// fits then the higher order is used
|
||||
if (status.equals(SUCCESS)) {
|
||||
managedPerson.addLogin(username);
|
||||
activePerson = personManager.getByEmail(username).get();
|
||||
preferencesController.clearEntries();
|
||||
|
||||
FacesContext facesContext = FacesContext.getCurrentInstance();
|
||||
HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);
|
||||
session.setAttribute("user", this);
|
||||
session.setAttribute("realUsername", username);
|
||||
|
||||
if (securityContext.isCallerInRole(UserGroup.ADMIN.toString())) {
|
||||
LOGGER.info("Login succesfull " + username + " with role: ADMIN");
|
||||
return "admin/welcome.xhtml?faces-redirect=true";
|
||||
}
|
||||
|
||||
if (securityContext.isCallerInRole(UserGroup.USER.toString()) || securityContext.isCallerInRole(UserGroup.SUPERUSER.toString())) {
|
||||
LOGGER.info("Login succesfull " + username + " with role: USER");
|
||||
return "/resources/user/welcome.xhtml?faces-redirect=true";
|
||||
}
|
||||
|
||||
if (securityContext.isCallerInRole(UserGroup.CUSTOMER.toString())) {
|
||||
LOGGER.info("Login succesfull " + username + " with role: USER");
|
||||
return "customer/welcome.xhtml?faces-redirect=true";
|
||||
}
|
||||
|
||||
redirect("index.xhtml");
|
||||
|
||||
} else if (status.equals(SEND_FAILURE)) {
|
||||
sendErrorMessage("Fehler!", "Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut!. Status " + SEND_FAILURE);
|
||||
return "";
|
||||
}
|
||||
} catch (InvalidPasswordException | InvalidEmailException e) {
|
||||
LOGGER.info("Wrong Email or Password: " + username);
|
||||
sendErrorMessage("Fehler!", "Falsche Email oder Passwort!");
|
||||
return "";
|
||||
} catch (PersonInaktiveException p) {
|
||||
sendErrorMessage("Fehler!", " Ihr Konto ist inatkiv. Bitte wenden Sie sich an den Administator.");
|
||||
return "";
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Login error with " + e);
|
||||
e.printStackTrace();
|
||||
sendErrorMessage("Fehler!", "Ein Fehler ist aufgetreten, bitte versuchen Sie es erneut!");
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public StreamedContent getImage() {
|
||||
if (activePerson == null) {
|
||||
return null;
|
||||
}
|
||||
UserPicture picture = activePerson.getUserPicture();
|
||||
|
||||
return DefaultStreamedContent.builder()
|
||||
.contentType(picture == null ? null : picture.getMime().getMimeType())
|
||||
.stream(() -> {
|
||||
if (picture == null || picture.getFileData() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new ByteArrayInputStream(picture.getFileData());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
public Person getActivePersonWithWatchlist() {
|
||||
activePerson = personManager.getActiveUserWithWatchlist();
|
||||
return activePerson;
|
||||
}
|
||||
|
||||
public boolean hasPicture() {
|
||||
if (activePerson == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return activePerson.getUserPicture() != null;
|
||||
}
|
||||
|
||||
public String createInitials() {
|
||||
try {
|
||||
String first = activePerson.getFirstname().substring(0, 1);
|
||||
String last = activePerson.getLastname().substring(0, 1);
|
||||
|
||||
return first.toUpperCase() + last.toUpperCase();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public void checkSessionStatus() {
|
||||
HttpSession session = Faces.getSession();
|
||||
|
||||
if (session == null || Faces.hasSessionTimedOut()) {
|
||||
LOGGER.info("Users \"{}\" Session time out", activePerson != null ? activePerson.getEmail() : "");
|
||||
logout();
|
||||
return;
|
||||
}
|
||||
LOGGER.info("MaxInactive {}, last accessed {}", Faces.getSessionMaxInactiveInterval(), session.getLastAccessedTime());
|
||||
}
|
||||
|
||||
public String logout() {
|
||||
LOGGER.info("User is logging out: " + username);
|
||||
|
||||
try {
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
|
||||
// Session invalidieren und Cleanup
|
||||
context.getExternalContext().invalidateSession();
|
||||
managedPerson.removeLogin(username);
|
||||
activePerson = null;
|
||||
unregister();
|
||||
|
||||
// Nur ein Redirect verwenden - absoluter Pfad für korrekte Weiterleitung
|
||||
String contextPath = context.getExternalContext().getRequestContextPath();
|
||||
context.getExternalContext().redirect(contextPath + "/index.xhtml");
|
||||
|
||||
// Response ist jetzt committed, kein weiterer Code nach redirect
|
||||
return null;
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Logout failed for user: " + username, e);
|
||||
|
||||
// Bei Fehler: JSF-Navigation verwenden (falls Response noch nicht committed)
|
||||
try {
|
||||
return "/index.xhtml?faces-redirect=true";
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("Fallback navigation also failed", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveActivePerson() {
|
||||
personManager.refresh(activePerson);
|
||||
}
|
||||
|
||||
public void reloadActivePerson() {
|
||||
this.activePerson = personManager.load(activePerson);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public boolean isRememberMe() {
|
||||
return rememberMe;
|
||||
}
|
||||
|
||||
public void setRememberMe(boolean rememberMe) {
|
||||
this.rememberMe = rememberMe;
|
||||
}
|
||||
|
||||
public Person getActiveUser() {
|
||||
return activePerson;
|
||||
}
|
||||
|
||||
public void setActiveUser(Person activeUser) {
|
||||
this.activePerson = activeUser;
|
||||
}
|
||||
|
||||
public Set<String> getLogins() {
|
||||
return managedPerson.getLogins();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
this.username = null;
|
||||
this.activePerson = null;
|
||||
this.password = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Person> getManager() {
|
||||
return personManager;
|
||||
}
|
||||
}
|
||||
+328
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package controller.person;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.user.PasswordManager;
|
||||
import business.user.PersonManager;
|
||||
import controller.AbstractController;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import model.person.Person;
|
||||
import model.person.Salt;
|
||||
import model.person.enums.Call;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Named
|
||||
@RequestScoped
|
||||
public class PersonEditController extends AbstractController<Person> {
|
||||
|
||||
@Inject
|
||||
PersonController personController;
|
||||
|
||||
@EJB
|
||||
PasswordManager passwordManager;
|
||||
|
||||
@EJB
|
||||
PersonManager personManager;
|
||||
|
||||
private String email;
|
||||
private String emailOld;
|
||||
private String email2;
|
||||
private String email3;
|
||||
private Call call;
|
||||
private String telefon;
|
||||
private String password;
|
||||
private String passwordOld;
|
||||
private String password2;
|
||||
private String mobile;
|
||||
private String fax;
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
private String title;
|
||||
private String choosenButton;
|
||||
private byte[] signature;
|
||||
private boolean autoSignature;
|
||||
private String signatureValue;
|
||||
|
||||
public PersonEditController() {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void loadUserdata() {
|
||||
Person activePerson = personController.getActiveUser();
|
||||
|
||||
email = activePerson.getEmail();
|
||||
call = activePerson.getCall();
|
||||
telefon = activePerson.getTelefon();
|
||||
password = "********";
|
||||
mobile = activePerson.getMobile();
|
||||
fax = activePerson.getFax();
|
||||
firstname = activePerson.getFirstname();
|
||||
lastname = activePerson.getLastname();
|
||||
title = activePerson.getTitle();
|
||||
signature = activePerson.getSignature();
|
||||
autoSignature = activePerson.isAutoSignature();
|
||||
|
||||
// Konvertiere die gespeicherte Signatur in das Signatur-Format, falls vorhanden
|
||||
if (signature != null && signature.length > 0) {
|
||||
signatureValue = new String(signature);
|
||||
}
|
||||
}
|
||||
|
||||
public void changepassword() {
|
||||
if (!checkOldPassword(passwordOld)) {
|
||||
sendErrorMessage("Fehler", "Aktuelles Passwort stimmt nicht!");
|
||||
return;
|
||||
}
|
||||
|
||||
passwordManager.changePassword(personController.getActiveUser(), password2, passwordOld);
|
||||
|
||||
sendInfoMessage("Erfolg!", "Password wurde geändert!");
|
||||
}
|
||||
|
||||
public void changeEmail() {
|
||||
if (!emailOld.equals(email)) {
|
||||
sendErrorMessage("Fehler", "Alte Emailadresse stimmt nicht!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!email2.equals(email3)) {
|
||||
sendErrorMessage("Fehler", "Neue Emails stimmen nicht überein!");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
InternetAddress emailAdd = new InternetAddress(email2);
|
||||
emailAdd.validate();
|
||||
} catch (AddressException a) {
|
||||
sendErrorMessage("Fehler", "Keine Korrekte Emailadresse " + email2);
|
||||
return;
|
||||
}
|
||||
|
||||
if (personManager.getByEmail(email2).isPresent()) {
|
||||
sendErrorMessage("Fehler", "Keine Email bereits vergeben!" + email2);
|
||||
return;
|
||||
}
|
||||
|
||||
Person user = personManager.load(personController.getActiveUser());
|
||||
user.setEmail(email2);
|
||||
personManager.save(user);
|
||||
|
||||
personController.reloadActivePerson();
|
||||
|
||||
sendInfoMessage("Erfolg", "Email \"" + emailOld + "\" wurde zu \"" + email2 + "\" geändert!");
|
||||
}
|
||||
|
||||
public void saveSignature() {
|
||||
if (signatureValue != null && !signatureValue.isEmpty()) {
|
||||
Person user = personManager.load(personController.getActiveUser());
|
||||
user.setSignature(signatureValue.getBytes());
|
||||
user.setAutoSignature(autoSignature);
|
||||
personManager.save(user);
|
||||
personController.reloadActivePerson();
|
||||
this.signature = personController.getActiveUser().getSignature();
|
||||
sendInfoMessage("Erfolg!", "Signatur wurde gespeichert!");
|
||||
} else {
|
||||
sendErrorMessage("Hinweis", "Keine Signatur vorhanden zum Speichern.");
|
||||
}
|
||||
}
|
||||
|
||||
public void clearSignature() {
|
||||
this.signatureValue = null;
|
||||
}
|
||||
|
||||
private boolean checkOldPassword(String pw) {
|
||||
return passwordManager.passwordCheckCustomer(personController.getActiveUser(), pw);
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Call getCall() {
|
||||
return call;
|
||||
}
|
||||
|
||||
public void setCall(Call call) {
|
||||
this.call = call;
|
||||
}
|
||||
|
||||
public String getTelefon() {
|
||||
return telefon;
|
||||
}
|
||||
|
||||
public void setTelefon(String telefon) {
|
||||
this.telefon = telefon;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
public String getEmailOld() {
|
||||
return emailOld;
|
||||
}
|
||||
|
||||
public void setEmailOld(String emailOld) {
|
||||
this.emailOld = emailOld;
|
||||
}
|
||||
|
||||
public String getFax() {
|
||||
return fax;
|
||||
}
|
||||
|
||||
public void setFax(String fax) {
|
||||
this.fax = fax;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getEmail2() {
|
||||
return email2;
|
||||
}
|
||||
|
||||
public void setEmail2(String email2) {
|
||||
this.email2 = email2;
|
||||
}
|
||||
|
||||
public String getEmail3() {
|
||||
return email3;
|
||||
}
|
||||
|
||||
public void setEmail3(String email3) {
|
||||
this.email3 = email3;
|
||||
}
|
||||
|
||||
public String getPassword2() {
|
||||
return password2;
|
||||
}
|
||||
|
||||
public void setPassword2(String password2) {
|
||||
this.password2 = password2;
|
||||
}
|
||||
|
||||
public String getChoosenButton() {
|
||||
return choosenButton;
|
||||
}
|
||||
|
||||
public void setChoosenButton(String choosenButton) {
|
||||
this.choosenButton = choosenButton;
|
||||
}
|
||||
|
||||
public String getPasswordOld() {
|
||||
return passwordOld;
|
||||
}
|
||||
|
||||
public void setPasswordOld(String passwordOld) {
|
||||
this.passwordOld = passwordOld;
|
||||
}
|
||||
|
||||
public byte[] getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(byte[] signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public boolean isAutoSignature() {
|
||||
return autoSignature;
|
||||
}
|
||||
|
||||
public void setAutoSignature(boolean autoSignature) {
|
||||
this.autoSignature = autoSignature;
|
||||
}
|
||||
|
||||
public String getSignatureAsBase64() {
|
||||
if (signature != null && signature.length > 0) {
|
||||
return Base64.getEncoder().encodeToString(signature);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getSignatureValue() {
|
||||
return signatureValue;
|
||||
}
|
||||
|
||||
public void setSignatureValue(String signatureValue) {
|
||||
this.signatureValue = signatureValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
this.email = null;
|
||||
this.emailOld = null;
|
||||
this.email2 = null;
|
||||
this.email3 = null;
|
||||
this.call = null;
|
||||
this.telefon = null;
|
||||
this.password = null;
|
||||
this.passwordOld = null;
|
||||
this.password2 = null;
|
||||
this.mobile = null;
|
||||
this.fax = null;
|
||||
this.firstname = null;
|
||||
this.lastname = null;
|
||||
this.title = null;
|
||||
this.choosenButton = null;
|
||||
this.signature = null;
|
||||
this.autoSignature = false;
|
||||
this.signatureValue = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Person> getManager() {
|
||||
return personManager;
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package controller.person;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.user.PreferencesManager;
|
||||
import controller.AbstractController;
|
||||
import java.util.TimeZone;
|
||||
import javax.ejb.EJB;
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.person.Person;
|
||||
import model.person.Preferences;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@SessionScoped
|
||||
@Named
|
||||
public class PreferencesController extends AbstractController<Preferences>{
|
||||
private static final String background_light = "#EEF7FC";
|
||||
private static final String background_dark = "#121212";
|
||||
private static final String comp_logo_light = "/resources/images/logos/logo_small.png";
|
||||
private static final String comp_logo_dark = "/resources/images/logos/MSS-Logo-weiss-RGB.png";
|
||||
private static final String css_icon_location_light = "";
|
||||
private static final String css_icon_location_dark = "";
|
||||
private static final String CSS_LIGHT = "light.css";
|
||||
private static final String CSS_DARK = "dark.css";
|
||||
|
||||
@Inject
|
||||
PersonController personController;
|
||||
|
||||
@EJB
|
||||
PreferencesManager preferencesManager;
|
||||
|
||||
private String theme;
|
||||
private String timeZone;
|
||||
|
||||
public PreferencesController() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
Person p = personController.getActiveUser();
|
||||
if (p == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Preferences pref = p.getPreferences();
|
||||
|
||||
theme = pref.getTheme();
|
||||
timeZone = pref.getTimeZone();
|
||||
}
|
||||
|
||||
public void save(){
|
||||
personController.reloadActivePerson();
|
||||
Preferences pref = preferencesManager.find(personController.getActiveUser().getPreferences().getId());
|
||||
pref.setTheme(theme);
|
||||
pref.setTimeZone(timeZone);
|
||||
preferencesManager.save(pref);
|
||||
personController.reloadActivePerson();
|
||||
clearEntries();
|
||||
}
|
||||
|
||||
public String[] timeZones(){
|
||||
return TimeZone.getAvailableIDs();
|
||||
}
|
||||
|
||||
public String getTheme() {
|
||||
if (theme == null || theme.isEmpty()) {
|
||||
return "vela";
|
||||
}
|
||||
return theme;
|
||||
}
|
||||
|
||||
public String getBackgroundColor(){
|
||||
if (getTheme().equals("saga") || getTheme().startsWith("nova")) {
|
||||
return background_light;
|
||||
}
|
||||
|
||||
return background_dark;
|
||||
}
|
||||
|
||||
public String getCompanyLogo(){
|
||||
if (getTheme().equals("saga") || getTheme().startsWith("nova")) {
|
||||
return comp_logo_light;
|
||||
}
|
||||
|
||||
return comp_logo_dark;
|
||||
}
|
||||
|
||||
public String getStyleClass(){
|
||||
if (getTheme().equals("saga") || getTheme().startsWith("nova")) {
|
||||
return CSS_LIGHT;
|
||||
}
|
||||
|
||||
return CSS_DARK;
|
||||
}
|
||||
|
||||
public void setTheme(String theme) {
|
||||
this.theme = theme;
|
||||
LOGGER.info(theme);
|
||||
}
|
||||
|
||||
public String getTimeZone() {
|
||||
return timeZone;
|
||||
}
|
||||
|
||||
public void setTimeZone(String timeZone) {
|
||||
this.timeZone = timeZone;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Preferences> getManager() {
|
||||
return preferencesManager;
|
||||
}
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package controller.person;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.user.PersonManager;
|
||||
import business.user.UserPictureManager;
|
||||
import controller.AbstractController;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.ejb.EJB;
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.files.Mime;
|
||||
import model.files.UserPicture;
|
||||
import model.person.Person;
|
||||
import org.primefaces.event.FileUploadEvent;
|
||||
import org.primefaces.model.DefaultStreamedContent;
|
||||
import org.primefaces.model.StreamedContent;
|
||||
import org.primefaces.model.file.UploadedFile;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Named
|
||||
@SessionScoped
|
||||
public class UserPictureController extends AbstractController<UserPicture> {
|
||||
|
||||
private UserPicture picture;
|
||||
|
||||
@Inject
|
||||
PersonController personController;
|
||||
|
||||
@EJB
|
||||
UserPictureManager upManager;
|
||||
|
||||
@EJB
|
||||
PersonManager personManager;
|
||||
|
||||
private Map<Long, UserPicture> loaded;
|
||||
|
||||
public void handleUserPictureUpload(FileUploadEvent event) {
|
||||
UploadedFile file = event.getFile();
|
||||
|
||||
if (file != null && file.getContent() != null && file.getContent().length > 0 && file.getFileName() != null) {
|
||||
|
||||
if (createSaveUserPicture(file)) {
|
||||
sendInfoMessage("Erfolg", this.picture.getName() + " wurde hochgeladen!");
|
||||
} else {
|
||||
sendErrorMessage("Fehler", "Es ist ein Fehler aufgetreten. Bitte Versuchen Sie es erneut!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean createSaveUserPicture(UploadedFile file) {
|
||||
picture = null;
|
||||
picture = personController.getActiveUser().getUserPicture();
|
||||
boolean isNew = picture == null;
|
||||
|
||||
if (isNew) {
|
||||
picture = new UserPicture();
|
||||
}
|
||||
|
||||
setData(picture, file);
|
||||
Person person = personManager.load(personController.getActiveUser());
|
||||
person.setUserPicture(picture);
|
||||
picture.setPerson(person);
|
||||
|
||||
if (isNew) {
|
||||
upManager.create(picture);
|
||||
} else {
|
||||
upManager.edit(picture);
|
||||
}
|
||||
|
||||
personManager.save(person);
|
||||
personController.reloadActivePerson();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setData(UserPicture picture, UploadedFile file) {
|
||||
picture.setName(file.getFileName());
|
||||
picture.setFileData(file.getContent());
|
||||
picture.setMime(Mime.getByMimeType(file.getContentType()));
|
||||
}
|
||||
|
||||
public long getMaxFileSize() {
|
||||
return UserPicture.getSizeLimit();
|
||||
}
|
||||
|
||||
public String getFileTypesRE() {
|
||||
return UserPicture.getAllowedTypesRE();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
this.picture = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<UserPicture> getManager() {
|
||||
return upManager;
|
||||
}
|
||||
|
||||
public StreamedContent pictureStream(UserPicture upicture){
|
||||
UserPicture loadedPicture = getDataForID(upicture);
|
||||
if (loadedPicture == null || loadedPicture.getFileData() == null) {
|
||||
System.out.println("Landed on null");
|
||||
return null;
|
||||
}
|
||||
System.out.println(loadedPicture.getId());
|
||||
return DefaultStreamedContent.builder()
|
||||
.contentType(loadedPicture.getFileData() == null ? null : loadedPicture.getMime().getMimeType())
|
||||
.stream(() -> {
|
||||
if (getCreated() == null
|
||||
|| loadedPicture.getFileData()== null
|
||||
|| loadedPicture.getFileData().length == 0) {
|
||||
System.out.println("Landed on null 2");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new ByteArrayInputStream(upicture.getFileData());
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
System.out.println("Landed on null 3");
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
public UserPicture getDataForID(UserPicture userPicture){
|
||||
if (userPicture == null || userPicture.getId() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (loaded == null) {
|
||||
initLoaded();
|
||||
}
|
||||
|
||||
if (loaded.containsKey(userPicture.getId()) && loaded.get(userPicture.getId()) != null) {
|
||||
return loaded.get(userPicture.getId());
|
||||
} else {
|
||||
UserPicture dbPicture = upManager.findWithData(userPicture.getId());
|
||||
if (dbPicture != null) {
|
||||
System.out.println(dbPicture.getFileData().length);
|
||||
loaded.put(dbPicture.getId(), dbPicture);
|
||||
return dbPicture;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void initLoaded(){
|
||||
loaded = new HashMap<>(100);
|
||||
}
|
||||
|
||||
public Map<Long, UserPicture> getLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
}
|
||||
+233
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.questions;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.questions.QuestionaireManager;
|
||||
import controller.AbstractController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Named;
|
||||
import model.question.Question;
|
||||
import model.question.Questionaire;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class QuestionaireController extends AbstractController<Questionaire> {
|
||||
|
||||
@EJB
|
||||
QuestionaireManager questionaireManager;
|
||||
|
||||
private Question selectedQuestion;
|
||||
|
||||
private List<Questionaire> allQuestionaires;
|
||||
|
||||
public QuestionaireController() {
|
||||
super();
|
||||
setSelected(new Questionaire());
|
||||
getSelected().setQuestions(new ArrayList<>());
|
||||
setCreated(new Questionaire());
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public void addQuestionToSelected() {
|
||||
if (getSelected() == null) {
|
||||
clearEntries();
|
||||
}
|
||||
Question q = new Question();
|
||||
q.setQuestionaire(getSelected());
|
||||
q.setAnswers(new ArrayList<>());
|
||||
q.setPosition(getMinPosition(getSelected().getQuestions()));
|
||||
q.setStandardValues(true);
|
||||
getSelected().getQuestions().add(q);
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Neue Frage Nr. " + q.getPosition() + " wurde hinzugefügt");
|
||||
}
|
||||
|
||||
public List<Questionaire> getAllGlobals(){
|
||||
return questionaireManager.loadAllGlobals();
|
||||
}
|
||||
|
||||
public Integer getMinPosition(List<Question> questions){
|
||||
if (questions == null || questions.isEmpty()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Integer size = questions.size();
|
||||
|
||||
Optional<Integer> max = questions.stream().map(Question::getPosition).max((q1, q2) -> q1.compareTo(q2));
|
||||
|
||||
if (max.isEmpty()) {
|
||||
return size + 1;
|
||||
}
|
||||
|
||||
return Integer.max(size, max.get()) + 1;
|
||||
}
|
||||
|
||||
public void saveSelected() {
|
||||
Questionaire selected = getSelected();
|
||||
|
||||
if (questionaireManager.save(selected)) {
|
||||
sendInfoMessage(SUCCESS_TITLE, selected.getName() + " wurde gespeichert!");
|
||||
clearEntries();
|
||||
return;
|
||||
}
|
||||
|
||||
sendErrorMessage(ERROR_TITLE, ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
public void delete(){
|
||||
try{
|
||||
if(questionaireManager.deleteWithQuestions(getSelected())){
|
||||
sendInfoMessage(SUCCESS_TITLE, getSelected().getName() + " wurde gelöscht");
|
||||
clearEntries();
|
||||
return;
|
||||
}
|
||||
|
||||
errorMessage();
|
||||
} catch(Exception e) {
|
||||
errorMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public void loadQuestionaires(){
|
||||
setEntities(questionaireManager.loadAllWithQuestions());
|
||||
}
|
||||
|
||||
public void removeQuestion(){
|
||||
if (selectedQuestion == null || selectedQuestion.getPosition() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
Integer pos = selectedQuestion.getPosition();
|
||||
boolean success = getSelected().getQuestions().removeIf(que -> que.getPosition().equals(pos));
|
||||
|
||||
if (success) {
|
||||
sendInfoMessage(SUCCESS_TITLE, "Frage wurde entfernt");
|
||||
return;
|
||||
}
|
||||
|
||||
errorMessage();
|
||||
}
|
||||
|
||||
public void moveSelectedQuestionLeft() {
|
||||
moveSelectedQuestion(-1);
|
||||
}
|
||||
|
||||
public void moveSelectedQuestionRight() {
|
||||
moveSelectedQuestion(1);
|
||||
}
|
||||
|
||||
private void moveSelectedQuestion(int delta) {
|
||||
if (selectedQuestion == null || selectedQuestion.getPosition() == null) {
|
||||
return;
|
||||
}
|
||||
List<Question> questions = getSelected() != null ? getSelected().getQuestions() : null;
|
||||
if (questions == null || questions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Integer current = selectedQuestion.getPosition();
|
||||
int target = current + delta;
|
||||
if (target < 1) {
|
||||
// out of bounds: do nothing
|
||||
return;
|
||||
}
|
||||
int maxPos = getMaxPosition();
|
||||
if (target > maxPos) {
|
||||
// at the end already
|
||||
return;
|
||||
}
|
||||
if (target == current) {
|
||||
return;
|
||||
}
|
||||
Question other = null;
|
||||
for (Question q : questions) {
|
||||
if (q != selectedQuestion && q.getPosition() != null && q.getPosition().intValue() == target) {
|
||||
other = q;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (other != null) {
|
||||
other.setPosition(current);
|
||||
selectedQuestion.setPosition(target);
|
||||
} else {
|
||||
selectedQuestion.setPosition(target);
|
||||
}
|
||||
Collections.sort(questions);
|
||||
}
|
||||
|
||||
private int getMaxPosition() {
|
||||
List<Question> questions = getSelected() != null ? getSelected().getQuestions() : null;
|
||||
if (questions == null || questions.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int max = 0;
|
||||
for (Question q : questions) {
|
||||
if (q != null && q.getPosition() != null && q.getPosition() > max) {
|
||||
max = q.getPosition();
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
public void autoArrangePositions() {
|
||||
List<Question> questions = getSelected() != null ? getSelected().getQuestions() : null;
|
||||
if (questions == null || questions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<Question> sorted = new ArrayList<>(questions);
|
||||
Collections.sort(sorted, (a, b) -> {
|
||||
Integer pa = a != null ? a.getPosition() : null;
|
||||
Integer pb = b != null ? b.getPosition() : null;
|
||||
if (pa == null && pb == null) return 0;
|
||||
if (pa == null) return 1;
|
||||
if (pb == null) return -1;
|
||||
return Integer.compare(pa, pb);
|
||||
});
|
||||
int pos = 1;
|
||||
for (Question q : sorted) {
|
||||
q.setPosition(pos++);
|
||||
}
|
||||
Collections.sort(questions);
|
||||
sendInfoMessage(SUCCESS_TITLE, "Fragen automatisch angeordnet");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Questionaire> getManager() {
|
||||
return questionaireManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(new Questionaire());
|
||||
getSelected().setQuestions(new ArrayList<>());
|
||||
setCreated(new Questionaire());
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public Question getSelectedQuestion() {
|
||||
return selectedQuestion;
|
||||
}
|
||||
|
||||
public void setSelectedQuestion(Question selectedQuestion) {
|
||||
this.selectedQuestion = selectedQuestion;
|
||||
}
|
||||
|
||||
public List<Questionaire> getAllQuestionaires() {
|
||||
if (allQuestionaires == null || allQuestionaires.isEmpty()) {
|
||||
allQuestionaires = questionaireManager.loadAllWithQuestions();
|
||||
}
|
||||
return allQuestionaires;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package controller.search;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.tickets.TicketManager;
|
||||
import controller.AbstractController;
|
||||
import controller.company.CompanyController;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import model.ticket.enums.Status;
|
||||
import model.ticket.Ticket;
|
||||
import org.omnifaces.cdi.Param;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class SearchController extends AbstractController<Ticket> {
|
||||
|
||||
private String searchText;
|
||||
private List<Object> results;
|
||||
|
||||
@Inject
|
||||
CompanyController companyController;
|
||||
|
||||
@EJB
|
||||
TicketManager ticketManager;
|
||||
|
||||
@Param(name = "company")
|
||||
private String companyParam;
|
||||
|
||||
List<Ticket> tickets;
|
||||
List<Ticket> filteredTickets;
|
||||
|
||||
Ticket selectedTicket;
|
||||
|
||||
public SearchController() {
|
||||
}
|
||||
|
||||
public void search() {
|
||||
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init(){
|
||||
if (companyParam == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
tickets = ticketManager.loadAllForCompany(companyParam);
|
||||
if (!tickets.isEmpty()) {
|
||||
companyController.setSelected(tickets.get(0).getCompany());
|
||||
companyController.addFromSelectedFromSearch();
|
||||
Collections.sort(tickets);
|
||||
Collections.reverse(tickets);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFromSelectedCompany() {
|
||||
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
|
||||
String url = request.getRequestURL().toString();
|
||||
|
||||
if (url != null && !url.contains("search")) {
|
||||
LOGGER.info(url);
|
||||
return;
|
||||
}
|
||||
|
||||
tickets = ticketManager.loadAllForCompany(companyController.getSelected());
|
||||
Collections.sort(tickets);
|
||||
Collections.reverse(tickets);
|
||||
}
|
||||
|
||||
public void deleteTicket(){
|
||||
LOGGER.info("Trying to delete {}", selectedTicket);
|
||||
|
||||
if (selectedTicket == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if(ticketManager.saveDelete(selectedTicket)){
|
||||
sendInfoMessage(SUCCESS_TITLE, "Ticket " + selectedTicket.getNumber() + " wurde gelöscht");
|
||||
LOGGER.info("Ticket is deleted");
|
||||
selectedTicket = null;
|
||||
setFromSelectedCompany();
|
||||
} else {
|
||||
errorMessage();
|
||||
LOGGER.error("Couldn't delete ticket");
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteTicket(Ticket ticket){
|
||||
LOGGER.info("Trying to delete {}", ticket);
|
||||
|
||||
if (ticket == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if(ticketManager.saveDelete(selectedTicket)){
|
||||
sendInfoMessage(SUCCESS_TITLE, "Ticket " + selectedTicket.getNumber() + " wurde gelöscht");
|
||||
LOGGER.info("Ticket is deleted");
|
||||
setFromSelectedCompany();
|
||||
} else {
|
||||
errorMessage();
|
||||
LOGGER.error("Couldn't delete ticket");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
this.searchText = null;
|
||||
this.results.clear();
|
||||
}
|
||||
|
||||
public String getSearchText() {
|
||||
return searchText;
|
||||
}
|
||||
|
||||
public void setSearchText(String searchText) {
|
||||
this.searchText = searchText;
|
||||
}
|
||||
|
||||
public List<Object> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager getManager() {
|
||||
return ticketManager;
|
||||
}
|
||||
|
||||
public Ticket getSelectedTicket() {
|
||||
return selectedTicket;
|
||||
}
|
||||
|
||||
public void setSelectedTicket(Ticket selectedTicket) {
|
||||
this.selectedTicket = selectedTicket;
|
||||
}
|
||||
|
||||
public List<Ticket> getTickets() {
|
||||
return tickets;
|
||||
}
|
||||
|
||||
public void setTickets(List<Ticket> tickets) {
|
||||
this.tickets = tickets;
|
||||
}
|
||||
|
||||
public List<Ticket> getFilteredTickets() {
|
||||
return filteredTickets;
|
||||
}
|
||||
|
||||
public void setFilteredTickets(List<Ticket> filteredTickets) {
|
||||
this.filteredTickets = filteredTickets;
|
||||
}
|
||||
|
||||
public Status[] getAllStatuses(){
|
||||
return Status.values();
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.tickets;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.tickets.TicketManager;
|
||||
import controller.AbstractController;
|
||||
import controller.person.PersonController;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.ticket.Ticket;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class PersonalTicketController extends AbstractController<Ticket>{
|
||||
@EJB
|
||||
TicketManager ticketManager;
|
||||
|
||||
@Inject
|
||||
PersonController personController;
|
||||
|
||||
private List<Ticket> loadedTickets;
|
||||
private List<Ticket> watchedTickets;
|
||||
|
||||
public PersonalTicketController() {
|
||||
super();
|
||||
setCreated(null);
|
||||
setSelected(null);
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init(){
|
||||
loadedTickets = ticketManager.loadBatchOrderedByCreationDateByPerson(personController.getActiveUser());
|
||||
watchedTickets = ticketManager.loadPersonalWatchlist(personController.getActiveUser());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Ticket> getManager() {
|
||||
return ticketManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setCreated(null);
|
||||
setSelected(null);
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public List<Ticket> getWatchedTickets() {
|
||||
return watchedTickets;
|
||||
}
|
||||
|
||||
public List<Ticket> getLoadedTickets() {
|
||||
return loadedTickets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,463 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.tickets;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.tickets.TicketManager;
|
||||
import business.user.PersonManager;
|
||||
import controller.AbstractController;
|
||||
import controller.company.CompanyController;
|
||||
import controller.person.PersonController;
|
||||
import controller.questions.QuestionaireController;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.company.Location;
|
||||
import model.customer.Customer;
|
||||
import model.machine.Machine;
|
||||
import model.person.Person;
|
||||
import model.question.Questionaire;
|
||||
import model.question.enums.Answer;
|
||||
import model.ticket.enums.FilenameGeneration;
|
||||
import model.ticket.enums.Status;
|
||||
import model.ticket.Ticket;
|
||||
import model.ticket.dataCopies.TicketLocation;
|
||||
import model.ticket.dataCopies.TicketMachine;
|
||||
import model.ticket.dataCopies.TicketSecurityArea;
|
||||
import model.ticket.questions.SecurityAreaQuestionaire;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class TicketController extends AbstractController<Ticket> {
|
||||
|
||||
@EJB
|
||||
TicketManager ticketManager;
|
||||
|
||||
@EJB
|
||||
PersonManager personManager;
|
||||
|
||||
@Inject
|
||||
CompanyController companyController;
|
||||
|
||||
@Inject
|
||||
PersonController personController;
|
||||
|
||||
@Inject
|
||||
TicketScrollController scrollController;
|
||||
|
||||
@Inject
|
||||
QuestionaireController questionaireController;
|
||||
|
||||
private List<Customer> contacts;
|
||||
private List<Customer> requester;
|
||||
|
||||
private List<Location> selectedLocations;
|
||||
private List<MachineContainer> machineContainers;
|
||||
|
||||
private boolean loadTicketData;
|
||||
|
||||
public TicketController() {
|
||||
super();
|
||||
setCreated(new Ticket());
|
||||
getCreated().setStartDate(LocalDateTime.now());
|
||||
getCreated().setEndDate(LocalDateTime.now().plusDays(7));
|
||||
getCreated().setPayed(false);
|
||||
|
||||
setSelected(new Ticket());
|
||||
selectedLocations = new ArrayList<>();
|
||||
machineContainers = new ArrayList<>();
|
||||
contacts = new ArrayList<>();
|
||||
requester = new ArrayList<>();
|
||||
this.loadTicketData = true;
|
||||
}
|
||||
|
||||
public void createSelectedLocations() {
|
||||
companyController.getSelected().getLocations().size();
|
||||
setSelectedLocations(new ArrayList<>(companyController.getSelected().getLocations()));
|
||||
}
|
||||
|
||||
public void createTicket() {
|
||||
if (checkNameExists(getCreated().getNumber())) {
|
||||
sendErrorMessage(ERROR_TITLE, "Ticketnummer existiert bereits!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (getCreated().getBillingAddress() == null) {
|
||||
sendErrorMessage(ERROR_TITLE, "Adresse Auftraggeber nicht gesetzt!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (getCreated().getServiceAddress() == null) {
|
||||
sendErrorMessage(ERROR_TITLE, "Serviceadresse/ Einsatzort nicht gesetzt!");
|
||||
return;
|
||||
}
|
||||
|
||||
getCreated().setCompany(companyController.getSelected());
|
||||
|
||||
List<TicketLocation> ticketLocations = new ArrayList<>(machineContainers.size());
|
||||
|
||||
machineContainers.forEach(con -> {
|
||||
Location location = con.getLocation();
|
||||
LOGGER.debug(con.getLocation().getName());
|
||||
location.setMachines(con.selectedMachines);
|
||||
con.selectedMachines.forEach(mac -> LOGGER.debug(mac.getName()));
|
||||
TicketLocation created = new TicketLocation(location);
|
||||
created.setTicket(getCreated());
|
||||
ticketLocations.add(created);
|
||||
});
|
||||
|
||||
List<Ticket> loadedCompTickets = ticketManager.loadAllForCompanyWithQuestions(companyController.getSelected());
|
||||
|
||||
if (!loadTicketData || loadedCompTickets == null || loadedCompTickets.isEmpty()) {
|
||||
List<Questionaire> globals = questionaireController.getAllGlobals();
|
||||
ticketLocations.forEach(loc -> {
|
||||
loc.getMachines().forEach(mac -> {
|
||||
mac.getSecurityAreas().stream().filter(area -> area != null).forEach(area -> {
|
||||
List<SecurityAreaQuestionaire> areaQuestionaires = globals.stream().map(SecurityAreaQuestionaire::new).collect(Collectors.toList());
|
||||
area.setQuestionaires(areaQuestionaires);
|
||||
areaQuestionaires.forEach(ques -> {
|
||||
ques.setArea(area);
|
||||
ques.getQuestions().stream()
|
||||
.forEach(q -> q.setAnswer(Answer.YES));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
findAddFilledQuestionaires(loadedCompTickets, ticketLocations);
|
||||
}
|
||||
|
||||
getCreated().setLocations(ticketLocations);
|
||||
getCreated().setStatus(Status.NEW);
|
||||
|
||||
personController.reloadActivePerson();
|
||||
getCreated().setCreator(personController.getActiveUser());
|
||||
ticketManager.save(getCreated());
|
||||
getCreated().setContacts(contacts);
|
||||
getCreated().setRequester(requester);
|
||||
ticketManager.save(getCreated());
|
||||
|
||||
List<Ticket> createdTickets = personController.getActiveUser().getCreatedTickets();
|
||||
|
||||
if (createdTickets == null) {
|
||||
createdTickets = new ArrayList<>();
|
||||
}
|
||||
|
||||
createdTickets.add(getCreated());
|
||||
personController.saveActivePerson();
|
||||
sendInfoMessage(SUCCESS_TITLE, "Ticket \"" + getCreated().getNumber() + "\" wurde erstellt");
|
||||
clearEntries();
|
||||
}
|
||||
|
||||
private void findAddFilledQuestionaires(List<Ticket> loadedTickets, List<TicketLocation> ticketLocations) {
|
||||
List<Questionaire> globals = questionaireController.getAllGlobals();
|
||||
//TreeMap<String, TreeMap<String, TicketMachine>> dataTree = new TreeMap<String, TreeMap<String, TicketMachine>>();
|
||||
TreeMap<String, TreeMap<String, TreeMap<String, List<SecurityAreaQuestionaire>>>> dataTree = new TreeMap<>();
|
||||
|
||||
//Create all Location Trees
|
||||
ticketLocations.forEach(loc -> {
|
||||
if (!dataTree.containsKey(loc.getName())) {
|
||||
dataTree.put(loc.getName(), new TreeMap<>());
|
||||
}
|
||||
|
||||
loc.getMachines().forEach(mac -> {
|
||||
TreeMap<String, List<SecurityAreaQuestionaire>> tree = new TreeMap<>();
|
||||
mac.getSecurityAreas().forEach(sa -> tree.put(sa.getName(), null));
|
||||
|
||||
dataTree.get(loc.getName()).put(mac.getName(), tree);
|
||||
});
|
||||
});
|
||||
|
||||
//Find newest questionaires from tickets
|
||||
loadedTickets.stream()
|
||||
.map(ticket -> ticket.getLocations())
|
||||
.filter(locs -> locs != null)
|
||||
.flatMap(List::stream)
|
||||
.filter(loc -> loc != null)
|
||||
.filter(loc -> dataTree.containsKey(loc.getName()))
|
||||
.forEach(loc -> {
|
||||
loc.getMachines().stream()
|
||||
.filter(mac -> dataTree.get(loc.getName()).containsKey(mac.getName()))
|
||||
.forEach(mac -> {
|
||||
mac.getSecurityAreas().stream()
|
||||
.filter(sa -> dataTree.get(loc.getName()).get(mac.getName()).containsKey(sa.getName()))
|
||||
.filter(sa -> sa.getQuestionaires() != null)
|
||||
.filter(sa -> !sa.getQuestionaires().isEmpty())
|
||||
.forEach(sa -> {
|
||||
if (dataTree.get(loc.getName()).get(mac.getName()).get(sa.getName()) == null) {
|
||||
dataTree.get(loc.getName()).get(mac.getName()).put(sa.getName(), sa.getQuestionaires());
|
||||
return;
|
||||
}
|
||||
|
||||
List<SecurityAreaQuestionaire> quests = dataTree.get(loc.getName()).get(mac.getName()).get(sa.getName());
|
||||
if (quests.isEmpty()) {
|
||||
dataTree.get(loc.getName()).get(mac.getName()).put(sa.getName(), sa.getQuestionaires());
|
||||
return;
|
||||
}
|
||||
|
||||
if (quests.get(0).getCreationDate().isBefore(sa.getQuestionaires().get(0).getCreationDate())) {
|
||||
dataTree.get(loc.getName()).get(mac.getName()).put(sa.getName(), sa.getQuestionaires());
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//Try to load and add from newest old Ticket
|
||||
ticketLocations.forEach(loc -> {
|
||||
loc.getMachines().forEach(mac -> {
|
||||
mac.getSecurityAreas().forEach(sa -> {
|
||||
List<SecurityAreaQuestionaire> quests = dataTree.get(loc.getName()).get(mac.getName()).get(sa.getName());
|
||||
|
||||
if (quests != null) {
|
||||
LOGGER.info("Found {} for Location \"{}\", Machine \"{}\", SecArea \"{}\"", quests.size(), loc.getName(), mac.getName(), sa.getName());
|
||||
try {
|
||||
String comment = quests.get(0).getArea().getMachine().getComment();
|
||||
mac.setComment(comment);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
String oldInspectionNr = quests.get(0).getArea().getMachine().getInspectID();
|
||||
mac.setOldInspectionID(oldInspectionNr);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
List<SecurityAreaQuestionaire> created = quests.stream().map(q -> new SecurityAreaQuestionaire(q, sa)).collect(Collectors.toList());
|
||||
sa.setQuestionaires(created);
|
||||
sa.setComment(quests.get(0).getArea().getComment());
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.info("Not Found for Location \"{}\", Machine \"{}\", SecArea \"{}\"", loc.getName(), mac.getName(), sa.getName());
|
||||
List<SecurityAreaQuestionaire> areaQuestionaires = globals.stream().map(SecurityAreaQuestionaire::new).collect(Collectors.toList());
|
||||
sa.setQuestionaires(areaQuestionaires);
|
||||
areaQuestionaires.forEach(ques -> {
|
||||
ques.setArea(sa);
|
||||
ques.getQuestions().stream()
|
||||
.filter(q -> q.isStandardValues())
|
||||
.forEach(q -> q.setAnswer(Answer.YES));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void addSelectedToWatchlist() {
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
setSelected(ticketManager.reloadWithWatchlist(getSelected()));
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
List<Ticket> userList = personController.getActivePersonWithWatchlist().getWatchlist();
|
||||
List<Person> ticketList = getSelected().getWatchers();
|
||||
if (userList == null) {
|
||||
userList = new ArrayList<>();
|
||||
}
|
||||
if (ticketList == null) {
|
||||
ticketList = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (!ticketList.contains(personController.getActiveUser())) {
|
||||
ticketList.add(personController.getActiveUser());
|
||||
}
|
||||
if (!userList.contains(getSelected())) {
|
||||
userList.add(getSelected());
|
||||
}
|
||||
|
||||
personController.saveActivePerson();
|
||||
ticketManager.save(getSelected());
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Ticket \"" + getSelected().getNumber() + "\" wurde der Beobachtungsliste hinzugefügt!");
|
||||
scrollController.reloadScrollList();
|
||||
}
|
||||
|
||||
public void setSelectedToClosed() {
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
}
|
||||
getSelected().setStatus(Status.CLOSED);
|
||||
ticketManager.save(getSelected());
|
||||
|
||||
scrollController.reloadScrollList();
|
||||
|
||||
successMessage();
|
||||
}
|
||||
|
||||
public void assignSelectedToActiveUser() {
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
setSelected(ticketManager.refresh(getSelected()));
|
||||
try {
|
||||
if (getSelected().getOwner() != null) {
|
||||
if (getSelected().getOwner().getId().equals(personController.getActiveUser().getId())) {
|
||||
//Nothing to do
|
||||
sendInfoMessage("Bereits zugewiesen", "Dieses Ticket ist Ihnen bereits zugewiesen!");
|
||||
return;
|
||||
}
|
||||
|
||||
Person oldOwner = getSelected().getOwner();
|
||||
oldOwner = personManager.load(oldOwner);
|
||||
Hibernate.initialize(oldOwner.getAssignTickets());
|
||||
oldOwner.getAssignTickets().remove(getSelected());
|
||||
personManager.save(oldOwner);
|
||||
}
|
||||
|
||||
personController.reloadActivePerson();
|
||||
Person newOwner = personController.getActiveUser();
|
||||
Hibernate.initialize(newOwner);
|
||||
Hibernate.initialize(newOwner.getAssignTickets());
|
||||
if (newOwner.getAssignTickets() == null) {
|
||||
newOwner.setAssignTickets(new ArrayList<>());
|
||||
}
|
||||
newOwner.getAssignTickets().add(getSelected());
|
||||
getSelected().setOwner(newOwner);
|
||||
personManager.save(newOwner);
|
||||
ticketManager.save(getSelected());
|
||||
|
||||
scrollController.reloadScrollList();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Ticket \"" + getSelected().getNumber() + "\" wurde der wurde Ihnen zugewiesen!");
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean checkNameExists(String number) {
|
||||
Long count = ticketManager.countByNumber(number);
|
||||
return count != null ? count > 0L : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Ticket> getManager() {
|
||||
return ticketManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setCreated(new Ticket());
|
||||
getCreated().setStartDate(LocalDateTime.now());
|
||||
getCreated().setEndDate(LocalDateTime.now().plusDays(7));
|
||||
getCreated().setPayed(false);
|
||||
|
||||
setSelected(new Ticket());
|
||||
getEntities().clear();
|
||||
selectedLocations = new ArrayList<>();
|
||||
machineContainers = new ArrayList<>();
|
||||
contacts = new ArrayList<>();
|
||||
requester = new ArrayList<>();
|
||||
|
||||
companyController.clearEntries();
|
||||
loadTicketData = true;
|
||||
}
|
||||
|
||||
public List<Location> getSelectedLocations() {
|
||||
return selectedLocations;
|
||||
}
|
||||
|
||||
public void setSelectedLocations(List<Location> selectedLocations) {
|
||||
this.selectedLocations = selectedLocations;
|
||||
if (selectedLocations != null && !selectedLocations.isEmpty()) {
|
||||
this.machineContainers = new ArrayList<>();
|
||||
selectedLocations.stream()
|
||||
.filter(loc -> loc.getMachines() != null)
|
||||
.filter(loc -> !loc.getMachines().isEmpty())
|
||||
.forEach(loc -> {
|
||||
LOGGER.debug(loc.getMachines().size());
|
||||
machineContainers.add(new MachineContainer(loc));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public List<MachineContainer> getMachineContainers() {
|
||||
return machineContainers;
|
||||
}
|
||||
|
||||
public void setMachineContainers(List<MachineContainer> machineContainers) {
|
||||
this.machineContainers = machineContainers;
|
||||
}
|
||||
|
||||
public FilenameGeneration[] getFilenameGenerations() {
|
||||
return FilenameGeneration.values();
|
||||
}
|
||||
|
||||
public class MachineContainer {
|
||||
|
||||
private Location location;
|
||||
private List<Machine> selectedMachines;
|
||||
|
||||
public MachineContainer(Location location) {
|
||||
this.location = location;
|
||||
selectedMachines = location.getMachines();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public List<Machine> getSelectedMachines() {
|
||||
return selectedMachines;
|
||||
}
|
||||
|
||||
public void setSelectedMachines(List<Machine> selectedMachines) {
|
||||
this.selectedMachines = selectedMachines;
|
||||
}
|
||||
}
|
||||
|
||||
public Answer[] getAnswers() {
|
||||
return Answer.values();
|
||||
}
|
||||
|
||||
public List<Customer> getContacts() {
|
||||
return contacts;
|
||||
}
|
||||
|
||||
public void setContacts(List<Customer> contacts) {
|
||||
this.contacts = contacts;
|
||||
}
|
||||
|
||||
public List<Customer> getRequester() {
|
||||
return requester;
|
||||
}
|
||||
|
||||
public void setRequester(List<Customer> requester) {
|
||||
this.requester = requester;
|
||||
}
|
||||
|
||||
public boolean isLoadTicketData() {
|
||||
return loadTicketData;
|
||||
}
|
||||
|
||||
public void setLoadTicketData(boolean loadTicketData) {
|
||||
this.loadTicketData = loadTicketData;
|
||||
}
|
||||
|
||||
}
|
||||
+312
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.tickets;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.tickets.TicketManager;
|
||||
import controller.AbstractController;
|
||||
import controller.tickets.protocoll.OverviewProtocolController;
|
||||
import controller.tickets.protocoll.ProtocolController;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.files.Mime;
|
||||
import model.files.Report;
|
||||
import model.ticket.Ticket;
|
||||
import model.ticket.dataCopies.TicketLocation;
|
||||
import model.ticket.dataCopies.TicketMachine;
|
||||
import model.ticket.dataCopies.TicketSecurityArea;
|
||||
import model.ticket.enums.Status;
|
||||
import model.ticket.questions.SecurityAreaQuestionaire;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.omnifaces.cdi.Param;
|
||||
import org.primefaces.model.DefaultStreamedContent;
|
||||
import org.primefaces.model.StreamedContent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class TicketEditController extends AbstractController<Ticket>{
|
||||
|
||||
@EJB
|
||||
TicketManager ticketManager;
|
||||
|
||||
@Inject
|
||||
ProtocolController protocolController;
|
||||
|
||||
@Inject
|
||||
OverviewProtocolController overviewProtocolController;
|
||||
|
||||
@Param(name = "number")
|
||||
private String nameParam;
|
||||
|
||||
private TicketLocation selectedLocation;
|
||||
private TicketLocation bkpLocation;
|
||||
private String[] widgets = {"dlgSelAddr1", "dlgSelAddr2"};
|
||||
|
||||
public TicketEditController() {
|
||||
super();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init(){
|
||||
setSelected(ticketManager.loadByNumber(nameParam));
|
||||
//initializeSelected();
|
||||
}
|
||||
|
||||
public void initializeSelected(){
|
||||
if (getSelected() != null) {
|
||||
Hibernate.initialize(getSelected());
|
||||
Hibernate.initialize(getSelected().getCompany().getAddresses());
|
||||
Hibernate.initialize(getSelected().getComments());
|
||||
Hibernate.initialize(getSelected().getContacts());
|
||||
Hibernate.initialize(getSelected().getInvoices());
|
||||
Hibernate.initialize(getSelected().getLocations());
|
||||
Hibernate.initialize(getSelected().getReports());
|
||||
Hibernate.initialize(getSelected().getWatchers());
|
||||
Hibernate.initialize(getSelected().getRequester());
|
||||
|
||||
for(TicketLocation loc : getSelected().getLocations()){
|
||||
for(TicketMachine mac : loc.getMachines()){
|
||||
for(TicketSecurityArea area : mac.getSecurityAreas()){
|
||||
Hibernate.initialize(area);
|
||||
Hibernate.initialize(area.getDangerPoints());
|
||||
Hibernate.initialize(area.getSecurityDevices());
|
||||
Hibernate.initialize(area.getSwitchingDevices());
|
||||
Hibernate.initialize(area.getQuestionaires());
|
||||
for (SecurityAreaQuestionaire q : area.getQuestionaires()) {
|
||||
Hibernate.initialize(q.getQuestions());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Hibernate.initialize(getSelected());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Ticket> getManager() {
|
||||
return ticketManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(null);
|
||||
setCreated(null);
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public TicketLocation getSelectedLocation() {
|
||||
return selectedLocation;
|
||||
}
|
||||
|
||||
public void saveSelected(){
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
ticketManager.save(getSelected());
|
||||
ticketManager.refresh(getSelected());
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Ticket " + getSelected().getNumber() + " wurde gespeichert!");
|
||||
closeDialogs(widgets);
|
||||
}
|
||||
|
||||
public void setTicketStatus(String name){
|
||||
Status loaded = Status.getFromName(name);
|
||||
|
||||
if (loaded == null) {
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
getSelected().setStatus(loaded);
|
||||
sendInfoMessage(SUCCESS_TITLE, "Status wurde geändert zu " + loaded);
|
||||
saveSelected();
|
||||
}
|
||||
|
||||
public void setSelectedLocation(TicketLocation selectedLocation) {
|
||||
if (selectedLocation != null) {
|
||||
bkpLocation = selectedLocation;
|
||||
}
|
||||
this.selectedLocation = selectedLocation;
|
||||
if (selectedLocation == null && bkpLocation != null) {
|
||||
this.selectedLocation = bkpLocation;
|
||||
}
|
||||
}
|
||||
|
||||
public StreamedContent createOverviewProtocol() {
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Report report = overviewProtocolController.createOverviewReport(getSelected());
|
||||
StreamedContent file = DefaultStreamedContent.builder()
|
||||
.name(report.getName())
|
||||
.contentType(report.getMime().getMimeType())
|
||||
.stream(() -> new ByteArrayInputStream(report.getFileData()))
|
||||
.build();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Übersichtsprotokoll wurde erfolgreich erstellt!");
|
||||
return file;
|
||||
|
||||
} catch (Exception io) {
|
||||
LOGGER.error(io);
|
||||
errorMessage();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public StreamedContent createAllProtocolsAsZip() {
|
||||
if (getSelected() == null) {
|
||||
errorMessage();
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// Prefetch full graph for protocol generation
|
||||
//initializeSelected();
|
||||
// Collect all machines from all locations
|
||||
List<TicketMachine> allMachines = new ArrayList<>();
|
||||
for (TicketLocation location : getSelected().getLocations()) {
|
||||
if (location.getMachines() != null) {
|
||||
allMachines.addAll(location.getMachines());
|
||||
}
|
||||
}
|
||||
|
||||
if (allMachines.isEmpty()) {
|
||||
sendErrorMessage("Fehler", "Keine Maschinen im Ticket vorhanden!");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create ZIP file
|
||||
ByteArrayOutputStream zipStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(zipStream);
|
||||
HashMap<String, Integer> fileNameCountMap = new HashMap<>();
|
||||
|
||||
for (TicketMachine machine : allMachines) {
|
||||
try {
|
||||
// Generate PDF report for each machine
|
||||
Report report = protocolController.createReportForMachine(machine);
|
||||
|
||||
// Add PDF to ZIP with sanitized filename to avoid folder creation in ZIP
|
||||
String baseName = cleanFileName(report.getName());
|
||||
String entryName = baseName;
|
||||
int duplicateCount = fileNameCountMap.getOrDefault(baseName, 0);
|
||||
if (duplicateCount > 0) {
|
||||
entryName = appendSuffixToFileName(baseName, "_" + (duplicateCount + 1));
|
||||
}
|
||||
fileNameCountMap.put(baseName, duplicateCount + 1);
|
||||
|
||||
ZipEntry entry = new ZipEntry(entryName);
|
||||
zip.putNextEntry(entry);
|
||||
zip.write(report.getFileData());
|
||||
zip.closeEntry();
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Fehler beim Erstellen des Protokolls für Maschine: " + machine.getName(), e);
|
||||
sendErrorMessage("Fehler", "Fehler beim Erstellen des Protokolls für Maschine: " + machine.getName());
|
||||
}
|
||||
}
|
||||
|
||||
//Add overview protocol
|
||||
try {
|
||||
Report overviewReport = overviewProtocolController.createOverviewReport(getSelected());
|
||||
String overviewBaseName = cleanFileName(overviewReport.getName());
|
||||
String overviewEntryName = overviewBaseName;
|
||||
int overviewCount = fileNameCountMap.getOrDefault(overviewBaseName, 0);
|
||||
if (overviewCount > 0) {
|
||||
overviewEntryName = appendSuffixToFileName(overviewBaseName, "_" + (overviewCount + 1));
|
||||
}
|
||||
fileNameCountMap.put(overviewBaseName, overviewCount + 1);
|
||||
ZipEntry overviewEntry = new ZipEntry(overviewEntryName);
|
||||
zip.putNextEntry(overviewEntry);
|
||||
zip.write(overviewReport.getFileData());
|
||||
zip.closeEntry();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Fehler beim Erstellen des Übersichtsprotokolls", e);
|
||||
sendErrorMessage("Fehler", "Fehler beim Erstellen des Übersichtsprotokolls");
|
||||
}
|
||||
|
||||
zip.close();
|
||||
|
||||
// Create filename for ZIP
|
||||
String zipFileName = cleanFileName("Protokolle_Ticket_" + getSelected().getNumber() + ".zip");
|
||||
|
||||
// Return ZIP as StreamedContent
|
||||
StreamedContent file = DefaultStreamedContent.builder()
|
||||
.name(zipFileName)
|
||||
.contentType("application/zip")
|
||||
.stream(() -> new ByteArrayInputStream(zipStream.toByteArray()))
|
||||
.build();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Alle Protokolle wurden erfolgreich erstellt (" + allMachines.size() + " Maschinen)!");
|
||||
return file;
|
||||
|
||||
} catch (IOException io) {
|
||||
LOGGER.error("Fehler beim Erstellen der ZIP-Datei", io);
|
||||
sendErrorMessage("Fehler", "Fehler beim Erstellen der ZIP-Datei!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String cleanFileName(String original) {
|
||||
if (original == null || original.isEmpty()) {
|
||||
return "file";
|
||||
}
|
||||
String cleaned = original.trim();
|
||||
cleaned = cleaned.replaceAll("[\\\\/:*?\"<>|]", "_");
|
||||
cleaned = cleaned.replaceAll("[\\p{Cntrl}]", "_");
|
||||
cleaned = cleaned.replaceAll("[^A-Za-z0-9._ -]", "_");
|
||||
cleaned = cleaned.replaceAll("_+", "_").trim();
|
||||
if (cleaned.isEmpty() || cleaned.replace(".", "").trim().isEmpty()) {
|
||||
cleaned = "file";
|
||||
}
|
||||
if (cleaned.length() > 200) {
|
||||
int dot = cleaned.lastIndexOf('.');
|
||||
if (dot > 0 && dot < cleaned.length() - 1) {
|
||||
String name = cleaned.substring(0, dot);
|
||||
String ext = cleaned.substring(dot);
|
||||
int maxNameLen = Math.max(1, 200 - ext.length());
|
||||
if (name.length() > maxNameLen) {
|
||||
name = name.substring(0, maxNameLen);
|
||||
}
|
||||
cleaned = name + ext;
|
||||
} else {
|
||||
cleaned = cleaned.substring(0, 200);
|
||||
}
|
||||
}
|
||||
return cleaned;
|
||||
}
|
||||
|
||||
private static String appendSuffixToFileName(String name, String suffix) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
return cleanFileName("file" + suffix);
|
||||
}
|
||||
int dot = name.lastIndexOf('.');
|
||||
if (dot > 0 && dot < name.length() - 1) {
|
||||
return name.substring(0, dot) + suffix + name.substring(dot);
|
||||
}
|
||||
return name + suffix;
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.tickets;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.tickets.TicketManager;
|
||||
import controller.AbstractController;
|
||||
import controller.person.PersonController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.ticket.Ticket;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class TicketScrollController extends AbstractController<Ticket>{
|
||||
@EJB
|
||||
TicketManager ticketManager;
|
||||
|
||||
@Inject
|
||||
PersonController personController;
|
||||
|
||||
private List<Ticket> loaded = new ArrayList<>(TicketManager.BATCH_SIZE);
|
||||
|
||||
public TicketScrollController() {
|
||||
super();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init(){
|
||||
loaded = ticketManager.loadBatchOrderedByCreationDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Ticket> getManager() {
|
||||
return ticketManager;
|
||||
}
|
||||
|
||||
public void reloadScrollList(){
|
||||
loaded = ticketManager.loadBatchOrderedByCreationDate();
|
||||
}
|
||||
|
||||
public void deleteTicket(){
|
||||
LOGGER.info("Trying to delete {}", getSelected());
|
||||
|
||||
|
||||
if(ticketManager.saveDelete(getSelected())){
|
||||
sendInfoMessage(SUCCESS_TITLE, "Ticket " + getSelected().getNumber() + " wurde gelöscht");
|
||||
LOGGER.info("Ticket is deleted");
|
||||
reloadScrollList();
|
||||
setSelected(null);
|
||||
} else {
|
||||
errorMessage();
|
||||
LOGGER.error("Couldn't delete ticket");
|
||||
}
|
||||
}
|
||||
|
||||
protected void refreshTicketInList(){
|
||||
if (getSelected() == null || loaded == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (loaded.contains(getSelected())) {
|
||||
int i = loaded.indexOf(getSelected());
|
||||
//Ticket fromLoaded = loaded.get(i);
|
||||
//fromLoaded = ticketManager.refresh(fromLoaded);
|
||||
loaded.set(i, getSelected());
|
||||
}
|
||||
|
||||
FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add("mainform");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setCreated(null);
|
||||
setSelected(null);
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public List<Ticket> getLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
}
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.tickets.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.tickets.machine.TicketMachineManager;
|
||||
import business.tickets.machine.TicketQuestionManager;
|
||||
import business.tickets.machine.TicketQuestionaireManager;
|
||||
import controller.AbstractController;
|
||||
import controller.questions.QuestionaireController;
|
||||
import controller.tickets.protocoll.ProtocolController;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import model.files.Report;
|
||||
import model.ticket.enums.SimpleAnswer;
|
||||
import model.ticket.dataCopies.TicketMachine;
|
||||
import model.ticket.enums.InspectionType;
|
||||
import model.ticket.questions.TicketQuestion;
|
||||
import model.ticket.questions.TicketQuestionaire;
|
||||
import org.primefaces.model.DefaultStreamedContent;
|
||||
import org.primefaces.model.StreamedContent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class TicketMachineController extends AbstractController<TicketMachine> {
|
||||
|
||||
@Inject
|
||||
QuestionaireController questionaireController;
|
||||
|
||||
@EJB
|
||||
TicketQuestionaireManager ticketQuestionaireManager;
|
||||
|
||||
@EJB
|
||||
TicketQuestionManager ticketQuestionManager;
|
||||
|
||||
@EJB
|
||||
TicketMachineManager machineManager;
|
||||
|
||||
@Inject
|
||||
ProtocolController protocolController;
|
||||
|
||||
private TicketQuestionaire selectedQuestionaire;
|
||||
|
||||
private TicketMachine bkpMachine;
|
||||
|
||||
private List<TicketMachine> filteredMachines;
|
||||
|
||||
private static final String[] WIDGETS = {"dlgEditSec"};
|
||||
|
||||
public TicketMachineController() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void addQuestionaire() {
|
||||
|
||||
if (questionaireController.getSelected() == null || bkpMachine == null) {
|
||||
System.out.println("controller.tickets.machine.TicketMachineController.addQuestionaire()" + questionaireController.getSelected() + " / " + getSelected());
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
setSelected(bkpMachine);
|
||||
|
||||
TicketQuestionaire created = new TicketQuestionaire(questionaireController.getSelected());
|
||||
created.setMachine(getSelected());
|
||||
|
||||
if (getSelected().getQuestionaires() == null) {
|
||||
getSelected().setQuestionaires(new ArrayList<>());
|
||||
}
|
||||
|
||||
getSelected().getQuestionaires().add(created);
|
||||
|
||||
saveSelected();
|
||||
sendInfoMessage(SUCCESS_TITLE, "Checkliste " + created.getName() + " wurde hinzugefügt!");
|
||||
}
|
||||
|
||||
public void removeQuestionaire() {
|
||||
if (selectedQuestionaire == null || bkpMachine == null) {
|
||||
System.out.println("controller.tickets.machine.TicketMachineController.removeQ()" + questionaireController.getSelected() + " / " + getSelected());
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
setSelected(bkpMachine);
|
||||
TicketQuestionaire toDelete = null;
|
||||
|
||||
for (int i = 0; i < getSelected().getQuestionaires().size(); i++) {
|
||||
TicketQuestionaire q = getSelected().getQuestionaires().get(i);
|
||||
System.out.println(q.getId() + " / " + selectedQuestionaire.getId());
|
||||
if (q.getId().equals(selectedQuestionaire.getId())) {
|
||||
toDelete = q;
|
||||
}
|
||||
}
|
||||
|
||||
if (toDelete == null) {
|
||||
System.err.println("Not found toDelete");
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
getSelected().getQuestionaires().remove(toDelete);
|
||||
|
||||
List<TicketQuestion> questions = toDelete.getQuestions();
|
||||
questions.forEach(q -> q.setQuestionaire(null));
|
||||
toDelete.setQuestions(null);
|
||||
ticketQuestionaireManager.save(toDelete);
|
||||
ticketQuestionManager.removeAllIn(questions);
|
||||
ticketQuestionaireManager.remove(toDelete);
|
||||
|
||||
saveSelected();
|
||||
sendInfoMessage(SUCCESS_TITLE, "Checkliste " + questionaireController.getSelected().getName() + " wurde entfernt!");
|
||||
}
|
||||
|
||||
public void saveSelected() {
|
||||
if (getSelected() == null) {
|
||||
setSelected(bkpMachine);
|
||||
}
|
||||
machineManager.save(getSelected());
|
||||
machineManager.refresh(getSelected());
|
||||
sendInfoMessage(SUCCESS_TITLE, "Machine " + getSelected().getName() + " wurde gespeichert!");
|
||||
}
|
||||
|
||||
public void saveSelectedChanges() {
|
||||
if (getSelected() == null) {
|
||||
setSelected(bkpMachine);
|
||||
}
|
||||
machineManager.save(getSelected());
|
||||
machineManager.refresh(getSelected());
|
||||
sendInfoMessage(SUCCESS_TITLE, "Machine " + getSelected().getName() + " wurde gespeichert!");
|
||||
|
||||
closeDialogs(WIDGETS);
|
||||
}
|
||||
|
||||
public void resetSelectMachine() {
|
||||
saveSelected();
|
||||
setSelected(null);
|
||||
}
|
||||
|
||||
public StreamedContent createSelectedMachinePrint() {
|
||||
try {
|
||||
Report report = protocolController.createReportForMachine(bkpMachine);
|
||||
StreamedContent file = DefaultStreamedContent.builder()
|
||||
.name(report.getName())
|
||||
.contentType(report.getMime().getMimeType())
|
||||
.stream(() -> {
|
||||
return new ByteArrayInputStream(report.getFileData());
|
||||
})
|
||||
.build();
|
||||
|
||||
return file;
|
||||
} catch (IOException io) {
|
||||
LOGGER.error(io);
|
||||
errorMessage();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<TicketMachine> getManager() {
|
||||
return machineManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(TicketMachine selected) {
|
||||
if (selected != null) {
|
||||
bkpMachine = selected;
|
||||
}
|
||||
super.setSelected(selected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
getEntities().clear();
|
||||
setSelected(null);
|
||||
setCreated(null);
|
||||
}
|
||||
|
||||
public SimpleAnswer[] getSimpleAnswers() {
|
||||
return SimpleAnswer.values();
|
||||
}
|
||||
|
||||
public TicketQuestionaire getSelectedQuestionaire() {
|
||||
return selectedQuestionaire;
|
||||
}
|
||||
|
||||
public void setSelectedQuestionaire(TicketQuestionaire selectedQuestionaire) {
|
||||
this.selectedQuestionaire = selectedQuestionaire;
|
||||
}
|
||||
|
||||
public TicketMachine getBkpMachine() {
|
||||
return bkpMachine;
|
||||
}
|
||||
|
||||
public void setBkpMachine(TicketMachine bkpMachine) {
|
||||
this.bkpMachine = bkpMachine;
|
||||
}
|
||||
|
||||
public List<TicketMachine> getFilteredMachines() {
|
||||
return filteredMachines;
|
||||
}
|
||||
|
||||
public void setFilteredMachines(List<TicketMachine> filteredMachines) {
|
||||
this.filteredMachines = filteredMachines;
|
||||
}
|
||||
|
||||
public InspectionType[] getInspectionTypes(){
|
||||
return InspectionType.values();
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+156
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package controller.tickets.machine;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.tickets.machine.TicketSecurityAreaManager;
|
||||
import business.tickets.machine.TicketSecurityAreaQuestionManager;
|
||||
import business.tickets.machine.TicketSecurityAreaQuestionaireManager;
|
||||
import controller.AbstractController;
|
||||
import static controller.AbstractController.SUCCESS_TITLE;
|
||||
import controller.questions.QuestionaireController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.transaction.Transactional;
|
||||
import model.ticket.dataCopies.TicketLocation;
|
||||
import model.ticket.dataCopies.TicketMachine;
|
||||
import model.ticket.dataCopies.TicketSecurityArea;
|
||||
import model.ticket.questions.SecurityAreaQuestion;
|
||||
import model.ticket.questions.SecurityAreaQuestionaire;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@ViewScoped
|
||||
@Named
|
||||
public class TicketSecurityAreaController extends AbstractController<TicketSecurityArea> {
|
||||
|
||||
@EJB
|
||||
TicketSecurityAreaManager ticketSecurityAreaManager;
|
||||
|
||||
@EJB
|
||||
TicketSecurityAreaQuestionaireManager questionaireManager;
|
||||
|
||||
@EJB
|
||||
TicketSecurityAreaQuestionManager questionManager;
|
||||
|
||||
@Inject
|
||||
QuestionaireController questionaireController;
|
||||
|
||||
@Inject
|
||||
TicketMachineController machineController;
|
||||
|
||||
private TicketSecurityArea bkpArea;
|
||||
|
||||
private SecurityAreaQuestionaire selectedQuestionaire;
|
||||
|
||||
@Override
|
||||
protected AbstractManager<TicketSecurityArea> getManager() {
|
||||
return ticketSecurityAreaManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
setSelected(new TicketSecurityArea());
|
||||
setCreated(null);
|
||||
getEntities().clear();
|
||||
}
|
||||
|
||||
public void addQuestionaire() {
|
||||
|
||||
if (questionaireController.getSelected() == null || bkpArea == null) {
|
||||
LOGGER.error("controller.tickets.machine.TicketMachineController.addQuestionaire()" + questionaireController.getSelected() + " / " + getSelected());
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
SecurityAreaQuestionaire created = new SecurityAreaQuestionaire(questionaireController.getSelected());
|
||||
created.setArea(getSelected());
|
||||
|
||||
if (getSelected().getQuestionaires() == null) {
|
||||
getSelected().setQuestionaires(new ArrayList<>());
|
||||
}
|
||||
|
||||
getSelected().getQuestionaires().add(created);
|
||||
questionaireManager.save(created);
|
||||
saveSelected();
|
||||
|
||||
sendInfoMessage(SUCCESS_TITLE, "Checkliste " + created.getName() + " wurde hinzugefügt!");
|
||||
machineController.setSelected(getSelected().getMachine());
|
||||
}
|
||||
|
||||
public void removeQuestionaire() {
|
||||
if (selectedQuestionaire == null || bkpArea == null) {
|
||||
System.out.println("controller.tickets.machine.TicketMachineController.removeQ()" + questionaireController.getSelected() + " / " + getSelected());
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
SecurityAreaQuestionaire toDelete = null;
|
||||
|
||||
for (int i = 0; i < getSelected().getQuestionaires().size(); i++) {
|
||||
SecurityAreaQuestionaire q = getSelected().getQuestionaires().get(i);
|
||||
LOGGER.debug(q.getId() + " / " + selectedQuestionaire.getId());
|
||||
if (q.getId().equals(selectedQuestionaire.getId())) {
|
||||
toDelete = q;
|
||||
}
|
||||
}
|
||||
|
||||
if (toDelete == null) {
|
||||
System.err.println("Not found toDelete");
|
||||
errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
getSelected().getQuestionaires().remove(toDelete);
|
||||
|
||||
//List<SecurityAreaQuestion> questions = toDelete.getQuestions();
|
||||
//questions.forEach(q -> q.setQuestionaire(null));
|
||||
//toDelete.setQuestions(null);
|
||||
//questionaireManager.save(toDelete);
|
||||
//questionManager.removeAllIn(questions);
|
||||
questionaireManager.remove(toDelete);
|
||||
|
||||
saveSelected();
|
||||
sendInfoMessage(SUCCESS_TITLE, "Checkliste wurde entfernt!");
|
||||
machineController.setSelected(getSelected().getMachine());
|
||||
//machineController.saveSelected();
|
||||
}
|
||||
|
||||
public void saveSelected() {
|
||||
if (getSelected() == null) {
|
||||
setSelected(bkpArea);
|
||||
}
|
||||
ticketSecurityAreaManager.save(getSelected());
|
||||
sendInfoMessage(SUCCESS_TITLE, "Schutzbereich " + getSelected().getName() + " wurde gespeichert!");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void setSelected(TicketSecurityArea selected) {
|
||||
|
||||
super.setSelected(selected);
|
||||
|
||||
if (selected != null) {
|
||||
bkpArea = selected;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public SecurityAreaQuestionaire getSelectedQuestionaire() {
|
||||
return selectedQuestionaire;
|
||||
}
|
||||
|
||||
public void setSelectedQuestionaire(SecurityAreaQuestionaire selectedQuestionaire) {
|
||||
this.selectedQuestionaire = selectedQuestionaire;
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+505
@@ -0,0 +1,505 @@
|
||||
package controller.tickets.protocoll;
|
||||
|
||||
import business.AbstractManager;
|
||||
import business.tickets.machine.TicketMachineManager;
|
||||
import business.tickets.machine.TicketSecurityAreaManager;
|
||||
import business.tickets.protocoll.ProtocolManager;
|
||||
import com.itextpdf.io.font.constants.StandardFonts;
|
||||
import com.itextpdf.layout.borders.Border;
|
||||
import com.itextpdf.layout.borders.SolidBorder;
|
||||
import controller.AbstractController;
|
||||
import controller.person.PersonController;
|
||||
import controller.tickets.TicketEditController;
|
||||
import model.files.Mime;
|
||||
import model.files.Report;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
import com.itextpdf.kernel.font.PdfFontFactory;
|
||||
import com.itextpdf.kernel.geom.PageSize;
|
||||
import com.itextpdf.kernel.pdf.PdfDocument;
|
||||
import com.itextpdf.kernel.pdf.PdfDocumentInfo;
|
||||
import com.itextpdf.kernel.pdf.PdfReader;
|
||||
import com.itextpdf.kernel.pdf.PdfWriter;
|
||||
import com.itextpdf.layout.Document;
|
||||
import com.itextpdf.layout.element.Cell;
|
||||
import com.itextpdf.layout.element.Image;
|
||||
import com.itextpdf.layout.element.Paragraph;
|
||||
import com.itextpdf.layout.element.Table;
|
||||
import com.itextpdf.layout.element.Text;
|
||||
import model.security.enums.DeviceRole;
|
||||
import model.ticket.Ticket;
|
||||
import model.ticket.dataCopies.*;
|
||||
|
||||
@Named
|
||||
@RequestScoped
|
||||
public class OverviewProtocolController extends AbstractController<Report> {
|
||||
|
||||
@EJB
|
||||
ProtocolManager protocolManager;
|
||||
|
||||
@Inject
|
||||
TicketEditController editController;
|
||||
|
||||
@Inject
|
||||
PersonController personController;
|
||||
|
||||
@EJB
|
||||
TicketMachineManager machineManager;
|
||||
|
||||
@EJB
|
||||
TicketSecurityAreaManager areaManager;
|
||||
|
||||
private Image logo;
|
||||
|
||||
private static final String FONT_BOLD = StandardFonts.HELVETICA_BOLD;
|
||||
private static final String FONT_NORMAL = StandardFonts.HELVETICA;
|
||||
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||
|
||||
public OverviewProtocolController() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Report createOverviewReport(Ticket selected) {
|
||||
if (selected == null) {
|
||||
sendErrorMessage("Fehler","Es wurde kein Ticket zum Erstellen des Protokolls ausgewählt!");
|
||||
return null;
|
||||
}
|
||||
byte[] pdfData = createPDFInMemory();
|
||||
if (pdfData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Report created = new Report();
|
||||
created = new Report();
|
||||
created.setName("Serviceprotokoll_" + selected.getNumber() + ".pdf");
|
||||
created.setFileData(pdfData);
|
||||
created.setMime(Mime.PDF);
|
||||
|
||||
return created;
|
||||
}
|
||||
|
||||
private byte[] createPDFInMemory() {
|
||||
ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
|
||||
PdfWriter writer;
|
||||
PdfDocument document;
|
||||
Document doc;
|
||||
|
||||
logo = logo == null ? loadCompanyLogo() : logo;
|
||||
|
||||
if (logo == null) {
|
||||
LOGGER.warn("Logo could not be loaded from path: " + LOGO_PATH);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// Create first PDF in memory
|
||||
writer = new PdfWriter(pdfStream);
|
||||
document = new PdfDocument(writer);
|
||||
doc = new Document(document, PageSize.A4, true);
|
||||
doc.setMargins(45F, 35F, 35F, 35F);
|
||||
|
||||
Ticket ticket = editController.getSelected();
|
||||
if (ticket == null) {
|
||||
sendErrorMessage("Fehler","Es wurde kein Ticket zum Erstellen des Protokolls ausgewählt!");
|
||||
return null;
|
||||
}
|
||||
|
||||
addDocumentInfo(document, ticket);
|
||||
addHeader(doc);
|
||||
addHeadline(doc, "Serviceprotokoll " + ticket.getNumber());
|
||||
addAuftragsdaten(doc, ticket);
|
||||
addNachlaufMessungen(doc, ticket);
|
||||
addAnzahlProSchutzeinrichtung(doc, ticket);
|
||||
addAnzahlInspektionenMaschinen(doc, ticket);
|
||||
addHinweiseUndErlaeuterungen(doc, ticket);
|
||||
|
||||
doc.close();
|
||||
document.close();
|
||||
writer.close();
|
||||
|
||||
// Create final PDF with page numbers in memory
|
||||
ByteArrayOutputStream finalPdfStream = new ByteArrayOutputStream();
|
||||
PdfReader reader = new PdfReader(new ByteArrayInputStream(pdfStream.toByteArray()));
|
||||
writer = new PdfWriter(finalPdfStream);
|
||||
document = new PdfDocument(reader, writer);
|
||||
doc = new Document(document);
|
||||
addPagenumbers(doc, ticket.getNumber() == null ? "-/-" : ticket.getNumber(), loadCompanyLogo());
|
||||
doc.close();
|
||||
document.close();
|
||||
reader.close();
|
||||
writer.close();
|
||||
|
||||
return finalPdfStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
errorMessage();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void addDocumentInfo(PdfDocument document, Ticket ticket) {
|
||||
PdfDocumentInfo info = document.getDocumentInfo();
|
||||
info.setTitle("Serviceprotokoll - " + ticket.getNumber());
|
||||
info.setAuthor((ticket.getOwner() == null ? "-/-" : ticket.getOwner().getLastname() + ", " + ticket.getOwner().getFirstname()));
|
||||
info.setKeywords("Protokoll maschinell generiert");
|
||||
info.setCreator("Softwarehersteller fuer Mss-Safety");
|
||||
}
|
||||
|
||||
private void addHeader(Document doc) throws IOException {
|
||||
// Creating a table
|
||||
float[] pointColumnWidths = {250F, 250F};
|
||||
Table table = new Table(pointColumnWidths);
|
||||
table.setBorder(Border.NO_BORDER);
|
||||
table.setMarginTop(-20F);
|
||||
|
||||
logo.scale(0.13F, 0.13F);
|
||||
logo.setMarginTop(-5F);
|
||||
Cell logoCell = new Cell().add(logo);
|
||||
logoCell.setBorder(Border.NO_BORDER);
|
||||
table.addCell(logoCell);
|
||||
|
||||
Text textHead = new Text(
|
||||
"MSS Machine Safety Services GmbH \r\n"
|
||||
+ "Lüneburger Str. 48 \r\n"
|
||||
+ "D-28870 Ottersberg \r\n"
|
||||
+ "E-Mail: Kontakt@MSS-Failsafe.com"
|
||||
);
|
||||
|
||||
textHead.setFont(PdfFontFactory.createFont(FONT_BOLD));
|
||||
textHead.setFontSize(10F);
|
||||
textHead.setHorizontalScaling(0.9F);
|
||||
|
||||
Paragraph pheader = new Paragraph();
|
||||
pheader.add(textHead);
|
||||
pheader.setMarginLeft(10F);
|
||||
pheader.setMultipliedLeading(1F);
|
||||
|
||||
Cell addressCell = new Cell().add(pheader);
|
||||
addressCell.setBorder(Border.NO_BORDER);
|
||||
table.addCell(addressCell);
|
||||
doc.add(table);
|
||||
}
|
||||
|
||||
private void addHeadline(Document doc, String headline) throws IOException {
|
||||
Paragraph pheadline = new Paragraph(headline);
|
||||
pheadline.setFont(PdfFontFactory.createFont(FONT_BOLD));
|
||||
pheadline.setFontSize(16F);
|
||||
pheadline.setMarginTop(20F);
|
||||
pheadline.setMarginLeft(20F);
|
||||
doc.add(pheadline);
|
||||
}
|
||||
|
||||
private void addAuftragsdaten(Document doc, Ticket ticket) throws IOException {
|
||||
Table auftragsdaten = generateSorroundingTable("Auftragsdaten", 520F);
|
||||
String dateString;
|
||||
if (ticket.getStartDate() != null && ticket.getEndDate() != null) {
|
||||
dateString = formatter.format(ticket.getStartDate()) + " - " + formatter.format(ticket.getEndDate());
|
||||
} else if (ticket.getStartDate() != null) {
|
||||
dateString = formatter.format(ticket.getStartDate());
|
||||
} else {
|
||||
dateString = "-/-";
|
||||
}
|
||||
|
||||
Cell firma = generateInnerTable(new Text("Firma"), true,
|
||||
"Firmenname", ticket.getCompany().getName(),
|
||||
"Straße/Hsnr.", ticket.getServiceAddress().getStreet() + (ticket.getServiceAddress().getNumber() == null ? "" : ticket.getServiceAddress().getNumber()),
|
||||
"Plz/Ort", String.format("%05d %s", ticket.getServiceAddress().getPostnumber(), ticket.getServiceAddress().getPlace()),
|
||||
"Staat", ticket.getServiceAddress().getCountry(),
|
||||
"Ticket-Nr.", ticket.getNumber(),
|
||||
"Kundennummer", ticket.getCompany().getKundenNr(),
|
||||
"Prüfer", (ticket.getOwner() == null ? "-/-" : ticket.getOwner().getLastname() + ", " + ticket.getOwner().getFirstname()),
|
||||
"Datum", dateString
|
||||
);
|
||||
|
||||
auftragsdaten.addCell(firma);
|
||||
auftragsdaten.setBorderBottom(new SolidBorder(0.5F));
|
||||
auftragsdaten.setMarginBottom(10.0F);
|
||||
doc.add(auftragsdaten);
|
||||
auftragsdaten.complete();
|
||||
}
|
||||
|
||||
private void addNachlaufMessungen(Document doc, Ticket ticket) throws IOException {
|
||||
Table table = generateSorroundingTable("Anzahl Inspektionen und Nachlaufmessungen", 520F);
|
||||
if (ticket.getLocations() == null || ticket.getLocations().isEmpty()) {
|
||||
LOGGER.warn("No locations found for ticket: " + ticket.getNumber());
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Integer> herstellerCounts = new HashMap<>();
|
||||
Map<String, Integer> gefahrenpunktCounts = new HashMap<>();
|
||||
for (TicketLocation location : ticket.getLocations()) {
|
||||
if (location.getMachines() == null || location.getMachines().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
for (TicketMachine machine : location.getMachines()) {
|
||||
if (machine.getSecurityAreas() == null || machine.getSecurityAreas().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
//machine = machineManager.refresh(machine);
|
||||
//Hibernate.initialize(machine.getSecurityAreas());
|
||||
|
||||
for(TicketSecurityArea area : machine.getSecurityAreas()){
|
||||
//area = areaManager.reloadWithAll(area);
|
||||
|
||||
area.getSecurityDevices().stream()
|
||||
.filter(device -> device.getType() != null)
|
||||
.filter(device -> (device.getDeviceRole() == DeviceRole.BASE || device.getDeviceRole() == DeviceRole.HOST || device.getDeviceRole() == null))
|
||||
.forEach(device ->{
|
||||
String hersteller = device.getCompany() == null ? "Unbekannt" : device.getCompany().getName();
|
||||
herstellerCounts.put(hersteller, herstellerCounts.getOrDefault(hersteller, 0) + 1);
|
||||
});
|
||||
area.getDangerPoints().stream()
|
||||
.filter(dp -> dp.getMessung() != null && dp.getMessung() == true)
|
||||
.filter(dp -> dp.getMeasuringPoint() != null)
|
||||
.filter(dp -> dp.getSecurityDistance() != null && dp.getSecurityDistance() > 0)
|
||||
.forEach(dp -> {
|
||||
String hersteller = dp.getSecurityDevice().getCompany() == null ? "Unbekannt" : dp.getSecurityDevice().getCompany().getName();
|
||||
gefahrenpunktCounts.put(hersteller, gefahrenpunktCounts.getOrDefault(hersteller, 0) + 1);
|
||||
});
|
||||
/*
|
||||
area.getSwitchingDevices().forEach(device ->{
|
||||
String hersteller = device.getCompany() == null ? "Unbekannt" : device.getCompany().getName();
|
||||
herstellerCounts.put(hersteller, herstellerCounts.getOrDefault(hersteller, 0) + 1);
|
||||
});*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String[] tableValues = new String[herstellerCounts.size() * 3 + 6];
|
||||
tableValues[0] = "Schutzeinrichtung\r\n-Hersteller";
|
||||
tableValues[1] = "Anzahl Inspektionen";
|
||||
tableValues[2] = "Anzahl NLZ-Messungen";
|
||||
int index = 3;
|
||||
for (Map.Entry<String, Integer> entry : herstellerCounts.entrySet()) {
|
||||
tableValues[index] = entry.getKey();
|
||||
tableValues[index + 1] = String.valueOf(entry.getValue());
|
||||
tableValues[index + 2] = String.valueOf(gefahrenpunktCounts.getOrDefault(entry.getKey(), 0));
|
||||
index += 3;
|
||||
}
|
||||
|
||||
tableValues[index] = "Gesamtanzahl";
|
||||
tableValues[index + 1] = String.valueOf(herstellerCounts.values().stream().mapToInt(Integer::intValue).sum());
|
||||
tableValues[index + 2] = String.valueOf(gefahrenpunktCounts.values().stream().mapToInt(Integer::intValue).sum());
|
||||
|
||||
Cell innerTable = generateInnerTable(new Text(""),3, true, tableValues);
|
||||
|
||||
table.addCell(innerTable);
|
||||
table.setBorderBottom(new SolidBorder(0.5F));
|
||||
table.setMarginBottom(10.0F);
|
||||
doc.add(table);
|
||||
table.complete();
|
||||
}
|
||||
|
||||
private void addAnzahlProSchutzeinrichtung(Document doc, Ticket ticket) throws IOException {
|
||||
Table table = generateSorroundingTable("Anzahl Inspektionen und Nachlaufmessungen", 520F);
|
||||
if (ticket.getLocations() == null || ticket.getLocations().isEmpty()) {
|
||||
LOGGER.warn("No locations found for ticket: " + ticket.getNumber());
|
||||
return;
|
||||
}
|
||||
Map<String, Integer> schutztypCounts = new HashMap<>();
|
||||
Map<String, Integer> dpCounts = new HashMap<>();
|
||||
|
||||
for (TicketLocation location : ticket.getLocations()) {
|
||||
if (location.getMachines() == null || location.getMachines().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
for (TicketMachine machine : location.getMachines()) {
|
||||
if (machine.getSecurityAreas() == null || machine.getSecurityAreas().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
//machine = machineManager.refresh(machine);
|
||||
//Hibernate.initialize(machine.getSecurityAreas());
|
||||
|
||||
for(TicketSecurityArea area : machine.getSecurityAreas()){
|
||||
//area = areaManager.reloadWithAll(area);
|
||||
|
||||
area.getSecurityDevices().stream()
|
||||
.filter(device -> device.getType() != null)
|
||||
.filter(device -> (device.getDeviceRole() == DeviceRole.BASE || device.getDeviceRole() == DeviceRole.HOST || device.getDeviceRole() == null))
|
||||
.forEach(device ->{
|
||||
String type = device.getType() == null ? "Unbekannt" : device.getType().getName();
|
||||
schutztypCounts.put(type, schutztypCounts.getOrDefault(type, 0) + 1);
|
||||
});
|
||||
area.getDangerPoints().stream()
|
||||
.filter(dp -> dp.getMessung() != null && dp.getMessung() == true)
|
||||
.filter(dp -> dp.getMeasuringPoint() != null)
|
||||
.filter(dp -> dp.getSecurityDistance() != null && dp.getSecurityDistance() > 0)
|
||||
.forEach(dp -> {
|
||||
String type = dp.getSecurityDevice().getType() == null ? "Unbekannt" : dp.getSecurityDevice().getType().getName();
|
||||
dpCounts.put(type, dpCounts.getOrDefault(type, 0) + 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String[] tableValues = new String[schutztypCounts.size() * 3 + 6];
|
||||
tableValues[0] = "Anzahl Inspektionen pro Schutzeinrichtungstyp";
|
||||
tableValues[1] = "Anzahl Inspektionen";
|
||||
tableValues[2] = "Anzahl NLZ-Messungen Standard";
|
||||
int index = 3;
|
||||
for (Map.Entry<String, Integer> entry : schutztypCounts.entrySet()) {
|
||||
tableValues[index] = entry.getKey();
|
||||
tableValues[index + 1] = String.valueOf(entry.getValue());
|
||||
tableValues[index + 2] = String.valueOf(dpCounts.getOrDefault(entry.getKey(), 0));
|
||||
index += 3;
|
||||
}
|
||||
tableValues[index] = "Gesamtanzahl";
|
||||
tableValues[index + 1] = String.valueOf(schutztypCounts.values().stream().mapToInt(Integer::intValue).sum());
|
||||
tableValues[index + 2] = String.valueOf(dpCounts.values().stream().mapToInt(Integer::intValue).sum());
|
||||
|
||||
Cell innerTable = generateInnerTable(new Text(""),3, true, tableValues);
|
||||
|
||||
table.addCell(innerTable);
|
||||
|
||||
table.setBorderBottom(new SolidBorder(0.5F));
|
||||
table.setMarginBottom(10.0F);
|
||||
doc.add(table);
|
||||
table.complete();
|
||||
}
|
||||
|
||||
private void addAnzahlInspektionenMaschinen(Document doc, Ticket ticket) throws IOException {
|
||||
Table table = generateSorroundingTable("Anzahl Inspektionen pro Maschine", 520F);
|
||||
if (ticket.getLocations() == null || ticket.getLocations().isEmpty()) {
|
||||
LOGGER.warn("No locations found for ticket: " + ticket.getNumber());
|
||||
return;
|
||||
}
|
||||
|
||||
List<String[]> data = new ArrayList<>();
|
||||
String[] headers = new String[]{
|
||||
"Standort",
|
||||
"Maschine",
|
||||
"Inspektionsnr.",
|
||||
"Anzahl Inspektionen",
|
||||
"Anzahl NLZ-Messungen Standard",
|
||||
"Anzahl NLZ-Messungen erweitert"
|
||||
};
|
||||
data.add(headers);
|
||||
int totalInspections = 0;
|
||||
int totalNLZStandard = 0;
|
||||
for (TicketLocation location : ticket.getLocations()) {
|
||||
if (location.getMachines() == null || location.getMachines().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean isFirstMachine = true;
|
||||
for (TicketMachine machine : location.getMachines()) {
|
||||
int inspections = 0;
|
||||
int nlzStandard = 0;
|
||||
for(TicketSecurityArea area : machine.getSecurityAreas()){
|
||||
//area = areaManager.reloadWithAll(area);
|
||||
for (TicketSecurityDevice device : area.getSecurityDevices()){
|
||||
if (device.getDeviceRole() == null){
|
||||
inspections++;
|
||||
continue;
|
||||
}
|
||||
if(device.getDeviceRole() == DeviceRole.BASE || device.getDeviceRole() == DeviceRole.HOST){
|
||||
inspections++;
|
||||
}
|
||||
}
|
||||
for(TicketDangerPoint dp : area.getDangerPoints()){
|
||||
if (dp.getMessung() != null && dp.getMessung() == true
|
||||
&& dp.getMeasuringPoint() != null
|
||||
&& dp.getSecurityDistance() != null
|
||||
&& dp.getSecurityDistance() > 0){
|
||||
nlzStandard++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String[] row = new String[6];
|
||||
row[0] = isFirstMachine ? location.getName() : "";
|
||||
row[1] = machine.getName();
|
||||
row[2] = machine.getInspectID() == null ? "-/-" : machine.getInspectID ();
|
||||
row[3] = String.valueOf(inspections);
|
||||
row[4] = String.valueOf(nlzStandard);
|
||||
row[5] = "";
|
||||
data.add(row);
|
||||
isFirstMachine = false;
|
||||
totalInspections += inspections;
|
||||
totalNLZStandard += nlzStandard;
|
||||
}
|
||||
}
|
||||
String[] totalRow = new String[6];
|
||||
totalRow[0] = "Gesamtanzahl";
|
||||
totalRow[1] = "";
|
||||
totalRow[2] = "";
|
||||
totalRow[3] = String.valueOf(totalInspections);
|
||||
totalRow[4] = String.valueOf(totalNLZStandard);
|
||||
totalRow[5] = "";
|
||||
data.add(totalRow);
|
||||
|
||||
// Convert List<String[]> to a single String[] for the table generation
|
||||
String[] tableValues = data.stream().flatMap(Arrays::stream).toArray(String[]::new);
|
||||
Cell innerTable = generateInnerTable(new Text(""),6, true, tableValues);
|
||||
table.addCell(innerTable);
|
||||
|
||||
table.setBorderBottom(new SolidBorder(0.5F));
|
||||
table.setMarginBottom(10.0F);
|
||||
doc.add(table);
|
||||
table.complete();
|
||||
}
|
||||
|
||||
private void addHinweiseUndErlaeuterungen(Document doc, Ticket ticket) throws IOException {
|
||||
Table table = generateSorroundingTable("Inspektionen mit Hinweisen und Erläuterungen", 520F);
|
||||
if (ticket.getLocations() == null || ticket.getLocations().isEmpty()) {
|
||||
LOGGER.warn("No locations found for ticket: " + ticket.getNumber());
|
||||
return;
|
||||
}
|
||||
|
||||
List<String[]> data = new ArrayList<>();
|
||||
String[] headers = new String[]{
|
||||
"Standort Maschine Inspektionsnummer",
|
||||
"Schutzbereich/Wirkbereich",
|
||||
"Bemerkungen zur Inspektion"
|
||||
};
|
||||
data.add(headers);
|
||||
for (TicketLocation location : ticket.getLocations()) {
|
||||
if (location.getMachines() == null || location.getMachines().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
boolean isFirstMachine = true;
|
||||
for (TicketMachine machine : location.getMachines()) {
|
||||
for(TicketSecurityArea area : machine.getSecurityAreas()){
|
||||
//area = areaManager.reloadWithAll(area);
|
||||
|
||||
String[] row = new String[3];
|
||||
row[0] = isFirstMachine ? location.getName() + "\r\n" + machine.getName() + "\r\n" + (machine.getInspectID() == null ? "-/-" : machine.getInspectID ()) : "";
|
||||
row[1] = area.getName();
|
||||
row[2] = area.getComment() == null ? "" : area.getComment();
|
||||
data.add(row);
|
||||
isFirstMachine = false;
|
||||
}
|
||||
isFirstMachine = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert List<String[]> to a single String[] for the table generation
|
||||
String[] tableValues = data.stream().flatMap(Arrays::stream).toArray(String[]::new);
|
||||
Cell innerTable = generateInnerTable(new Text(""),3, true, tableValues);
|
||||
table.addCell(innerTable);
|
||||
|
||||
table.setBorderBottom(new SolidBorder(0.5F));
|
||||
table.setMarginBottom(10.0F);
|
||||
doc.add(table);
|
||||
table.complete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractManager<Report> getManager() {
|
||||
return protocolManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEntries() {
|
||||
|
||||
}
|
||||
}
|
||||
+1216
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package converter;
|
||||
|
||||
import business.questions.QuestionaireManager;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.convert.Converter;
|
||||
import javax.faces.convert.FacesConverter;
|
||||
import model.question.Questionaire;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@FacesConverter(value = "questionnaireConverter", managed = true)
|
||||
public class QuestionnaireConverter implements Converter<Questionaire> {
|
||||
|
||||
@EJB
|
||||
private QuestionaireManager questionaireManager;
|
||||
|
||||
@Override
|
||||
public Questionaire getAsObject(FacesContext context, UIComponent component, String value) {
|
||||
if (value == null || value.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Long id = Long.valueOf(value);
|
||||
return questionaireManager.find(id);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString(FacesContext context, UIComponent component, Questionaire value) {
|
||||
if (value == null || value.getId() == null) {
|
||||
return "";
|
||||
}
|
||||
return value.getId().toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package converter;
|
||||
|
||||
import controller.machine.SecurityDeviceCompanyController;
|
||||
import javax.el.ValueExpression;
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.convert.Converter;
|
||||
import javax.faces.convert.FacesConverter;
|
||||
import model.security.SecurityDeviceCompany;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@FacesConverter(value = "seDeCoConverter")
|
||||
public class SeDeCoConverter implements Converter {
|
||||
@Override
|
||||
public Object getAsObject(FacesContext ctx, UIComponent uiComponent, String beerId) {
|
||||
ValueExpression vex =
|
||||
ctx.getApplication().getExpressionFactory()
|
||||
.createValueExpression(ctx.getELContext(),
|
||||
"#{securityDeviceCompanyController}", SecurityDeviceCompanyController.class);
|
||||
|
||||
SecurityDeviceCompanyController controller = (SecurityDeviceCompanyController)vex.getValue(ctx.getELContext());
|
||||
if (beerId == null) {
|
||||
return null;
|
||||
}
|
||||
return controller.getCompany(Long.valueOf(beerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object securityDeviceCompany) {
|
||||
if (securityDeviceCompany == null) {
|
||||
return "";
|
||||
}
|
||||
return ((SecurityDeviceCompany)securityDeviceCompany).getId().toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package converter;
|
||||
|
||||
import controller.machine.SecurityDeviceController;
|
||||
import model.security.SecurityDevice;
|
||||
import javax.el.ValueExpression;
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.convert.Converter;
|
||||
import javax.faces.convert.FacesConverter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@FacesConverter(value = "seDeConverter")
|
||||
public class SeDeConverter implements Converter {
|
||||
@Override
|
||||
public Object getAsObject(FacesContext ctx, UIComponent uiComponent, String beerId) {
|
||||
ValueExpression vex =
|
||||
ctx.getApplication().getExpressionFactory()
|
||||
.createValueExpression(ctx.getELContext(),
|
||||
"#{securityDeviceController}", SecurityDeviceController.class);
|
||||
|
||||
SecurityDeviceController controller = (SecurityDeviceController)vex.getValue(ctx.getELContext());
|
||||
if (beerId == null) {
|
||||
return null;
|
||||
}
|
||||
return controller.getDevice(Long.valueOf(beerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object securityDevice) {
|
||||
if (securityDevice == null) {
|
||||
return "";
|
||||
}
|
||||
return ((SecurityDevice)securityDevice).getId().toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package exception;
|
||||
|
||||
import javax.ejb.ApplicationException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@ApplicationException(rollback = true)
|
||||
public abstract class AbstractBusinessException extends RuntimeException {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
public class InvalidCredentialException extends AbstractBusinessException{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
public class InvalidEmailException extends AbstractBusinessException {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
public class InvalidPasswordException extends AbstractBusinessException {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
public class PersonInaktiveException extends AbstractBusinessException{
|
||||
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package httpauthenticationmechanism;
|
||||
|
||||
import business.ChangeToCLOBManager;
|
||||
import business.user.DemoManager;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.security.enterprise.credential.CallerOnlyCredential;
|
||||
import javax.security.enterprise.credential.Credential;
|
||||
import javax.security.enterprise.credential.UsernamePasswordCredential;
|
||||
import javax.security.enterprise.identitystore.CredentialValidationResult;
|
||||
import static javax.security.enterprise.identitystore.CredentialValidationResult.INVALID_RESULT;
|
||||
import static javax.security.enterprise.identitystore.CredentialValidationResult.NOT_VALIDATED_RESULT;
|
||||
import javax.security.enterprise.identitystore.IdentityStore;
|
||||
|
||||
import business.user.PersonManager;
|
||||
import exception.InvalidCredentialException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import model.person.Person;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class AppIdentityStore implements IdentityStore {
|
||||
|
||||
protected final Logger LOGGER = LogManager.getLogger(this.getClass());
|
||||
@EJB
|
||||
PersonManager userManager;
|
||||
|
||||
@EJB
|
||||
DemoManager demos;
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
void init() {
|
||||
if (userManager.count() < 1) {
|
||||
demos.runDemos();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CredentialValidationResult validate(Credential credential) {
|
||||
try {
|
||||
// check if the credential was UsernamePasswordCredential
|
||||
if (credential instanceof UsernamePasswordCredential) {
|
||||
String username = ((UsernamePasswordCredential) credential).getCaller();
|
||||
String password = ((UsernamePasswordCredential) credential).getPasswordAsString();
|
||||
|
||||
return validate(this.userManager.getByEmailAndPassword(username, password));
|
||||
}
|
||||
|
||||
// check if the credential was CallerOnlyCredential
|
||||
if (credential instanceof CallerOnlyCredential) {
|
||||
String username = ((CallerOnlyCredential) credential).getCaller();
|
||||
|
||||
return validate(
|
||||
this.userManager.getByEmail(username)
|
||||
.orElseThrow(InvalidCredentialException::new)
|
||||
);
|
||||
}
|
||||
|
||||
} catch (InvalidCredentialException e) {
|
||||
return INVALID_RESULT;
|
||||
}
|
||||
return NOT_VALIDATED_RESULT;
|
||||
}
|
||||
|
||||
private CredentialValidationResult validate(Person person) {
|
||||
Set<String> groups;
|
||||
|
||||
groups = person.getUserGroups().stream()
|
||||
.map(gr -> gr.toString())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
return new CredentialValidationResult(person.getEmail(), groups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCallerGroups(CredentialValidationResult validationResult) {
|
||||
Optional<Person> person = userManager.getByEmail(validationResult.getCallerPrincipal().getName());
|
||||
|
||||
if (person.isEmpty()) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
Set<String> stringGroups = person.get()
|
||||
.getUserGroups()
|
||||
.stream()
|
||||
.map(gr -> gr.toString())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
return stringGroups;
|
||||
}
|
||||
}
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package httpauthenticationmechanism;
|
||||
|
||||
import static javax.security.enterprise.identitystore.CredentialValidationResult.INVALID_RESULT;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.ejb.EJB;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.security.enterprise.CallerPrincipal;
|
||||
import javax.security.enterprise.credential.RememberMeCredential;
|
||||
import javax.security.enterprise.identitystore.CredentialValidationResult;
|
||||
import javax.security.enterprise.identitystore.RememberMeIdentityStore;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import business.user.TokenManager;
|
||||
import business.user.PersonManager;
|
||||
import model.person.Person;
|
||||
import static model.person.enums.TokenType.REMEMBER_ME;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class AppRememberMeIdentityStore implements RememberMeIdentityStore {
|
||||
@Inject
|
||||
HttpServletRequest request;
|
||||
|
||||
@EJB
|
||||
PersonManager userManager;
|
||||
|
||||
@EJB
|
||||
TokenManager tokenManager;
|
||||
|
||||
@Override
|
||||
public CredentialValidationResult validate(RememberMeCredential rmc) {
|
||||
Optional<Person> user = this.userManager.getByLoginToken(rmc.getToken(), REMEMBER_ME);
|
||||
|
||||
if (user.isPresent()) {
|
||||
return new CredentialValidationResult(user.get().getEmail());
|
||||
} else {
|
||||
return INVALID_RESULT;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateLoginToken(CallerPrincipal cp, Set<String> set) {
|
||||
return this.tokenManager.generate(cp.getName(), getRemoteAddr(request), getDescription(), REMEMBER_ME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLoginToken(String string) {
|
||||
this.tokenManager.remove(string);
|
||||
}
|
||||
|
||||
private String getRemoteAddr(HttpServletRequest request){
|
||||
return request.getRemoteAddr();
|
||||
}
|
||||
|
||||
private String getDescription() {
|
||||
return "Remember me session: " + this.request.getHeader("User-Agent");
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package httpauthenticationmechanism;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class ApplicationConfig {
|
||||
|
||||
final static Logger LOGGER = LogManager.getLogger(ApplicationConfig.class);
|
||||
|
||||
public ApplicationConfig() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
package httpauthenticationmechanism;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.security.enterprise.AuthenticationStatus;
|
||||
import javax.security.enterprise.authentication.mechanism.http.AutoApplySession;
|
||||
import javax.security.enterprise.authentication.mechanism.http.HttpAuthenticationMechanism;
|
||||
import javax.security.enterprise.authentication.mechanism.http.HttpMessageContext;
|
||||
import javax.security.enterprise.authentication.mechanism.http.LoginToContinue;
|
||||
import javax.security.enterprise.authentication.mechanism.http.RememberMe;
|
||||
import javax.security.enterprise.credential.Credential;
|
||||
import javax.security.enterprise.identitystore.IdentityStore;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@AutoApplySession // For "Is user already logged-in?"
|
||||
@RememberMe(
|
||||
cookieMaxAgeSeconds = 60 * 60 * 24 * 14, // 14 days
|
||||
cookieSecureOnly = false, // Remove this when login is served over HTTPS.
|
||||
isRememberMeExpression = "#{self.isRememberMe(httpMessageContext)}"
|
||||
)
|
||||
@LoginToContinue(
|
||||
loginPage = "/index.xhtml",
|
||||
errorPage = "/error.xhtml",
|
||||
useForwardToLogin = true)
|
||||
@ApplicationScoped
|
||||
public class CustomAuthenticationMechanism implements HttpAuthenticationMechanism {
|
||||
|
||||
final static Logger LOGGER = LogManager.getLogger(CustomAuthenticationMechanism.class);
|
||||
|
||||
public CustomAuthenticationMechanism() {
|
||||
}
|
||||
|
||||
@Inject
|
||||
private IdentityStore identityStore;
|
||||
|
||||
@Override
|
||||
public AuthenticationStatus validateRequest(HttpServletRequest req, HttpServletResponse res, HttpMessageContext context) {
|
||||
Credential credential = context.getAuthParameters().getCredential();
|
||||
if (credential != null) {
|
||||
return context.notifyContainerAboutLogin(this.identityStore.validate(credential));
|
||||
} else {
|
||||
return context.doNothing();
|
||||
}
|
||||
}
|
||||
|
||||
// this was called on @RememberMe annotations
|
||||
public Boolean isRememberMe(HttpMessageContext httpMessageContext) {
|
||||
return httpMessageContext.getAuthParameters().isRememberMe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanSubject(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) {
|
||||
HttpAuthenticationMechanism.super.cleanSubject(request, response, httpMessageContext);
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package httpauthenticationmechanism;
|
||||
|
||||
import javax.servlet.annotation.WebListener;
|
||||
import javax.servlet.http.HttpSessionEvent;
|
||||
import javax.servlet.http.HttpSessionListener;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import controller.person.PersonController;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@WebListener
|
||||
public class LogoutListener implements HttpSessionListener{
|
||||
final static Logger LOGGER = LogManager.getLogger(LogoutListener.class);
|
||||
|
||||
@Override
|
||||
public void sessionCreated(HttpSessionEvent event) {
|
||||
// NOOP.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionDestroyed(HttpSessionEvent event) {
|
||||
LOGGER.info("Session destroyed");
|
||||
PersonController userManager = (PersonController) event.getSession().getAttribute("user");
|
||||
String username = (String) event.getSession().getAttribute("realUsername");
|
||||
if (userManager != null && username != null) {
|
||||
LOGGER.info("not nulls");
|
||||
userManager.getLogins().remove(username);
|
||||
}
|
||||
}
|
||||
|
||||
private static HttpServletResponse getResponse(FacesContext context) {
|
||||
return (HttpServletResponse) context.getExternalContext().getResponse();
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package httpauthenticationmechanism;
|
||||
|
||||
import controller.person.PersonController;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import static java.util.UUID.randomUUID;
|
||||
import javax.inject.Named;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@Named(value = "managedPerson")
|
||||
@ApplicationScoped
|
||||
public class ManagedPerson {
|
||||
|
||||
private Set<String> logins;
|
||||
private Map<String, PersonController> loggedInController;
|
||||
|
||||
/**
|
||||
* Creates a new instance of ManagedCustomer
|
||||
*/
|
||||
public ManagedPerson() {
|
||||
}
|
||||
|
||||
public Set<String> getLogins(){
|
||||
if (this.logins == null) {
|
||||
this.logins = new HashSet<>();
|
||||
}
|
||||
|
||||
return this.logins;
|
||||
}
|
||||
|
||||
public Map<String, PersonController> getControllers() {
|
||||
if (loggedInController == null) {
|
||||
this.loggedInController = new HashMap<>();
|
||||
}
|
||||
|
||||
return loggedInController;
|
||||
}
|
||||
|
||||
public boolean isLoggedIn(String user) {
|
||||
return logins == null || logins.contains(user);
|
||||
}
|
||||
|
||||
public void addLogin(String user){
|
||||
getLogins().add(user);
|
||||
}
|
||||
|
||||
public void removeLogin(String user){
|
||||
getLogins().remove(user);
|
||||
}
|
||||
|
||||
public String addController(PersonController ctlr){
|
||||
String id = randomUUID().toString();
|
||||
while(getControllers().containsKey(id)){
|
||||
id = randomUUID().toString();
|
||||
}
|
||||
|
||||
getControllers().put(id, ctlr);
|
||||
return id;
|
||||
}
|
||||
|
||||
public void removeController(String id){
|
||||
getControllers().remove(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package model;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick Plate
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class AbstractEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private LocalDateTime changedDate;
|
||||
|
||||
private LocalDateTime creationDate;
|
||||
|
||||
private boolean outdated;
|
||||
|
||||
public AbstractEntity() {
|
||||
this.creationDate = LocalDateTime.now();
|
||||
this.changedDate = this.creationDate;
|
||||
this.outdated = false;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (id != null ? id.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(object.getClass() == this.getClass())) {
|
||||
return false;
|
||||
}
|
||||
AbstractEntity other = (AbstractEntity) object;
|
||||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isOutdated() {
|
||||
return outdated;
|
||||
}
|
||||
|
||||
public void setOutdated(boolean outdated) {
|
||||
this.outdated = outdated;
|
||||
}
|
||||
|
||||
public LocalDateTime getChangedDate() {
|
||||
return changedDate;
|
||||
}
|
||||
|
||||
public void setChangedDate(LocalDateTime changedDate) {
|
||||
this.changedDate = changedDate;
|
||||
}
|
||||
|
||||
public void setCreationDate (LocalDateTime creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
}
|
||||
+233
@@ -0,0 +1,233 @@
|
||||
package model.adresses;
|
||||
|
||||
import java.util.Objects;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.PostLoad;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import model.AbstractEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class Address extends AbstractEntity{
|
||||
|
||||
//Land
|
||||
@NotNull(message = "Land darf nicht null sein")
|
||||
private String country;
|
||||
|
||||
//Straßenname
|
||||
@NotNull(message = "Strasse darf nicht null sein")
|
||||
private String street;
|
||||
|
||||
//Hausnummer
|
||||
@NotNull(message = "Hausnummer darf nicht null sein")
|
||||
private String number;
|
||||
|
||||
//Zusatz
|
||||
private String extra;
|
||||
|
||||
//PLZ
|
||||
@NotNull(message = "PLZ darf nicht null sein")
|
||||
private Integer postnumber;
|
||||
|
||||
//Bundesland
|
||||
@NotNull(message = "Bundesland darf nicht null sein")
|
||||
private String county;
|
||||
|
||||
//Ort
|
||||
@NotNull(message = "Ort darf nicht null sein")
|
||||
private String place;
|
||||
|
||||
private String contact;
|
||||
|
||||
private String comment;
|
||||
|
||||
@Lob
|
||||
@Column(columnDefinition = "CLOB")
|
||||
private String comment2;
|
||||
|
||||
public Address() {
|
||||
}
|
||||
|
||||
public Address(String street, String number, String extra, Integer postnumber, String county, String place) {
|
||||
this.street = street;
|
||||
this.number = number;
|
||||
this.extra = extra;
|
||||
this.postnumber = postnumber;
|
||||
this.county = county;
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
public Address(String country, String street, String number, String extra, Integer postnumber, String county, String place) {
|
||||
this.country = country;
|
||||
this.street = street;
|
||||
this.number = number;
|
||||
this.extra = extra;
|
||||
this.postnumber = postnumber;
|
||||
this.county = county;
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
public Address(String country, String street, String number, String extra, Integer postnumber, String county, String place, String contact, String comment) {
|
||||
this.country = country;
|
||||
this.street = street;
|
||||
this.number = number;
|
||||
this.extra = extra;
|
||||
this.postnumber = postnumber;
|
||||
this.county = county;
|
||||
this.place = place;
|
||||
this.contact = contact;
|
||||
this.comment2 = comment;
|
||||
}
|
||||
|
||||
public Address(Address toCopyAddress){
|
||||
this.country = toCopyAddress.getCountry();
|
||||
this.street = toCopyAddress.getStreet();
|
||||
this.number = toCopyAddress.getNumber();
|
||||
this.extra = toCopyAddress.getExtra();
|
||||
this.postnumber = toCopyAddress.getPostnumber();
|
||||
this.county = toCopyAddress.getCounty();
|
||||
this.place = toCopyAddress.getPlace();
|
||||
this.contact = toCopyAddress.getContact();
|
||||
this.comment2 = toCopyAddress.getComment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 83 * hash + Objects.hashCode(this.country);
|
||||
hash = 83 * hash + Objects.hashCode(this.street);
|
||||
hash = 83 * hash + Objects.hashCode(this.number);
|
||||
hash = 83 * hash + Objects.hashCode(this.extra);
|
||||
hash = 83 * hash + Objects.hashCode(this.postnumber);
|
||||
hash = 83 * hash + Objects.hashCode(this.county);
|
||||
hash = 83 * hash + Objects.hashCode(this.place);
|
||||
hash = 83 * hash + Objects.hashCode(this.contact);
|
||||
hash = 83 * hash + Objects.hashCode(this.comment);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final Address other = (Address) obj;
|
||||
if (!Objects.equals(this.country, other.country)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.street, other.street)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.number, other.number)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.extra, other.extra)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.county, other.county)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.place, other.place)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.comment, other.comment)) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(this.postnumber, other.postnumber);
|
||||
}
|
||||
|
||||
@PostLoad
|
||||
private void switchToClobComment(){
|
||||
if (comment != null && comment2 == null) {
|
||||
comment2 = comment;
|
||||
}
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(String number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getExtra() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
public void setExtra(String extra) {
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
public Integer getPostnumber() {
|
||||
return postnumber;
|
||||
}
|
||||
|
||||
public void setPostnumber(Integer postnumber) {
|
||||
this.postnumber = postnumber;
|
||||
}
|
||||
|
||||
public String getCounty() {
|
||||
return county;
|
||||
}
|
||||
|
||||
public void setCounty(String county) {
|
||||
this.county = county;
|
||||
}
|
||||
|
||||
public String getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
public void setPlace(String place) {
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
public void setContact(String contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment2;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
if (comment != null && comment.length() > 256) {
|
||||
comment2 = comment;
|
||||
} else {
|
||||
this.comment2 = comment;
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package model.adresses;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToOne;
|
||||
import model.company.Company;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@Entity
|
||||
public class CompanyAddress extends Address{
|
||||
@ManyToOne
|
||||
private Company company;
|
||||
|
||||
public CompanyAddress() {
|
||||
}
|
||||
|
||||
public CompanyAddress(Company company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public CompanyAddress(Company company, String country, String street, String number, String extra, Integer postnumber, String county, String place, String contact, String comment) {
|
||||
super(country, street, number, extra, postnumber, county, place, contact, comment);
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public Company getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(Company company) {
|
||||
this.company = company;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package model.adresses;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToOne;
|
||||
import model.company.Company;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Patrick
|
||||
*/
|
||||
@Entity
|
||||
public class CompanyBillingAddress extends Address{
|
||||
@ManyToOne
|
||||
private Company company;
|
||||
|
||||
private boolean delivery;
|
||||
|
||||
public CompanyBillingAddress() {
|
||||
}
|
||||
|
||||
public CompanyBillingAddress(Company company, boolean delivery) {
|
||||
this.company = company;
|
||||
this.delivery = delivery;
|
||||
}
|
||||
|
||||
public CompanyBillingAddress(Company company, boolean delivery,String country, String street, String number, String extra, Integer postnumber, String county, String place) {
|
||||
super(country, street, number, extra, postnumber, county, place);
|
||||
this.company = company;
|
||||
this.delivery = delivery;
|
||||
}
|
||||
|
||||
public Company getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(Company company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public boolean isDelivery() {
|
||||
return delivery;
|
||||
}
|
||||
|
||||
public void setDelivery(boolean delivery) {
|
||||
this.delivery = delivery;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package model.adresses;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToOne;
|
||||
import model.company.Location;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Entity
|
||||
public class LocationAddress extends Address {
|
||||
|
||||
@OneToOne
|
||||
private Location location;
|
||||
|
||||
public LocationAddress() {
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package model.company;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.Size;
|
||||
import model.AbstractEntity;
|
||||
import model.adresses.CompanyAddress;
|
||||
import model.customer.Customer;
|
||||
import model.ticket.Ticket;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Entity
|
||||
@NamedQueries(
|
||||
@NamedQuery(name = Company.FIND_BY_NAME, query = "SELECT c FROM Company c WHERE c.name = :name")
|
||||
)
|
||||
public class Company extends AbstractEntity {
|
||||
|
||||
public static final String FIND_BY_NAME = "Company.findByName";
|
||||
public static final String FIND_BY_STEUERID = "Company.findBySteuerID";
|
||||
public static final String FIND_BY_UMSATZSTEUERID = "Company.findByUmsatzsteuerID";
|
||||
public static final String FIND_BY_CUSTOMER = "Company.findByCustomer";
|
||||
public static final String FIND_BY_ADDRESS = "Company.findByAddress";
|
||||
public static final String FIND_BY_DELIVERYADDRESS = "Company.findByLocation";
|
||||
|
||||
@Column(unique = true, nullable = false)
|
||||
private String name;
|
||||
|
||||
@Column(unique = true, nullable = true)
|
||||
@Size(min = 0, max = 255)
|
||||
private String steuerNr;
|
||||
|
||||
@Column(unique = true, nullable = true)
|
||||
@Size(min = 0, max = 255)
|
||||
private String umsatzSteuerID;
|
||||
|
||||
@Column(unique = true, nullable = true)
|
||||
private String kundenNr;
|
||||
|
||||
@Column(unique = false, nullable = true)
|
||||
private String headerInspection;
|
||||
|
||||
@Column(unique = false, nullable = true)
|
||||
private String headerService;
|
||||
|
||||
@Column(unique = false, nullable = false)
|
||||
@Enumerated(EnumType.ORDINAL)
|
||||
private Status status;
|
||||
|
||||
@Column(unique = false, nullable = true, length = 210)
|
||||
private String comment;
|
||||
|
||||
@OneToMany(mappedBy = "company", cascade = {CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
|
||||
private Set<CompanyAddress> addresses;
|
||||
|
||||
@OneToMany(mappedBy = "company", cascade = {CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
|
||||
@OrderBy("name ASC")
|
||||
private Set<Location> locations;
|
||||
|
||||
@OneToMany(mappedBy = "company", cascade = {
|
||||
CascadeType.PERSIST,
|
||||
CascadeType.MERGE,
|
||||
CascadeType.REFRESH,
|
||||
})
|
||||
private Set<Customer> customers;
|
||||
|
||||
@OneToMany(mappedBy = "company")
|
||||
private List<Ticket> tickets;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
private CompanyLogo companyLogo;
|
||||
|
||||
public Company() {
|
||||
}
|
||||
|
||||
public CompanyLogo getCompanyLogo() {
|
||||
return companyLogo;
|
||||
}
|
||||
|
||||
public void setCompanyLogo(CompanyLogo companyLogo) {
|
||||
this.companyLogo = companyLogo;
|
||||
}
|
||||
|
||||
public void addCustomer(Customer customer){
|
||||
if (customers == null) {
|
||||
customers = new HashSet<>();
|
||||
}
|
||||
|
||||
if (customer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
customers.add(customer);
|
||||
}
|
||||
|
||||
public void addLocation(Location location){
|
||||
if (locations == null) {
|
||||
locations = new HashSet<>();
|
||||
}
|
||||
|
||||
if (location == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
locations.add(location);
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSteuerNr() {
|
||||
return steuerNr;
|
||||
}
|
||||
|
||||
public void setSteuerNr(String steuerNr) {
|
||||
this.steuerNr = steuerNr;
|
||||
}
|
||||
|
||||
public String getUmsatzSteuerID() {
|
||||
return umsatzSteuerID;
|
||||
}
|
||||
|
||||
public void setUmsatzSteuerID(String umsatzSteuerID) {
|
||||
this.umsatzSteuerID = umsatzSteuerID;
|
||||
}
|
||||
|
||||
public String getKundenNr() {
|
||||
return kundenNr;
|
||||
}
|
||||
|
||||
public void setKundenNr(String kundenNr) {
|
||||
this.kundenNr = kundenNr;
|
||||
}
|
||||
|
||||
public String getHeaderInspection() {
|
||||
return headerInspection;
|
||||
}
|
||||
|
||||
public void setHeaderInspection(String headerInspection) {
|
||||
this.headerInspection = headerInspection;
|
||||
}
|
||||
|
||||
public String getHeaderService() {
|
||||
return headerService;
|
||||
}
|
||||
|
||||
public void setHeaderService(String headerService) {
|
||||
this.headerService = headerService;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Set<CompanyAddress> getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public void setAddresses(Set<CompanyAddress> addresses) {
|
||||
this.addresses = addresses;
|
||||
}
|
||||
|
||||
public Set<Location> getLocations() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
public void setLocations(Set<Location> locations) {
|
||||
this.locations = locations;
|
||||
}
|
||||
|
||||
public Set<Customer> getCustomers() {
|
||||
return customers;
|
||||
}
|
||||
|
||||
public void setCustomers(Set<Customer> customers) {
|
||||
this.customers = customers;
|
||||
}
|
||||
|
||||
public List<Ticket> getTickets() {
|
||||
return tickets;
|
||||
}
|
||||
|
||||
public void setTickets(List<Ticket> tickets) {
|
||||
this.tickets = tickets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package model.company;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToOne;
|
||||
import model.files.FileDB;
|
||||
import model.files.Mime;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pplate
|
||||
*/
|
||||
@Entity
|
||||
public class CompanyLogo extends FileDB {
|
||||
private static final List<Mime> ALLOWED_FILE_TYPES = Arrays.asList(Mime.JPEG, Mime.JPG, Mime.PNG, Mime.BMP, Mime.PNG);
|
||||
private static final long SIZE_LIMIT = 2000000L;
|
||||
|
||||
@OneToOne
|
||||
private Company company;
|
||||
|
||||
public CompanyLogo() {
|
||||
}
|
||||
|
||||
public static String getAllowedTypesRE(){
|
||||
StringBuilder output = new StringBuilder(ALLOWED_FILE_TYPES.size() * 4);
|
||||
|
||||
output.append("/(\\.|\\/)(");
|
||||
|
||||
for(int i = 0; i < ALLOWED_FILE_TYPES.size(); i++){
|
||||
output.append(ALLOWED_FILE_TYPES.get(i).getExtension());
|
||||
if (i < ALLOWED_FILE_TYPES.size() -1) {
|
||||
output.append('|');
|
||||
}
|
||||
}
|
||||
|
||||
output.append(")$/");
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
public static List<Mime> getALLOWED_FILE_TYPES() {
|
||||
return ALLOWED_FILE_TYPES;
|
||||
}
|
||||
|
||||
public static long getSIZE_LIMIT() {
|
||||
return SIZE_LIMIT;
|
||||
}
|
||||
|
||||
public Company getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(Company company) {
|
||||
this.company = company;
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package model.company;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.persistence.*;
|
||||
|
||||
import model.AbstractEntity;
|
||||
import model.machine.Machine;
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Entity
|
||||
public class Location extends AbstractEntity{
|
||||
|
||||
@ManyToOne
|
||||
private Company company;
|
||||
|
||||
private String name;
|
||||
|
||||
private String kostenstelle;
|
||||
|
||||
private String comment;
|
||||
|
||||
@Lob
|
||||
@Column(columnDefinition = "CLOB")
|
||||
private String comment2;
|
||||
|
||||
@OneToMany(mappedBy = "location", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||
@OrderBy("name ASC")
|
||||
private List<Machine> machines;
|
||||
|
||||
public Location() {
|
||||
}
|
||||
|
||||
public Location(Company company, String name, String kostenstelle, List<Machine> machines, String comment) {
|
||||
this.company = company;
|
||||
this.name = name;
|
||||
this.kostenstelle = kostenstelle;
|
||||
this.machines = machines;
|
||||
this.comment2 = comment;
|
||||
}
|
||||
|
||||
public Location(Location location) {
|
||||
this.company = location.getCompany();
|
||||
this.name = location.getName();
|
||||
this.kostenstelle = location.getKostenstelle();
|
||||
this.machines = location.getMachines();
|
||||
this.comment2 = location.getComment();
|
||||
}
|
||||
|
||||
@PostLoad
|
||||
private void switchToClobComment(){
|
||||
if (comment != null && comment2 == null) {
|
||||
comment2 = comment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment2;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
if (comment != null && comment.length() > 256) {
|
||||
comment2 = comment;
|
||||
} else {
|
||||
this.comment2 = comment;
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
|
||||
public Company getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(Company company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public List<Machine> getMachines() {
|
||||
return machines;
|
||||
}
|
||||
|
||||
public void setMachines(List<Machine> machines) {
|
||||
this.machines = machines;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getKostenstelle() {
|
||||
return kostenstelle;
|
||||
}
|
||||
|
||||
public void setKostenstelle(String kostenstelle) {
|
||||
this.kostenstelle = kostenstelle;
|
||||
}
|
||||
|
||||
public void addMachine(Machine mac) {
|
||||
if (this.machines == null) {
|
||||
this.machines = new ArrayList<>();
|
||||
}
|
||||
|
||||
machines.add(mac);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package model.company;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
public enum Status {
|
||||
ACTIVE,
|
||||
INACTIVE;
|
||||
|
||||
private Status() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch(this){
|
||||
case ACTIVE:
|
||||
return "aktiv";
|
||||
case INACTIVE:
|
||||
return "inaktiv";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String toLanguageString(Locale locale){
|
||||
if (locale == null ||locale.equals(Locale.GERMAN) || locale.equals(Locale.GERMANY)) {
|
||||
return getGerman();
|
||||
}
|
||||
|
||||
if (locale.equals(Locale.ENGLISH)) {
|
||||
getEnglish();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getGerman() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
private String getEnglish(){
|
||||
switch(this){
|
||||
case ACTIVE:
|
||||
return "active";
|
||||
case INACTIVE:
|
||||
return "inactive";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package model.customer;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import model.person.Person;
|
||||
import model.company.Company;
|
||||
import model.person.Salt;
|
||||
import model.person.enums.UserGroup;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@Entity
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = Customer.GET_BY_EMAIL, query = "SELECT c FROM Customer c WHERE c.email = :email")
|
||||
})
|
||||
public class Customer extends Person{
|
||||
|
||||
public static final String GET_BY_EMAIL = "Customer.getByEmail";
|
||||
|
||||
@ManyToOne
|
||||
private Company company;
|
||||
|
||||
@Column(nullable = true, length = 210)
|
||||
private String note;
|
||||
|
||||
private String devision;
|
||||
|
||||
public Customer() {
|
||||
addGroup(UserGroup.CUSTOMER);
|
||||
}
|
||||
|
||||
public Customer(String email, byte[] password, Salt salt, Set<UserGroup> usergroups) {
|
||||
super(email, password, salt, usergroups);
|
||||
}
|
||||
|
||||
public String getDevision() {
|
||||
return devision;
|
||||
}
|
||||
|
||||
public void setDevision(String devision) {
|
||||
this.devision = devision;
|
||||
}
|
||||
|
||||
public Customer(Company company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public Company getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(Company company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public void setNote(String note) {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws CloneNotSupportedException
|
||||
*/
|
||||
@Override
|
||||
public Customer clone() throws CloneNotSupportedException {
|
||||
Customer clone = new Customer();
|
||||
|
||||
clone.setActive(this.isActive());
|
||||
clone.setCall(this.getCall());
|
||||
clone.setDevision(this.getDevision());
|
||||
clone.setChangedDate(this.getChangedDate());
|
||||
clone.setCompany(this.getCompany());
|
||||
clone.setCreationDate(this.getCreationDate());
|
||||
clone.setEmail(this.getEmail());
|
||||
clone.setFax(this.getFax());
|
||||
clone.setFirstname(this.getFirstname());
|
||||
clone.setId(this.getId());
|
||||
clone.setLastname(this.getLastname());
|
||||
clone.setMobile(this.getMobile());
|
||||
clone.setNote(this.getNote());
|
||||
clone.setOutdated(false);
|
||||
clone.setPassword(this.getPassword());
|
||||
clone.setSalt(this.getSalt());
|
||||
clone.setTelefon(this.getTelefon());
|
||||
clone.setTitle(this.getTitle());
|
||||
clone.setTokens(this.getTokens());
|
||||
clone.setUserGroups(this.getUserGroups());
|
||||
clone.setUserPicture(this.getUserPicture());
|
||||
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package model.files;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import model.AbstractEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author patri
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class FileDB extends AbstractEntity{
|
||||
@Column(nullable = false, length = 100)
|
||||
private String name;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Mime mime;
|
||||
|
||||
@Lob
|
||||
private byte[] fileData;
|
||||
|
||||
public FileDB() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public byte[] getFileData() {
|
||||
return fileData;
|
||||
}
|
||||
|
||||
public void setFileData(byte[] fileData) {
|
||||
this.fileData = fileData;
|
||||
}
|
||||
|
||||
public Mime getMime() {
|
||||
return mime;
|
||||
}
|
||||
|
||||
public void setMime(Mime mime) {
|
||||
this.mime = mime;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user