Skip to content

Commit

Permalink
Google Java format
Browse files Browse the repository at this point in the history
  • Loading branch information
slominskir committed Sep 30, 2024
1 parent fe5f9da commit e7357c2
Show file tree
Hide file tree
Showing 42 changed files with 2,278 additions and 2,280 deletions.
5 changes: 2 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
* text=auto
*.sh text eol=lf
*.env text eol=lf
* text eol=lf
*.png binary
*.bat text eol=crlf
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'war'
id "com.diffplug.spotless" version "6.25.0"
}
description = 'CEBAF Nomenclature Manager app'
group 'org.jlab'
Expand Down Expand Up @@ -40,3 +41,9 @@ war {
}
}
}

spotless {
java {
googleJavaFormat()
}
}
146 changes: 72 additions & 74 deletions src/main/java/org/jlab/cnm/business/session/AbstractFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,97 +15,95 @@
import javax.persistence.criteria.Root;

/**
*
* @author ryans
*/
public abstract class AbstractFacade<T> {
@Resource
private SessionContext context;

private final Class<T> entityClass;
@Resource private SessionContext context;

public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}
private final Class<T> entityClass;

protected abstract EntityManager getEntityManager();
public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}

protected void create(T entity) {
getEntityManager().persist(entity);
}
protected abstract EntityManager getEntityManager();

protected void edit(T entity) {
getEntityManager().merge(entity);
}
protected void create(T entity) {
getEntityManager().persist(entity);
}

protected void remove(T entity) {
getEntityManager().remove(getEntityManager().merge(entity));
}
protected void edit(T entity) {
getEntityManager().merge(entity);
}

protected T find(Object id) {
return getEntityManager().find(entityClass, id);
}
protected void remove(T entity) {
getEntityManager().remove(getEntityManager().merge(entity));
}

protected List<T> findAll() {
CriteriaQuery<T> cq = getEntityManager().getCriteriaBuilder().createQuery(entityClass);
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
}
protected T find(Object id) {
return getEntityManager().find(entityClass, id);
}

protected List<T> findAll() {
CriteriaQuery<T> cq = getEntityManager().getCriteriaBuilder().createQuery(entityClass);
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
}

protected List<T> findAll(OrderDirective... directives) {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<T> cq = cb.createQuery(entityClass);
Root<T> root = cq.from(entityClass);
cq.select(root);
List<Order> orders = new ArrayList<Order>();
for (OrderDirective ob : directives) {
Order o;

Path p = root.get(ob.field);

if (ob.asc) {
o = cb.asc(p);
} else {
o = cb.desc(p);
}

orders.add(o);
}
cq.orderBy(orders);
return getEntityManager().createQuery(cq).getResultList();
protected List<T> findAll(OrderDirective... directives) {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<T> cq = cb.createQuery(entityClass);
Root<T> root = cq.from(entityClass);
cq.select(root);
List<Order> orders = new ArrayList<Order>();
for (OrderDirective ob : directives) {
Order o;

Path p = root.get(ob.field);

if (ob.asc) {
o = cb.asc(p);
} else {
o = cb.desc(p);
}

orders.add(o);
}
cq.orderBy(orders);
return getEntityManager().createQuery(cq).getResultList();
}

public static class OrderDirective {
public static class OrderDirective {

private final String field;
private final boolean asc;
private final String field;
private final boolean asc;

public OrderDirective(String field) {
this(field, true);
}
public OrderDirective(String field) {
this(field, true);
}

public OrderDirective(String field, boolean asc) {
this.field = field;
this.asc = asc;
}
public OrderDirective(String field, boolean asc) {
this.field = field;
this.asc = asc;
}

public String getField() {
return field;
}
public String getField() {
return field;
}

public boolean isAsc() {
return asc;
}
public boolean isAsc() {
return asc;
}
}

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
protected String checkAuthenticated() {
String username = context.getCallerPrincipal().getName();
if (username == null || username.isEmpty() || username.equalsIgnoreCase("ANONYMOUS")) {
throw new EJBAccessException("You must be authenticated to perform the requested operation");
} else {
username = username.split(":")[2];
}

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
protected String checkAuthenticated() {
String username = context.getCallerPrincipal().getName();
if (username == null || username.isEmpty() || username.equalsIgnoreCase("ANONYMOUS")) {
throw new EJBAccessException("You must be authenticated to perform the requested operation");
} else {
username = username.split(":")[2];
}
return username;
}
return username;
}
}
29 changes: 14 additions & 15 deletions src/main/java/org/jlab/cnm/business/session/ElementCodeFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@
import org.jlab.cnm.persistence.entity.ElementCode;

/**
*
* @author ryans
*/
@Stateless
public class ElementCodeFacade extends AbstractFacade<ElementCode> {
@PersistenceContext(unitName = "webappPU")
private EntityManager em;
@PersistenceContext(unitName = "webappPU")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
return em;
}
@Override
protected EntityManager getEntityManager() {
return em;
}

public ElementCodeFacade() {
super(ElementCode.class);
}
@Override
public List<ElementCode> findAll() {
return super.findAll(new OrderDirective("zzCode"));
}
public ElementCodeFacade() {
super(ElementCode.class);
}

@Override
public List<ElementCode> findAll() {
return super.findAll(new OrderDirective("zzCode"));
}
}
130 changes: 66 additions & 64 deletions src/main/java/org/jlab/cnm/business/session/ExcelCodeListFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,75 +14,77 @@
import org.jlab.cnm.persistence.entity.TypeCode;

