Skip to content

Commit

Permalink
Low level interface, cleanup set attribute at index
Browse files Browse the repository at this point in the history
Removed obsolete code, maybe copy-paste leftovers from the
original SetAttributeChange?
  • Loading branch information
hlg committed Mar 16, 2021
1 parent 94d0db2 commit 9c9d474
Showing 1 changed file with 23 additions and 42 deletions.
65 changes: 23 additions & 42 deletions BimServer/src/org/bimserver/changes/SetAttributeChangeAtIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,24 @@
import org.bimserver.emf.PackageMetaData;
import org.bimserver.shared.HashMapVirtualObject;
import org.bimserver.shared.exceptions.UserException;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;

public class SetAttributeChangeAtIndex implements Change {

private final long oid;
private final String attributeName;
import org.eclipse.emf.ecore.*;

public class SetAttributeChangeAtIndex implements Change {

private final long oid;
private final String attributeName;
private final Object value;
private int index;

public SetAttributeChangeAtIndex(long oid, String attributeName, int index, Object value) {
this.oid = oid;
private int index;

public SetAttributeChangeAtIndex(long oid, String attributeName, int index, Object value) {
this.oid = oid;
this.attributeName = attributeName;
this.index = index;
this.value = value;
}

this.index = index;
this.value = value;
}

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());

Expand Down Expand Up @@ -79,28 +75,13 @@ public void execute(Transaction transaction) throws UserException, BimserverLock
if (eAttribute == null) {
throw new UserException("No attribute with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
}
if (value instanceof List && eAttribute.isMany()) {
List sourceList = (List)value;
if (!eAttribute.isMany()) {
throw new UserException("Attribute is not of type 'many'");
}
List list = (List)object.eGet(eAttribute);
list.clear();
List asStringList = null;
if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
asStringList = (List)object.eGet(object.eClass().getEStructuralFeature(attributeName + "AsString"));
asStringList.clear();
}
for (Object o : sourceList) {
if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
asStringList.add(String.valueOf(o));
}
list.add(o);
}
if (!eAttribute.isMany()) {
throw new UserException("Attribute is not of type 'many'");
}
if (value instanceof List) {
throw new UserException("Value is list, only primitive values allowed.");
// If this was a two-dimensional array we would have a structural feature, not an attribute referring to the inner array
} else {
if (!eAttribute.isMany()) {
throw new UserException("Attribute is not of type 'many'");
}
if (eAttribute.getEType() instanceof EEnum) {
EEnum eEnum = (EEnum) eAttribute.getEType();
object.setListItem(eAttribute, index, eEnum.getEEnumLiteral(((String) value).toUpperCase()).getInstance());
Expand All @@ -111,6 +92,6 @@ public void execute(Transaction transaction) throws UserException, BimserverLock
EStructuralFeature asStringAttribute = object.eClass().getEStructuralFeature(attributeName + "AsString");
object.setListItem(asStringAttribute, index, String.valueOf((Double)value));
}
}
}
}
}
}

0 comments on commit 9c9d474

Please sign in to comment.