format the source code for the issue we have

This commit is contained in:
YuCheng Hu 2023-08-28 17:46:18 -04:00
parent 40523282fb
commit d2e2f54722
1 changed files with 91 additions and 113 deletions

View File

@ -17,8 +17,7 @@ import java.util.HashMap;
import static org.reso.service.servlet.RESOservlet.resourceLookup;
import static org.reso.service.servlet.RESOservlet.getConnection;
public class EnumFieldInfo extends FieldInfo
{
public class EnumFieldInfo extends FieldInfo {
private String lookupName;
private final ArrayList<EnumValueInfo> values = new ArrayList<>();
private final HashMap<String, Object> valueLookup = new HashMap<>();
@ -29,25 +28,20 @@ public class EnumFieldInfo extends FieldInfo
private static final String LOOKUP_COLUMN_NAME = "LookupValue";
public EnumFieldInfo(String fieldName, FullQualifiedName type)
{
public EnumFieldInfo(String fieldName, FullQualifiedName type) {
super(fieldName, type);
}
public void addValue(EnumValueInfo value)
{
public void addValue(EnumValueInfo value) {
values.add(value);
}
private void loadValues()
{
private void loadValues() {
ResourceInfo resource = resourceLookup.get("Lookup");
if (resource!=null)
{
if (resource != null) {
Connection connect = getConnection();
String queryString = null;
try
{
try {
Statement statement = connect.createStatement();
HashMap<String, Boolean> selectLookup = new HashMap<>();
selectLookup.put(LOOKUP_COLUMN_NAME, true);
@ -56,26 +50,21 @@ public class EnumFieldInfo extends FieldInfo
LOG.debug("Query: " + queryString);
ResultSet resultSet = statement.executeQuery(queryString);
while (resultSet.next())
{
while (resultSet.next()) {
Entity ent = CommonDataProcessing.getEntityFromRow(resultSet, resource, selectLookup);
Property property = ent.getProperty(LOOKUP_COLUMN_NAME);
String val = property.getValue().toString();
values.add(new EnumValueInfo(val));
}
}
catch (Exception e)
{
} catch (Exception e) {
LOG.info("Query: " + queryString);
LOG.error("Error in finding Lookup values for " + lookupName + ": " + e.getMessage());
}
}
}
public ArrayList<EnumValueInfo> getValues()
{
if (values.size()==0)
{
public ArrayList<EnumValueInfo> getValues() {
if (values.size() == 0) {
EnumValueInfo sampleValue = new EnumValueInfo("Sample" + lookupName + "EnumValue");
values.add(sampleValue);
}
@ -83,16 +72,15 @@ public class EnumFieldInfo extends FieldInfo
return values;
}
public void setLookupName(String name) { lookupName=name; }
public void setLookupName(String name) {
lookupName = name;
}
public FullQualifiedName getType()
{
if (values.size()==0)
{
public FullQualifiedName getType() {
if (values.size() == 0) {
getValues();
}
if (values.size()>0)
{
if (values.size() > 0) {
return new FullQualifiedName("org.reso.metadata.enums." + lookupName);
}
@ -102,49 +90,39 @@ public class EnumFieldInfo extends FieldInfo
/**
* Accessor for lookupName
*
* @return
*/
public String getLookupName()
{
public String getLookupName() {
return lookupName;
}
public boolean isCollection()
{
public boolean isCollection() {
return isCollection;
}
public void setCollection()
{
public void setCollection() {
isCollection = true;
}
public void setFlags()
{
public void setFlags() {
isFlags = true;
}
public boolean isFlags()
{
public boolean isFlags() {
return isFlags;
}
public Object getValueOf(String enumStringValue)
{
public Object getValueOf(String enumStringValue) {
Object value = valueLookup.get(enumStringValue);
if (value==null)
{
if (value == null) {
long bitValue = 1;
for (EnumValueInfo val: values)
{
for (EnumValueInfo val : values) {
valueLookup.put(val.getValue(), bitValue);
if (isFlags)
{
if (isFlags) {
bitValue = bitValue * 2;
}
else
{
} else {
bitValue = bitValue + 1;
}
}