/**
*
* @author ryans
*/
@Stateless
public class ExcelCodeListFacade {

@PermitAll
public void export(OutputStream out, List<SystemCode> systemList, List<TypeCode> typeList, List<SectorCode> sectorList) throws IOException {
Workbook wb = new XSSFWorkbook();


// START Sheet 1
Sheet sheet1 = wb.createSheet("System Codes");

int rownum = 0;

for (SystemCode code : systemList) {
Row row = sheet1.createRow(rownum++);

row.createCell(0).setCellValue(String.valueOf(code.getSCode()));
row.createCell(1).setCellValue(code.getDescription());
}

sheet1.autoSizeColumn(0);
sheet1.autoSizeColumn(1);

// END Sheet 1
// START Sheet 2

Sheet sheet2 = wb.createSheet("Type Codes");

rownum = 0;

for(TypeCode code: typeList) {
Row row = sheet2.createRow(rownum++);

row.createCell(0).setCellValue(String.valueOf(code.getSystemCode().getSCode()));
row.createCell(1).setCellValue(code.getVvCode());
row.createCell(2).setCellValue(code.getDescription());
row.createCell(3).setCellValue(code.getGrouping());
}

sheet2.autoSizeColumn(0);
sheet2.autoSizeColumn(1);
sheet2.autoSizeColumn(2);
sheet2.autoSizeColumn(3);

// END Sheet 2
// START Sheet 3

Sheet sheet3 = wb.createSheet("Sector Codes");

rownum = 0;

for (SectorCode code : sectorList) {
Row row = sheet3.createRow(rownum++);

row.createCell(0).setCellValue(code.getXxCode());
row.createCell(1).setCellValue(code.getDescription());
row.createCell(2).setCellValue(code.getGrouping());
}

sheet3.autoSizeColumn(0);
sheet3.autoSizeColumn(1);
sheet3.autoSizeColumn(2);

// END Sheet 3

wb.write(out);
@PermitAll
public void export(
OutputStream out,
List<SystemCode> systemList,
List<TypeCode> typeList,
List<SectorCode> sectorList)
throws IOException {
Workbook wb = new XSSFWorkbook();

// START Sheet 1
Sheet sheet1 = wb.createSheet("System Codes");

int rownum = 0;

for (SystemCode code : systemList) {
Row row = sheet1.createRow(rownum++);

row.createCell(0).setCellValue(String.valueOf(code.getSCode()));
row.createCell(1).setCellValue(code.getDescription());
}

sheet1.autoSizeColumn(0);
sheet1.autoSizeColumn(1);

// END Sheet 1
// START Sheet 2

Sheet sheet2 = wb.createSheet("Type Codes");

rownum = 0;

for (TypeCode code : typeList) {
Row row = sheet2.createRow(rownum++);

row.createCell(0).setCellValue(String.valueOf(code.getSystemCode().getSCode()));
row.createCell(1).setCellValue(code.getVvCode());
row.createCell(2).setCellValue(code.getDescription());
row.createCell(3).setCellValue(code.getGrouping());
}

sheet2.autoSizeColumn(0);
sheet2.autoSizeColumn(1);
sheet2.autoSizeColumn(2);
sheet2.autoSizeColumn(3);

// END Sheet 2
// START Sheet 3

Sheet sheet3 = wb.createSheet("Sector Codes");

rownum = 0;

for (SectorCode code : sectorList) {
Row row = sheet3.createRow(rownum++);

row.createCell(0).setCellValue(code.getXxCode());
row.createCell(1).setCellValue(code.getDescription());
row.createCell(2).setCellValue(code.getGrouping());
}

sheet3.autoSizeColumn(0);
sheet3.autoSizeColumn(1);
sheet3.autoSizeColumn(2);

// END Sheet 3

wb.write(out);
}
}
Loading

0 comments on commit e7357c2

Please sign in to comment.