2
0
Fork 0

WIP: left over open files for long...

This commit is contained in:
Willem 2017-06-10 02:22:01 +02:00
parent 0a2398c5c1
commit 76aa74990e
165 changed files with 4299 additions and 3373 deletions

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>vasc-backend-object</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.forwardfire.vasc.backend</groupId>
<artifactId>vasc-backend</artifactId>
<version>0.4.2-SNAPSHOT</version>
</parent>
<artifactId>vasc-backend-object</artifactId>
<name>vasc-backend-object</name>
<description>vasc-backend-object</description>
<dependencies>
<dependency>
<groupId>net.forwardfire.vasc.backend</groupId>
<artifactId>vasc-backend-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,141 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend.object;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import net.forwardfire.vasc.backend.AbstractVascBackendLocal;
import net.forwardfire.vasc.backend.VascBackendAccessDataKey;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.select.DefaultVascBackendSelectItem;
import net.forwardfire.vasc.backend.select.VascBackendSelect;
import net.forwardfire.vasc.backend.select.VascBackendSelectItem;
/**
* ObjectEnumVascBackendSelect uses an Enum as select backend.
*
* @author Willem Cazander
* @version 1.0 Oct 27, 2007
*/
public class ObjectEnumVascBackendSelect<ENUM_RETURN_TYPE extends Serializable> extends AbstractVascBackendLocal<ENUM_RETURN_TYPE> implements VascBackendSelect<ENUM_RETURN_TYPE> {
private Class<? extends Enum<?>> enumClass = null;
private ObjectEnumVascBackendSelectType enumReturnType = null;
private String enumReturnMethod = null;
@Override
protected void startBackendLocal() {
requireNonNull(enumClass, "enumClass is null");
requireNonNull(enumReturnType, "enumClass is null");
}
@Override
public VascBackendAccessDataKey<ENUM_RETURN_TYPE> createVascBackendAccessDataKey() {
return null;
}
@Override
public List<VascBackendSelectItem<ENUM_RETURN_TYPE>> execute() throws VascBackendException {
List<VascBackendSelectItem<ENUM_RETURN_TYPE>> result = new ArrayList<VascBackendSelectItem<ENUM_RETURN_TYPE>>();
for (Enum<?> enumObject:enumClass.getEnumConstants()) {
boolean header = false;
boolean enabled = true;
String name = enumObject.name();
boolean nameI18nKey = false;
String description = enumObject.name();
boolean descriptionI18nKey = false;
ENUM_RETURN_TYPE primaryKey = (ENUM_RETURN_TYPE)getEnumValue(enumObject);
result.add(new DefaultVascBackendSelectItem<ENUM_RETURN_TYPE>(header,enabled,name,nameI18nKey,description,descriptionI18nKey,primaryKey));
}
return result;
}
private Object getEnumValue(Enum<?> enumObject) {
switch (enumReturnType) {
case VALUE:
return enumObject;
case METHOD:
try {
return enumObject.getClass().getMethod(enumReturnMethod, new Class<?>[]{}).invoke(null, new Object[]{});
} catch (Exception e) {
throw new IllegalStateException("Could not get static return method value: "+e.getMessage(),e);
}
case NAME:
return enumObject.name();
case ORDINAL:
return enumObject.ordinal();
default:
throw new IllegalStateException("Unknown enum return type: "+enumReturnType.name());
}
}
/*
public List<VascBackendSelectItem> getVascSelectItems(VascEntry currentEntry) throws VascException {
List<VascBackendSelectItem> result = new ArrayList<VascBackendSelectItem>(100);
if (nullLabel!=null) {
if (nullKeyValue==null) {
nullKeyValue = "null";
}
nullLabel = currentEntry.getVascFrontendController().getVascEntryResourceResolver().getTextValue(nullLabel);
VascBackendSelectItem item = new VascBackendSelectItem(nullLabel,null,nullKeyValue);
result.add(item);
}
if (enumClass!=null) {
for (Object o:enumClass.getEnumConstants()) {
String value = o.toString();
result.add(new VascBackendSelectItem(value,value,value));
}
}
if (data==null) {
return result;
}
if (data instanceof String) {
String[] values = ((String)data).split(",");
for (String value:values) {
result.add(new VascBackendSelectItem(value,value,value));
}
} else if (data instanceof List) {
List<?> values = (List<?>)data;
for (Object o:values) {
String value = ""+o;
result.add(new VascBackendSelectItem(value,value,value));
}
}
return result;
}
*/
}

View file

@ -0,0 +1,9 @@
package net.forwardfire.vasc.backend.object;
public enum ObjectEnumVascBackendSelectType {
VALUE,
NAME,
ORDINAL,
METHOD,
}

