Skip to content

Commit

Permalink
WIP. issue #1955
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Dec 15, 2023
1 parent 6ade6a8 commit c2cd324
Show file tree
Hide file tree
Showing 10 changed files with 2,225 additions and 24 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,19 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="splitMain" min="-2" pref="720" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblInvoiceTotal" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel10" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblInvoiceTax" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel11" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblNetValue" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel12" alignment="3" min="-2" max="-2" attributes="0"/>
<Group type="103" alignment="3" groupAlignment="3" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" alignment="0" groupAlignment="3" attributes="0">
<Component id="cmdCancel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cmdSave" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblInvoiceTotal" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel10" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblInvoiceTax" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel11" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblNetValue" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel12" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
</Group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1593,16 +1593,17 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addContainerGap()
.addComponent(splitMain, javax.swing.GroupLayout.PREFERRED_SIZE, 720, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblInvoiceTotal)
.addComponent(jLabel10)
.addComponent(lblInvoiceTax)
.addComponent(jLabel11)
.addComponent(lblNetValue)
.addComponent(jLabel12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmdCancel)
.addComponent(cmdSave)))
.addComponent(cmdSave))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblInvoiceTotal)
.addComponent(jLabel10)
.addComponent(lblInvoiceTax)
.addComponent(jLabel11)
.addComponent(lblNetValue)
.addComponent(jLabel12)))
.addGap(6, 6, 6))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,4 +915,12 @@ public interface ArchiveFileServiceRemote {
ArrayList<String> getAllArchiveFileNumbers() throws Exception;

List<String> getCaseIdsSyncedForUser(String principalId) throws Exception;

List<CaseAccountEntry> getAccountEntries(String caseId) throws Exception;

CaseAccountEntry addAccountEntry(String caseId, CaseAccountEntry accountEntry) throws Exception;

CaseAccountEntry updateAccountEntry(String caseId, CaseAccountEntry accountEntry) throws Exception;

void removeAccountEntry(String entryId) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ You should also get your employer (if you work as a programmer) or school,
*/
package com.jdimension.jlawyer.persistence;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
Expand All @@ -685,5 +686,10 @@ protected EntityManager getEntityManager() {
public CaseAccountEntryFacade() {
super(CaseAccountEntry.class);
}

@Override
public List<CaseAccountEntry> findByArchiveFileKey(ArchiveFileBean archiveFileKey) {
return (List<CaseAccountEntry>) em.createNamedQuery("CaseAccountEntry.findByArchiveFileKey").setParameter("archiveFileKey", archiveFileKey).getResultList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -687,4 +687,6 @@ public interface CaseAccountEntryFacadeLocal {

int count();

List<CaseAccountEntry> findByArchiveFileKey(ArchiveFileBean archiveFileKey);

}
Original file line number Diff line number Diff line change
Expand Up @@ -712,15 +712,10 @@
import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.jms.ConnectionFactory;
import javax.jms.JMSConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.naming.InitialContext;
import org.apache.log4j.Logger;
import org.jboss.ejb3.annotation.SecurityDomain;
import org.jlawyer.data.tree.GenericNode;
import org.jlawyer.data.tree.TreeNodeUtils;
import org.jlawyer.databucket.DataBucketUtils;
Expand Down Expand Up @@ -793,11 +788,12 @@ public class ArchiveFileService implements ArchiveFileServiceRemote, ArchiveFile
private InvoiceTypeFacadeLocal invoicesTypesFacade;
@EJB
private InvoiceServiceLocal invoiceService;

@EJB
private TimesheetFacadeLocal timesheetFacade;
@EJB
private TimesheetPositionFacadeLocal timesheetPositionsFacade;
@EJB
private CaseAccountEntryFacadeLocal accountEntries;


// custom hooks support
Expand Down Expand Up @@ -6024,4 +6020,147 @@ public void updateDocumentExternalId(String id, String externalId) throws Except

}

@Override
@RolesAllowed({"readArchiveFileRole"})
public List<CaseAccountEntry> getAccountEntries(String caseId) throws Exception {
String principalId = context.getCallerPrincipal().getName();

ArchiveFileBean aFile = this.archiveFileFacade.find(caseId);
boolean allowed = false;
if (principalId != null) {
List<Group> userGroups = new ArrayList<>();
try {
userGroups = this.securityFacade.getGroupsForUser(principalId);
} catch (Throwable t) {
log.error("Unable to determine groups for user " + principalId, t);
}
if (SecurityUtils.checkGroupsForCase(userGroups, aFile, this.caseGroupsFacade)) {
allowed = true;
}
} else {
allowed = true;
}

if (allowed) {
return this.accountEntries.findByArchiveFileKey(aFile);
} else {
return new ArrayList<>();
}
}

@Override
@RolesAllowed({"writeArchiveFileRole"})
public CaseAccountEntry addAccountEntry(String caseId, CaseAccountEntry accountEntry) throws Exception {
String principalId = context.getCallerPrincipal().getName();

ArchiveFileBean aFile = this.archiveFileFacade.find(caseId);
boolean allowed = false;
if (principalId != null) {
List<Group> userGroups = new ArrayList<>();
try {
userGroups = this.securityFacade.getGroupsForUser(principalId);
} catch (Throwable t) {
log.error("Unable to determine groups for user " + principalId, t);
}
if (SecurityUtils.checkGroupsForCase(userGroups, aFile, this.caseGroupsFacade)) {
allowed = true;
}
} else {
allowed = true;
}

if (allowed) {

StringGenerator idGen = new StringGenerator();
accountEntry.setId(idGen.getID().toString());
accountEntry.setArchiveFileKey(aFile);

this.accountEntries.create(accountEntry);

this.addCaseHistory(new StringGenerator().getID().toString(), aFile, "Buchung Aktenkonto hinzugefügt (" + accountEntry.getDescription() + ")");

return this.accountEntries.find(accountEntry.getId());
} else {
throw new Exception(MSG_MISSINGPRIVILEGE_CASE);
}
}

@Override
@RolesAllowed({"writeArchiveFileRole"})
public CaseAccountEntry updateAccountEntry(String caseId, CaseAccountEntry accountEntry) throws Exception {
String principalId = context.getCallerPrincipal().getName();

ArchiveFileBean aFile = this.archiveFileFacade.find(caseId);
boolean allowed = false;
if (principalId != null) {
List<Group> userGroups = new ArrayList<>();
try {
userGroups = this.securityFacade.getGroupsForUser(principalId);
} catch (Throwable t) {
log.error("Unable to determine groups for user " + principalId, t);
}
if (SecurityUtils.checkGroupsForCase(userGroups, aFile, this.caseGroupsFacade)) {
allowed = true;
}
} else {
allowed = true;
}

if (allowed) {

CaseAccountEntry updatedEntry = this.accountEntries.find(accountEntry.getId());
updatedEntry.setContact(accountEntry.getContact());
updatedEntry.setDescription(accountEntry.getDescription());
updatedEntry.setEarnings(accountEntry.getEarnings());
updatedEntry.setEscrowIn(accountEntry.getEscrowIn());
updatedEntry.setEscrowOut(accountEntry.getEscrowOut());
updatedEntry.setExpendituresIn(accountEntry.getExpendituresIn());
updatedEntry.setExpendituresOut(accountEntry.getExpendituresOut());
updatedEntry.setInvoice(accountEntry.getInvoice());
updatedEntry.setSpendings(accountEntry.getSpendings());

this.accountEntries.edit(updatedEntry);

this.addCaseHistory(new StringGenerator().getID().toString(), aFile, "Buchung Aktenkonto geändert (" + updatedEntry.getDescription() + ")");

return this.accountEntries.find(updatedEntry.getId());
} else {
throw new Exception(MSG_MISSINGPRIVILEGE_CASE);
}
}

@Override
@RolesAllowed({"writeArchiveFileRole"})
public void removeAccountEntry(String entryId) throws Exception {
String principalId = context.getCallerPrincipal().getName();

CaseAccountEntry entry = this.accountEntries.find(entryId);
if (entry == null) {
throw new Exception("Eintrag im Aktenkonto kann nicht gefunden werden");
}

ArchiveFileBean aFile = this.archiveFileFacade.find(entry.getArchiveFileKey().getId());
boolean allowed = false;
if (principalId != null) {
List<Group> userGroups = new ArrayList<>();
try {
userGroups = this.securityFacade.getGroupsForUser(principalId);
} catch (Throwable t) {
log.error("Unable to determine groups for user " + principalId, t);
}
if (SecurityUtils.checkGroupsForCase(userGroups, aFile, this.caseGroupsFacade)) {
allowed = true;
}
} else {
allowed = true;
}

if (allowed) {
this.accountEntries.remove(entry);
this.addCaseHistory(new StringGenerator().getID().toString(), aFile, "Buchung Aktenkonto gelöscht (" + entry.getDescription() + ")");
} else {
throw new Exception(MSG_MISSINGPRIVILEGE_CASE);
}
}

}

0 comments on commit c2cd324

Please sign in to comment.