use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.
the class AddReferenceChange method execute.
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
HashMapVirtualObject object = transaction.get(oid);
if (object == null) {
Query query = new Query(packageMetaData);
QueryPart queryPart = query.createQueryPart();
queryPart.addOid(oid);
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
object = queryObjectProvider.next();
transaction.updated(object);
}
EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
if (!ChangeHelper.canBeChanged(eClass)) {
throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
}
if (object == null) {
throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
}
EReference eReference = packageMetaData.getEReference(eClass.getName(), referenceName);
if (eReference == null) {
throw new UserException("No reference with the name \"" + referenceName + "\" found in class \"" + eClass.getName() + "\"");
}
if (!eReference.isMany()) {
throw new UserException("Reference is not of type 'many'");
}
EClass eClassForOid = transaction.getDatabaseSession().getEClassForOid(referenceOid);
object.addReference(eReference, eClassForOid, referenceOid);
}
use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.
the class RemoveAllReferencesChange method execute.
@SuppressWarnings("rawtypes")
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
Query query = new Query(packageMetaData);
QueryPart queryPart = query.createQueryPart();
queryPart.addOid(oid);
HashMapVirtualObject object = transaction.get(oid);
if (object == null) {
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
object = queryObjectProvider.next();
transaction.updated(object);
}
EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
if (!ChangeHelper.canBeChanged(eClass)) {
throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
}
if (object == null) {
throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
}
EReference eReference = packageMetaData.getEReference(eClass.getName(), referenceName);
if (eReference == null) {
throw new UserException("No reference with the name \"" + referenceName + "\" found in class \"" + eClass.getName() + "\"");
}
if (!eReference.isMany()) {
throw new UserException("Reference is not of type 'many'");
}
List list = (List) object.get(eReference.getName());
while (!list.isEmpty()) {
list.remove(0);
}
}
use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.
the class RemoveReferenceChange method execute.
@SuppressWarnings("rawtypes")
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
Query query = new Query(packageMetaData);
QueryPart queryPart = query.createQueryPart();
queryPart.addOid(oid);
HashMapVirtualObject object = transaction.get(oid);
if (object == null) {
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
object = queryObjectProvider.next();
transaction.updated(object);
}
EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
if (object == null) {
throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
}
if (!ChangeHelper.canBeChanged(eClass)) {
throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
}
EReference eReference = packageMetaData.getEReference(eClass.getName(), referenceName);
if (eReference == null) {
throw new UserException("No reference with the name \"" + referenceName + "\" found in class \"" + eClass.getName() + "\"");
}
if (!eReference.isMany()) {
throw new UserException("Reference is not of type 'many'");
}
List list = (List) object.get(eReference.getName());
if (referencedOid != -1) {
list.remove((Object) referencedOid);
}
if (index != -1) {
list.remove(index);
}
}
use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.
the class DatabaseSession method getExactSize.
private int getExactSize(IdEObject idEObject, PackageMetaData packageMetaData, boolean useUnsetBits) {
int size = 0;
int bits = 0;
for (EStructuralFeature eStructuralFeature : idEObject.eClass().getEAllStructuralFeatures()) {
if (packageMetaData.useForDatabaseStorage(idEObject.eClass(), eStructuralFeature)) {
bits++;
if (!useUnsetBits || !useUnsetBit(eStructuralFeature, idEObject)) {
Object val = idEObject.eGet(eStructuralFeature);
if (eStructuralFeature instanceof EAttribute) {
EAttribute eAttribute = (EAttribute) eStructuralFeature;
if (eAttribute.isMany()) {
size += 4;
for (Object v : ((List<?>) val)) {
size += getPrimitiveSize(eAttribute.getEAttributeType(), v);
}
} else {
size += getPrimitiveSize(eAttribute.getEAttributeType(), val);
}
} else if (eStructuralFeature instanceof EReference) {
EReference eReference = (EReference) eStructuralFeature;
if (eReference.isMany()) {
size += 4;
for (Object v : ((List<?>) val)) {
size += getWrappedValueSize(v, eReference, packageMetaData);
}
} else {
size += getWrappedValueSize(val, eReference, packageMetaData);
}
}
}
}
}
if (useUnsetBits) {
size += (int) Math.ceil(bits / 8.0);
}
return size;
}
use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.
the class BimServer method updateUserPlugin.
@SuppressWarnings("unchecked")
public void updateUserPlugin(DatabaseSession session, User user, PluginDescriptor pluginDescriptor, PluginContext pluginContext) throws BimserverDatabaseException {
if (pluginDescriptor.isInstallForNewUsers()) {
UserSettings userSettings = user.getUserSettings();
if (userSettings == null) {
userSettings = session.create(UserSettings.class);
user.setUserSettings(userSettings);
session.store(user);
}
Class<?> pluginInterface = getPluginInterface(pluginContext.getPlugin().getClass());
String originalPluginInterfaceName = pluginInterface.getSimpleName();
String pluginInterfaceName = pluginInterface.getSimpleName();
if (pluginInterfaceName.endsWith("Plugin")) {
pluginInterfaceName = pluginInterfaceName.substring(0, pluginInterfaceName.length() - 6);
}
if (pluginInterfaceName.equals("StreamingSerializer")) {
pluginInterfaceName = "Serializer";
} else if (pluginInterfaceName.equals("MessagingStreamingSerializer")) {
pluginInterfaceName = "MessagingSerializer";
}
if (pluginInterfaceName.equals("StreamingDeserializer")) {
pluginInterfaceName = "Deserializer";
}
if (pluginInterfaceName.equals("ModelChecker") || pluginInterfaceName.equals("WebModule")) {
// ServerSettings
return;
}
EClass userSettingsClass = StorePackage.eINSTANCE.getUserSettings();
String listRefName = StringUtils.firstLowerCase(pluginInterfaceName) + "s";
if (listRefName.equals("messagingSerializers")) {
listRefName = "serializers";
}
EReference listReference = (EReference) userSettingsClass.getEStructuralFeature(listRefName);
if (listReference == null) {
LOGGER.warn(listRefName + " not found");
return;
}
EReference defaultReference = (EReference) userSettingsClass.getEStructuralFeature("default" + pluginInterfaceName);
EClass pluginConfigurationClass = (EClass) StorePackage.eINSTANCE.getEClassifier((pluginInterfaceName.equals("Service") ? "Internal" : "") + pluginInterfaceName + "PluginConfiguration");
List<PluginConfiguration> list = (List<PluginConfiguration>) userSettings.eGet(listReference);
PluginConfiguration pluginConfiguration = find(list, pluginContext.getIdentifier());
if (pluginConfiguration == null) {
pluginConfiguration = (PluginConfiguration) session.create(pluginConfigurationClass);
if (pluginConfiguration instanceof SerializerPluginConfiguration) {
boolean streaming = originalPluginInterfaceName.equals("StreamingSerializerPlugin") || originalPluginInterfaceName.equals("MessagingStreamingSerializerPlugin");
((SerializerPluginConfiguration) pluginConfiguration).setStreaming(streaming);
} else if (pluginConfiguration instanceof InternalServicePluginConfiguration) {
((InternalServicePluginConfiguration) pluginConfiguration).setUserSettings(userSettings);
}
list.add(pluginConfiguration);
genericPluginConversion(pluginContext, session, pluginConfiguration, pluginDescriptor);
}
if (pluginInterfaceName.equals("Service")) {
activateService(user.getOid(), (InternalServicePluginConfiguration) pluginConfiguration);
}
if (defaultReference != null) {
if (userSettings.eGet(defaultReference) == null || pluginConfiguration.getName().equals("IfcOpenShell")) {
userSettings.eSet(defaultReference, pluginConfiguration);
}
}
session.store(userSettings);
}
}
Aggregations