View file

@ -0,0 +1,311 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend.object;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListRequest;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.backend.select.VascBackendSelectItem;
/**
* The DefaultVascSelectItemModel
*
* @author Willem Cazander
* @version 1.0 Oct 27, 2007
*/
public class VascSelectItemModelEntry /*implements VascSelectItemModel*/ {
/*
private static final long serialVersionUID = 1L;
private String entryId = null;
private String keyFieldId = null;
private String displayFieldId = null;
private String nullLabel = null;
private String nullKeyValue = null;
private String nullObjectValue = null;
private Boolean returnKeyValue = null;
private Map<String,String> entryParameterFieldIds = new HashMap<String,String>(3);
private Boolean useParentFields = null;
@Override
public List<VascBackendSelectItem> getVascSelectItems(VascEntry currentEntry) throws VascException {
List<VascBackendSelectItem> result = new ArrayList<VascBackendSelectItem>(100);
VascEntryLocal entry = (VascEntryLocal)currentEntry.getVascFrontendController().getVascController().getVascEntryController().getVascEntryById(entryId);
if (keyFieldId==null) {
keyFieldId = entry.getPrimaryKeyFieldId();
}
VascEntryFieldLocal key = (VascEntryFieldLocal)entry.getVascEntryFieldById(keyFieldId);
if (displayFieldId==null) {
displayFieldId = entry.getDisplayNameFieldId();
}
VascEntryFieldLocal dis = (VascEntryFieldLocal)entry.getVascEntryFieldById(displayFieldId);
if (key==null) {
throw new VascException("Could not find: "+keyFieldId+" from: "+entry.getId());
}
if (dis==null) {
throw new VascException("Could not find: "+displayFieldId+" from: "+entry.getId());
}
// set frontend data for new clone, we need te get better lifecycle management for stats/entry/etc
entry.setVascFrontendController(currentEntry.getVascFrontendController());
VascBackendCrud<Serializable,Serializable> back = currentEntry.getVascFrontendController().getVascController().getVascEntryConfigController().configVascBackendProxied(currentEntry.getVascFrontendController().getVascController(), entry);
try {
if (nullLabel!=null) {
if (nullKeyValue==null) {
nullKeyValue = "null";
}
nullLabel = currentEntry.getVascFrontendController().getVascEntryResourceResolver().getTextValue(nullLabel);
if (nullObjectValue==null) {
result.add(new VascBackendSelectItem(nullLabel,null,nullKeyValue));
} else {
result.add(new VascBackendSelectItem(nullLabel,nullObjectValue,nullKeyValue));
}
}
// set def para
DefaultVascBackendListRequest state = new DefaultVascBackendListRequest();
for (String key2:entry.getEntryParameterKeys()) {
Object value = entry.getEntryParameter(key2);
//System.out.println("Copy paras name: "+key2+" value: "+value+" class: "+value.getClass().getName());
state.setDataParameter(key2, value);
}
// set list para
for (VascEntryField vef:entry.getVascEntryListOptions()) {
Object def = vef.getDefaultValue();
if (def==null) {
continue;
}
String backendName = vef.getBackendName();
state.setDataParameter(backendName, def);
}
// set para from parent state entry
for (String paraName:entryParameterFieldIds.keySet()) {
VascEntry fieldEntry = currentEntry;
if (useParentFields!=null && useParentFields==true) {
if (currentEntry.getVascFrontendController().getVascEntryState().getParent()==null) {
throw new IllegalStateException("Requested to use parent state field values but no parent state found.");
}
fieldEntry = currentEntry.getVascFrontendController().getVascEntryState().getParent().getVascEntry();
}
String paraValueId = entryParameterFieldIds.get(paraName);
VascEntryFieldLocal fieldOrg = (VascEntryFieldLocal)fieldEntry.getVascEntryFieldById(paraValueId);
if (fieldOrg==null) {
//System.out.println("could not find field: "+paraValueId);
continue;
}
VascEntryField field = fieldOrg.clone();
field.getVascValidators().clear();
VascBackendAccessDataRecord<Serializable,Serializable> v = fieldEntry.getVascFrontendController().getVascEntryState().getVascBackend().provideVascEntryFieldValue();
Serializable record = fieldEntry.getVascFrontendController().getVascEntryState().getEntryDataObject();
if (record==null) {
//System.out.println("could not get selected records from state.");
continue;
}
Object value = v.getValue(fieldOrg.getBackendName(), record);
//System.out.println("Set entry paras name: "+paraName+" value: "+value+" class: "+value.getClass().getName());
state.setDataParameter(paraName, value);
}
// TODO: FIX >>>>>>>>>>>>>>>>>>
if (key.getVascEntryFieldValue()==null) {
// TODO: fix this for better remote support
VascEntryField fieldClone = key.clone();
fieldClone.getVascValidators().clear();
VascBackendAccessDataRecord<Serializable,Serializable> v = currentEntry.getVascFrontendController().getVascEntryState().getVascBackend().provideVascEntryFieldValue();
key.setVascEntryFieldValue(v);
}
if (dis.getVascEntryFieldValue()==null) {
// TODO: fix this for better remote support
VascEntryField fieldClone = dis.clone();
fieldClone.getVascValidators().clear();
VascBackendAccessDataRecord<Serializable,Serializable> v = currentEntry.getVascFrontendController().getVascEntryState().getVascBackend().provideVascEntryFieldValue();
dis.setVascEntryFieldValue(v);
}
// execute
for (Serializable o:back.execute(state).getPageData()) {
Serializable keyId = key.getVascEntryFieldValue().getValue(key.getBackendName(), o);
String nameId = ""+dis.getVascEntryFieldValue().getValue(dis.getBackendName(), o);
if (returnKeyValue!=null && false==returnKeyValue) {
VascBackendSelectItem item = new VascBackendSelectItem(nameId,o,""+keyId);
result.add(item);
} else {
VascBackendSelectItem item = new VascBackendSelectItem(nameId,keyId,""+keyId); // per default return keyID object.
result.add(item);
}
}
} catch (Exception e) {
throw new VascException(e);
}
return result;
}
/*
//
// /**
// * @return the entryId
// */
// public String getEntryId() {
// return entryId;
// }
//
// /**
// * @param entryId the entryId to set
// */
// public void setEntryId(String entryId) {
// this.entryId = entryId;
// }
//
// /**
// * @return the keyFieldId
// */
// public String getKeyFieldId() {
// return keyFieldId;
// }
//
// /**
// * @param keyFieldId the keyFieldId to set
// */
// public void setKeyFieldId(String keyFieldId) {
// this.keyFieldId = keyFieldId;
// }
//
// /**
// * @return the displayFieldId
// */
// public String getDisplayFieldId() {
// return displayFieldId;
// }
//
// /**
// * @param displayFieldId the displayFieldId to set
// */
// public void setDisplayFieldId(String displayFieldId) {
// this.displayFieldId = displayFieldId;
// }
//
// /**
// * @return the nullLabel
// */
// @Override
// public String getNullLabel() {
// return nullLabel;
// }
//
// /**
// * @param nullLabel the nullLabel to set
// */
// @Override
// public void setNullLabel(String nullLabel) {
// this.nullLabel = nullLabel;
// }
//
// /**
// * @return the nullKeyValue
// */
// @Override
// public String getNullKeyValue() {
// return nullKeyValue;
// }
//
// /**
// * @param nullKeyValue the nullKeyValue to set
// */
// @Override
// public void setNullKeyValue(String nullKeyValue) {
// this.nullKeyValue = nullKeyValue;
// }
//
// /**
// * @return the returnKeyValue
// */
// public Boolean getReturnKeyValue() {
// return returnKeyValue;
// }
//
// /**
// * @param returnKeyValue the returnKeyValue to set
// */
// public void setReturnKeyValue(Boolean returnKeyValue) {
// this.returnKeyValue = returnKeyValue;
// }
//
// public String getEntryParameterFieldId(String parameterName) {
// return entryParameterFieldIds.get(parameterName);
// }
// public void addEntryParameterFieldId(String parameterName,String valueFieldId) {
// entryParameterFieldIds.put(parameterName, valueFieldId);
// }
// public List<String> getEntryParameterFieldIdKeys() {
// return new ArrayList<String>(entryParameterFieldIds.keySet());
// }
//
// /**
// * @return the useParentFields
// */
// public Boolean getUseParentFields() {
// return useParentFields;
// }
//
// /**
// * @param useParentFields the useParentFields to set
// */
// public void setUseParentFields(Boolean useParentFields) {
// this.useParentFields = useParentFields;
// }
//
// /**
// * @return the nullObjectValue
// */
// public String getNullObjectValue() {
// return nullObjectValue;
// }
//
// /**
// * @param nullObjectValue the nullObjectValue to set
// */
// public void setNullObjectValue(String nullObjectValue) {
// this.nullObjectValue = nullObjectValue;
// }
//
}

View file

@ -0,0 +1,8 @@
/**
*
*/
/**
* @author willemc
*
*/
package net.forwardfire.vasc.backend.object;