Skip to content

Commit

Permalink
added data source support
Browse files Browse the repository at this point in the history
  • Loading branch information
dprzybyl committed Oct 2, 2023
1 parent d64f086 commit 8252e8a
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@
*/
package com.cognifide.apm.core.grammar.datasource;

import com.cognifide.apm.core.grammar.*;
import com.cognifide.apm.core.grammar.ApmEmpty;
import com.cognifide.apm.core.grammar.ApmList;
import com.cognifide.apm.core.grammar.ApmMap;
import com.cognifide.apm.core.grammar.ApmString;
import com.cognifide.apm.core.grammar.ApmType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Component
public class ContentDataSource implements DataSource {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
package com.cognifide.apm.core.grammar.datasource;

import com.cognifide.apm.core.grammar.ApmType;
import org.apache.sling.api.resource.ResourceResolver;

import java.util.List;
import org.apache.sling.api.resource.ResourceResolver;

public interface DataSource {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
package com.cognifide.apm.core.grammar.datasource;

import com.cognifide.apm.core.grammar.ApmType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component(service = DataSourceInvoker.class)
public class DataSourceInvoker {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.cognifide.apm.core.grammar.datasource;

import com.cognifide.apm.core.grammar.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;

import com.cognifide.apm.core.grammar.ApmList;
import com.cognifide.apm.core.grammar.ApmString;
import com.cognifide.apm.core.grammar.ApmType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;

@Component
public class GroupsDataSource implements DataSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@

import com.cognifide.apm.core.grammar.ApmString;
import com.cognifide.apm.core.grammar.ApmType;
import java.util.List;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;

import java.util.List;

@Component
public class LowerDataSource implements DataSource {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@
import com.cognifide.apm.core.grammar.ApmMap;
import com.cognifide.apm.core.grammar.ApmString;
import com.cognifide.apm.core.grammar.ApmType;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;

@Component
public class NodesDataSource implements DataSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@

import com.cognifide.apm.core.grammar.ApmString;
import com.cognifide.apm.core.grammar.ApmType;
import java.util.List;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;

import java.util.List;

@Component
public class UpperDataSource implements DataSource {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@
*/
package com.cognifide.apm.core.grammar.datasource;

import com.cognifide.apm.core.grammar.*;
import com.cognifide.apm.core.grammar.ApmInteger;
import com.cognifide.apm.core.grammar.ApmList;
import com.cognifide.apm.core.grammar.ApmMap;
import com.cognifide.apm.core.grammar.ApmString;
import com.cognifide.apm.core.grammar.ApmType;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.osgi.service.component.annotations.Component;

import java.io.InputStream;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

@Component
public class ValueMapDataSource implements DataSource {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public List<String> getMessages() {
@Override
public List<String> getPrettyMessages() {
return messages.stream()
.map(message -> message.replaceAll("\n", "<br>").replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;"))
.map(message -> message.replaceAll("\n", "<br>").replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;"))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ data class ApmList(val value: List<ApmType>) : ApmType() {
}

override fun prettyPrint(depth: Int, prefixDepth: Int): String {
return if (value.all { it is ApmString || it is ApmInteger }) {
return if (value.isEmpty() || value.all { it is ApmString || it is ApmInteger }) {
value.joinToString(
prefix = "\t".repeat(prefixDepth) + "[",
postfix = "]"
Expand All @@ -109,9 +109,9 @@ data class ApmMap(val value: Map<String, ApmType>) : ApmType() {
}

override fun prettyPrint(depth: Int, prefixDepth: Int): String {
return if (value.size == 1
return if (value.isEmpty() || value.size == 1
&& (value.values.all { it is ApmString || it is ApmInteger }
|| value.values.filterIsInstance<ApmList>().first().value.all { it is ApmString || it is ApmInteger })
|| value.values.first { it is ApmList }.list!!.all { it is ApmString || it is ApmInteger })
) {
value.entries.joinToString(
prefix = "\t".repeat(prefixDepth) + "{",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,30 @@

package com.cognifide.apm.core.grammar.argument

import com.cognifide.apm.core.grammar.*
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.*
import com.cognifide.apm.core.grammar.ApmEmpty
import com.cognifide.apm.core.grammar.ApmInteger
import com.cognifide.apm.core.grammar.ApmList
import com.cognifide.apm.core.grammar.ApmMap
import com.cognifide.apm.core.grammar.ApmPair
import com.cognifide.apm.core.grammar.ApmString
import com.cognifide.apm.core.grammar.ApmType
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.ArgumentContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.ArrayContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.ComplexArgumentsContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.DataSourceContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.ExpressionContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.FlagContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.NameContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.NamedArgumentContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.NamedArgumentsContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.NumberValueContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.PathContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.PrivilegeNameContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.RequiredArgumentContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.StringValueContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.StructureContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.StructureEntryContext
import com.cognifide.apm.core.grammar.antlr.ApmLangParser.VariableContext
import com.cognifide.apm.core.grammar.common.getIdentifier
import com.cognifide.apm.core.grammar.common.getKey
import com.cognifide.apm.core.grammar.common.getPath
Expand Down

0 comments on commit 8252e8a

Please sign in to comment.