use of org.structr.core.property.GenericProperty in project structr by structr.
the class JarConfigurationProvider method getPropertyKeyForDatabaseName.
@Override
public PropertyKey getPropertyKeyForDatabaseName(Class type, String dbName, boolean createGeneric) {
Map<String, PropertyKey> classDBNamePropertyMap = getClassDBNamePropertyMapForType(type);
PropertyKey key = classDBNamePropertyMap.get(dbName);
if (key == null) {
// first try: uuid
if (GraphObject.id.dbName().equals(dbName)) {
return GraphObject.id;
}
if (createGeneric) {
key = new GenericProperty(dbName);
}
}
return key;
}
use of org.structr.core.property.GenericProperty in project structr by structr.
the class EnvResource method doGet.
@Override
public Result doGet(PropertyKey sortKey, boolean sortDescending, int pageSize, int page) throws FrameworkException {
final List<GraphObjectMap> resultList = new LinkedList<>();
final GraphObjectMap info = new GraphObjectMap();
info.setProperty(new GenericProperty("modules"), VersionHelper.getModules());
info.setProperty(new GenericProperty("components"), VersionHelper.getComponents());
info.setProperty(new StringProperty("classPath"), VersionHelper.getClassPath());
info.setProperty(new StringProperty("instanceName"), VersionHelper.getInstanceName());
info.setProperty(new StringProperty("instanceStage"), VersionHelper.getInstanceStage());
info.setProperty(new ArrayProperty("mainMenu", String.class), VersionHelper.getMenuEntries());
final LicenseManager licenseManager = Services.getInstance().getLicenseManager();
if (licenseManager != null) {
info.setProperty(new StringProperty("edition"), licenseManager.getEdition());
info.setProperty(new StringProperty("licensee"), licenseManager.getLicensee());
info.setProperty(new StringProperty("hostId"), licenseManager.getHardwareFingerprint());
info.setProperty(new StringProperty("startDate"), licenseManager.getStartDate());
info.setProperty(new StringProperty("endDate"), licenseManager.getEndDate());
} else {
info.setProperty(new StringProperty("edition"), "Community");
info.setProperty(new StringProperty("licensee"), "Unlicensed");
}
resultList.add(info);
return new Result(resultList, resultList.size(), false, false);
}
use of org.structr.core.property.GenericProperty in project structr by structr.
the class LogResource method wrap.
private List<GraphObjectMap> wrap(final List<Map<String, Object>> entries) {
final List<GraphObjectMap> result = new LinkedList<>();
for (final Map<String, Object> entry : entries) {
final GraphObjectMap map = new GraphObjectMap();
for (final Entry<String, Object> e : entry.entrySet()) {
final String key = e.getKey();
if (timestampProperty.jsonName().equals(key)) {
map.put(timestampProperty, new Date((Long) e.getValue()));
} else {
map.put(new GenericProperty(key), e.getValue());
}
}
result.add(map);
}
return result;
}
use of org.structr.core.property.GenericProperty in project structr by structr.
the class FulltextIndexerModule method getContextObject.
@Override
public GraphObjectMap getContextObject(final String searchTerm, final String text, final int contextLength) {
final GraphObjectMap contextObject = new GraphObjectMap();
final Set<String> contextValues = new LinkedHashSet<>();
final String[] searchParts = searchTerm.split("[\\s,;]+");
final GenericProperty contextKey = new GenericProperty("context");
for (final String searchString : searchParts) {
final String lowerCaseSearchString = searchString.toLowerCase();
final String lowerCaseText = text.toLowerCase();
final StringBuilder wordBuffer = new StringBuilder();
final StringBuilder lineBuffer = new StringBuilder();
final int textLength = text.length();
/*
* we take an average word length of 8 characters, multiply
* it by the desired prefix and suffix word count, add 20%
* and try to extract up to prefixLength words.
*/
// modify these parameters to tune prefix and suffix word extraction
// loop variables
int newlineCount = 0;
// wordCount starts at 1 because we include the matching word
int wordCount = 0;
int pos = -1;
do {
// find next occurrence
pos = lowerCaseText.indexOf(lowerCaseSearchString, pos + 1);
if (pos > 0) {
lineBuffer.setLength(0);
wordBuffer.setLength(0);
wordCount = 0;
newlineCount = 0;
// fetch context words before search hit
for (int i = pos; i >= 0; i--) {
final char c = text.charAt(i);
if (!Character.isAlphabetic(c) && !Character.isDigit(c) && !FulltextTokenizer.SpecialChars.contains(c)) {
wordCount += flushWordBuffer(lineBuffer, wordBuffer, true);
// store character in buffer
wordBuffer.insert(0, c);
if (c == '\n') {
// increase newline count
newlineCount++;
} else {
// reset newline count
newlineCount = 0;
}
// paragraph boundary reached
if (newlineCount > 1) {
break;
}
// stop if we collected half of the desired word count
if (wordCount > contextLength / 2) {
break;
}
} else {
// store character in buffer
wordBuffer.insert(0, c);
// reset newline count
newlineCount = 0;
}
}
wordCount += flushWordBuffer(lineBuffer, wordBuffer, true);
wordBuffer.setLength(0);
// fetch context words after search hit
for (int i = pos + 1; i < textLength; i++) {
final char c = text.charAt(i);
if (!Character.isAlphabetic(c) && !Character.isDigit(c) && !FulltextTokenizer.SpecialChars.contains(c)) {
wordCount += flushWordBuffer(lineBuffer, wordBuffer, false);
// store character in buffer
wordBuffer.append(c);
if (c == '\n') {
// increase newline count
newlineCount++;
} else {
// reset newline count
newlineCount = 0;
}
// paragraph boundary reached
if (newlineCount > 1) {
break;
}
// stop if we collected enough words
if (wordCount > contextLength) {
break;
}
} else {
// store character in buffer
wordBuffer.append(c);
// reset newline count
newlineCount = 0;
}
}
wordCount += flushWordBuffer(lineBuffer, wordBuffer, false);
// replace single newlines with space
contextValues.add(lineBuffer.toString().trim());
}
} while (pos >= 0);
}
contextObject.put(contextKey, contextValues);
return contextObject;
}
use of org.structr.core.property.GenericProperty in project structr by structr.
the class CypherQueryCommand method execute.
public List<GraphObject> execute(String query, Map<String, Object> parameters, boolean includeHiddenAndDeleted, boolean publicOnly) throws FrameworkException {
DatabaseService graphDb = (DatabaseService) arguments.get("graphDb");
RelationshipFactory relFactory = new RelationshipFactory(securityContext);
NodeFactory nodeFactory = new NodeFactory(securityContext);
List<GraphObject> resultList = new LinkedList<>();
// graphdb can be null..
if (graphDb != null) {
try (final NativeResult result = graphDb.execute(query, parameters != null ? parameters : Collections.emptyMap())) {
while (result.hasNext()) {
final Map<String, Object> row = result.next();
for (Entry<String, Object> entry : row.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
final Object obj = handleObject(nodeFactory, relFactory, key, value, includeHiddenAndDeleted, publicOnly, 0);
if (obj != null) {
if (obj instanceof GraphObject) {
resultList.add((GraphObject) obj);
} else if (obj instanceof Collection) {
final List<Object> nonGraphObjectResult = new LinkedList<>();
for (final Object item : ((Collection) obj)) {
if (item instanceof GraphObject) {
resultList.add((GraphObject) item);
} else {
nonGraphObjectResult.add(item);
}
}
if (!nonGraphObjectResult.isEmpty()) {
// Wrap non-graph-objects in simple list
final GraphObjectMap graphObject = new GraphObjectMap();
graphObject.setProperty(new GenericProperty(key), nonGraphObjectResult);
resultList.add(graphObject);
}
} else {
logger.warn("Unable to handle Cypher query result object of type {}, ignoring.", obj.getClass().getName());
}
}
}
}
}
}
return resultList;
}
Aggregations