use of com.servoy.j2db.util.UUID in project servoy-client by Servoy.
the class AbstractSolutionTest method buildSolution.
@Before
public void buildSolution() throws Exception {
TestNGClient.initSettings();
Types.getTypesInstance().registerTypes();
final File f = new File(NGClient.class.getProtectionDomain().getCodeSource().getLocation().getPath());
IPackageReader[] servicesReaders = null;
IPackageReader[] componentsReaders = null;
InMemPackageReader inMemPackageReader = getTestComponents();
if (f.isFile() && f.getName().startsWith("servoy_ngclient") && f.getName().endsWith(".jar")) {
// it is running from bundles/jars
ZipFile zipFile = new ZipFile(f);
componentsReaders = inMemPackageReader != null ? new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoycore/"), new ZipPackageReader(zipFile, "war/servoydefault/"), inMemPackageReader } : new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoycore/"), new ZipPackageReader(zipFile, "war/servoydefault/") };
servicesReaders = new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoyservices/") };
} else {
// it is running from sources/projects
File ngClientProjDir = f;
if (!new File(ngClientProjDir, "/war/servoycore/").exists()) {
ngClientProjDir = ngClientProjDir.getParentFile();
}
componentsReaders = getReaders(new File[] { new File(ngClientProjDir.getAbsoluteFile() + "/war/servoycore/"), new File(ngClientProjDir.getAbsoluteFile() + "/war/servoydefault/") }, // in eclipse we .. out of bin, in jenkins we .. out of @dot
inMemPackageReader);
servicesReaders = getReaders(new File[] { new File(ngClientProjDir.getAbsoluteFile(), "/war/servoyservices/") }, null);
}
WebComponentSpecProvider.init(componentsReaders, DefaultComponentPropertiesProvider.instance);
WebServiceSpecProvider.init(servicesReaders);
final TestRepository tr = new TestRepository();
try {
ApplicationServerRegistry.setApplicationServerSingleton(new TestApplicationServer(tr));
UUID uuid = UUID.randomUUID();
final RootObjectMetaData metadata = tr.createRootObjectMetaData(tr.getElementIdForUUID(uuid), uuid, "Test", IRepository.SOLUTIONS, 1, 1);
solution = (Solution) tr.createRootObject(metadata);
tr.cacheRootObject(solution);
solution.setChangeHandler(new ChangeHandler(tr));
fillTestSolution();
HttpSession testHttpsession = new TestHttpsession();
endpoint = new NGClientEndpoint() {
// for testing onstart of the NGClientEndpoint should not run
@Override
public void onStart() {
}
@Override
protected HttpSession getHttpSession(Session session) {
return testHttpsession;
}
};
NGClientWebsocketSession session = new NGClientWebsocketSession(new WebsocketSessionKey(testHttpsession.getId(), 1)) {
@Override
public void init(Map<String, List<String>> requestParams) throws Exception {
// override default init, shouldnt make another client.
}
@Override
protected IEventDispatcher createEventDispatcher() {
return new TestNGEventDispatcher(endpoint);
}
};
WebsocketSessionManager.addSession(session);
NGClientWebsocketSessionWindows windows = new NGClientWebsocketSessionWindows(session);
CurrentWindow.set(windows);
client = new TestNGClient(tr, session) {
@Override
public boolean loadSolutionsAndModules(SolutionMetaData solutionMetaData) {
boolean b = super.loadSolutionsAndModules(solutionMetaData);
IPersistIndex index = PersistIndexCache.getCachedIndex(solution);
solution.getChangeHandler().addIPersistListener((IItemChangeListener<IPersist>) index);
try {
setupData();
} catch (ServoyException e) {
e.printStackTrace();
}
return b;
}
};
J2DBGlobals.setServiceProvider(client);
client.setUseLoginSolution(false);
endpoint.start(new TestSession(), String.valueOf(session.getSessionKey().getClientnr()), "null", "42");
CurrentWindow.set(session.getWindows().iterator().next());
} catch (RepositoryException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.servoy.j2db.util.UUID in project servoy-client by Servoy.
the class FlattenedSolution method getSolutionCopy.
public Solution getSolutionCopy(boolean create) {
if (mainSolution == null) {
if (loginFlattenedSolution != null) {
return loginFlattenedSolution.getSolutionCopy(create);
}
return null;
}
if (copySolution != null || !create)
return copySolution;
try {
SimplePersistFactory factory = getPersistFactory();
copySolution = SimplePersistFactory.createDummyCopy(mainSolution);
copySolution.setChangeHandler(new ChangeHandler(factory) {
// overwrite this new Object to skip the call to rootObject.registerNewObject(object); which shouldn't be needed for solution model solutions.
@Override
public IPersist createNewObject(ISupportChilds parent, int object_type_id, int element_id, UUID uuid) throws RepositoryException {
return factory.createObject(parent, object_type_id, element_id, uuid);
}
});
copySolution.getChangeHandler().addIPersistListener(this);
getIndex().setSolutionModelSolution(copySolution);
} catch (Exception e) {
Debug.error(e);
}
return copySolution;
}
use of com.servoy.j2db.util.UUID in project servoy-client by Servoy.
the class FlattenedSolution method clonePersist.
@SuppressWarnings({ "unchecked", "nls" })
public <T extends AbstractBase> T clonePersist(T persist, String newName, AbstractBase newParent) {
T clone = (T) persist.clonePersist(persist.getParent() == newParent ? null : newParent);
final Map<Object, Object> updatedElementIds = AbstractPersistFactory.resetUUIDSRecursively(clone, getPersistFactory(), false);
if (persist.getParent() == newParent) {
newParent.addChild(clone);
}
// make sure that this persist is not seen as a copy a real persist/form
clone.setRuntimeProperty(CLONE_PROPERTY, null);
if (clone instanceof ISupportUpdateableName) {
try {
((ISupportUpdateableName) clone).updateName(new ScriptNameValidator(this), newName);
} catch (Exception e) {
if (newParent != null) {
newParent.removeChild(clone);
}
throw new RuntimeException("name '" + newName + "' invalid for the clone of " + ((ISupportName) persist).getName() + ", error: " + e.getMessage());
}
}
if (clone instanceof ISupportChilds) {
clone.acceptVisitor(new IPersistVisitor() {
public Object visit(IPersist o) {
if (o instanceof AbstractBase) {
Map<String, Object> propertiesMap = ((AbstractBase) o).getPropertiesMap();
for (Map.Entry<String, Object> entry : propertiesMap.entrySet()) {
Object elementId = updatedElementIds.get(entry.getValue());
if (elementId instanceof Integer) {
Element element = StaticContentSpecLoader.getContentSpec().getPropertyForObjectTypeByName(o.getTypeID(), entry.getKey());
if (element.getTypeID() == IRepository.ELEMENTS)
((AbstractBase) o).setProperty(entry.getKey(), elementId);
} else if (entry.getValue() instanceof JSONObject) {
updateElementReferences((JSONObject) entry.getValue(), updatedElementIds);
}
}
}
return null;
}
});
}
if (securityAccess != null) {
ConcurrentMap<Object, Integer> securityValues = securityAccess.getLeft();
for (Object elementUUID : new HashSet(securityValues.keySet())) {
if (updatedElementIds.containsKey(elementUUID.toString())) {
UUID uuid = Utils.getAsUUID(updatedElementIds.get(elementUUID.toString()), false);
if (uuid != null) {
securityValues.put(uuid, securityValues.get(elementUUID));
}
}
}
}
flush(persist);
getIndex().reload();
return clone;
}
use of com.servoy.j2db.util.UUID in project servoy-client by Servoy.
the class ComponentFactory method getRealValueList.
@SuppressWarnings("unchecked")
public static IValueList getRealValueList(IServiceProvider application, ValueList valuelist, boolean useSoftCacheForCustom, int type, ParsedFormat format, String dataprovider, boolean readOnlyCache) {
if (application == null) {
application = J2DBGlobals.getServiceProvider();
}
IValueList list = null;
if (valuelist != null && (valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES || // reuse,those are static,OTHERS not!
(valuelist.getValueListType() == IValueListConstants.DATABASE_VALUES && valuelist.getDatabaseValuesType() == IValueListConstants.TABLE_VALUES))) {
WeakHashMap<UUID, Object> hmValueLists = null;
if (application != null) {
hmValueLists = (WeakHashMap<UUID, Object>) application.getRuntimeProperties().get(IServiceProvider.RT_VALUELIST_CACHE);
if (hmValueLists == null) {
hmValueLists = new WeakHashMap<UUID, Object>();
application.getRuntimeProperties().put(IServiceProvider.RT_VALUELIST_CACHE, hmValueLists);
}
Object object = hmValueLists.get(valuelist.getUUID());
if (object instanceof SoftReference<?>) {
SoftReference<IValueList> sr = (SoftReference<IValueList>) object;
list = sr.get();
// if it was inserted by a soft reference but now it can't be softly referenced, put it back in hard.
if (list != null && !useSoftCacheForCustom && !readOnlyCache) {
hmValueLists.put(valuelist.getUUID(), list);
}
} else if (object instanceof IValueList) {
list = (IValueList) object;
}
}
// as it may have been changed via solution model (that creates a new persist copy ), and then we need to replace the cached value
if (list != null && list.getValueList() != valuelist) {
list = null;
}
if (list == null) {
list = ValueListFactory.createRealValueList(application, valuelist, type, format);
if (valuelist.getFallbackValueListID() > 0 && valuelist.getFallbackValueListID() != valuelist.getID()) {
list.setFallbackValueList(getFallbackValueList(application, dataprovider, type, format, valuelist));
}
if (!useSoftCacheForCustom && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
if (hmValueLists != null && !readOnlyCache)
hmValueLists.put(valuelist.getUUID(), list);
if (dataprovider != null) {
((CustomValueList) list).addDataProvider(dataprovider);
}
} else {
if (hmValueLists != null && !readOnlyCache)
hmValueLists.put(valuelist.getUUID(), new SoftReference<IValueList>(list));
if (dataprovider != null && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
((CustomValueList) list).addDataProvider(dataprovider);
}
}
} else if (valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
if (application instanceof IApplication && ((IApplication) application).isInDeveloper()) {
int currentType = ((CustomValueList) list).getValueType();
if (currentType == Types.OTHER) {
((CustomValueList) list).setValueType(type);
if (dataprovider != null) {
((CustomValueList) list).addDataProvider(dataprovider);
}
} else if (type != Types.OTHER && type != currentType && !((Column.mapToDefaultType(type) == IColumnTypes.INTEGER && Column.mapToDefaultType(currentType) == IColumnTypes.NUMBER) || (Column.mapToDefaultType(type) == IColumnTypes.NUMBER && Column.mapToDefaultType(currentType) == IColumnTypes.INTEGER))) {
List<String> lst = ((CustomValueList) list).getDataProviders();
StringBuffer message = new StringBuffer("The valuelist was already created for type: " + Column.getDisplayTypeString(((CustomValueList) list).getValueType()));
message.append("\n for the dataproviders: ");
for (String previousProviders : lst) {
message.append(previousProviders);
message.append(",");
}
message.setLength(message.length() - 1);
message.append("\nSo it can't be used also for type: " + Column.getDisplayTypeString(type) + " for the dataprovider: " + dataprovider);
message.append("\nPlease edit these dataprovider(s) (using table editor for database column or Edit variable context menu action for variables) of this valuelist: " + valuelist.getName() + " so that they have the same type.");
application.reportError("Valuelist: " + list.getName() + " used with different types", message);
}
}
}
} else {
list = ValueListFactory.createRealValueList(application, valuelist, type, format);
if (valuelist != null && valuelist.getFallbackValueListID() > 0 && valuelist.getFallbackValueListID() != valuelist.getID()) {
list.setFallbackValueList(getFallbackValueList(application, dataprovider, type, format, valuelist));
}
}
return list;
}
use of com.servoy.j2db.util.UUID in project servoy-client by Servoy.
the class AbstractRepository method searchPersist.
/**
* Search the persist in the parent tree.
* <p>
* optimized using the assumption that the persist is in a tree of similar structure to the tree of parent.
*
* @param parent
* @param persist
* @throws RepositoryException
*/
@SuppressWarnings("unchecked")
public static <T extends IPersist> T searchPersist(ISupportChilds parent, T persist) {
if (persist == null || parent == null)
return null;
UUID parentUuid = parent.getUUID();
if (parentUuid.equals(persist.getUUID()))
return (T) parent;
// find the path to the parent
List<UUID> path = new ArrayList<UUID>();
IPersist p = persist;
while (p != null) {
path.add(p.getUUID());
if (p.getUUID().equals(parentUuid)) {
p = null;
} else {
p = p.getParent();
}
}
if (path.size() > 0 && parentUuid.equals(path.get(path.size() - 1))) {
// find persist via same path
IPersist node = parent;
for (int i = path.size() - 2; node != null && i >= 0; i--) {
node = ((ISupportChilds) node).getChild(path.get(i));
}
if (node != null) {
return (T) node;
}
}
// not found via the path, check if the persist's (grand)parent is the parent, in that case the persist was deleted
p = persist;
while (p != null) {
if (p == parent) {
// persist was deleted, no need to do a complete search
return null;
}
p = p.getParent();
}
// not found via the path and in different parent, fall back on complete search on uuid
return (T) searchPersist(parent, persist.getUUID(), persist.getParent());
}
Aggregations