Skip to content

Commit

Permalink
fix file licenses and apply spotless (#79)
Browse files Browse the repository at this point in the history
* add license to missing files, remove double licenses after package import

* apply spotless
  • Loading branch information
elliVM authored Sep 5, 2024
1 parent 7959e79 commit 07acaa6
Show file tree
Hide file tree
Showing 31 changed files with 539 additions and 802 deletions.
64 changes: 55 additions & 9 deletions src/main/java/com/teragrep/pth_06/config/ConditionConfig.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
/*
* Teragrep Archive Datasource (pth_06)
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
* Additional permission under GNU Affero General Public License version 3
* section 7
*
* If you modify this Program, or any covered work, by linking or combining it
* with other code, such other code is not for that reason alone subject to any
* of the requirements of the GNU Affero GPL version 3 as long as this Program
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
* modifications.
*
* Supplemented terms under GNU Affero General Public License version 3
* section 7
*
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
* versions must be marked as "Modified version of" The Program.
*
* Names of the licensors and authors may not be used for publicity purposes.
*
* No rights are granted for use of trade names, trademarks, or service marks
* which are in The Program if any.
*
* Licensee must indemnify licensors and authors for any liability that these
* contractual assumptions impose on licensors and authors.
*
* To the extent this program is licensed as part of the Commercial versions of
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/
package com.teragrep.pth_06.config;

import com.teragrep.pth_06.planner.walker.conditions.ElementCondition;
import org.jooq.DSLContext;

public final class ConditionConfig {

private final DSLContext ctx;
private final boolean streamQuery;
private final boolean bloomEnabled;
Expand Down Expand Up @@ -41,13 +86,14 @@ public boolean withoutFilter() {

@Override
public boolean equals(Object object) {
if (this == object) return true;
if (object == null) return false;
if (object.getClass() != this.getClass()) return false;
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
return false;
final ConditionConfig cast = (ConditionConfig) object;
return this.bloomEnabled == cast.bloomEnabled &&
this.streamQuery == cast.streamQuery &&
this.withoutFilters == cast.withoutFilters &&
this.ctx == cast.ctx;
return this.bloomEnabled == cast.bloomEnabled && this.streamQuery == cast.streamQuery
&& this.withoutFilters == cast.withoutFilters && this.ctx == cast.ctx;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ public Condition emitUnaryOperation(String op, Element current) throws Exception
}

Condition emitElem(Element current) {
ElementCondition elementCondition = new ElementCondition(current,
new ConditionConfig(ctx, streamQuery, bloomEnabled, false));
ElementCondition elementCondition = new ElementCondition(
current,
new ConditionConfig(ctx, streamQuery, bloomEnabled, false)
);
return elementCondition.condition();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This program handles user requests that require archive access.
* Copyright (C) 2024 Suomen Kanuuna Oy
* Teragrep Archive Datasource (pth_06)
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand All @@ -13,7 +13,7 @@
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
* Additional permission under GNU Affero General Public License version 3
Expand Down Expand Up @@ -43,7 +43,6 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.pth_06.planner.walker.conditions;

import org.jooq.Condition;
Expand All @@ -54,6 +53,7 @@
import static com.teragrep.pth_06.jooq.generated.journaldb.Journaldb.JOURNALDB;

public final class EarliestCondition implements QueryCondition {

private final String value;

public EarliestCondition(String value) {
Expand All @@ -69,8 +69,11 @@ public Condition condition() {
final java.sql.Date timeQualifier = new Date(instant.toEpochMilli());
Condition condition;
condition = JOURNALDB.LOGFILE.LOGDATE.greaterOrEqual(timeQualifier);
condition = condition.and("UNIX_TIMESTAMP(STR_TO_DATE(SUBSTRING(REGEXP_SUBSTR(path,'[0-9]+(\\.log)?\\.gz(\\.[0-9]*)?$'), 1, 10), '%Y%m%d%H'))" +
" >= " + instant.getEpochSecond());
condition = condition
.and(
"UNIX_TIMESTAMP(STR_TO_DATE(SUBSTRING(REGEXP_SUBSTR(path,'[0-9]+(\\.log)?\\.gz(\\.[0-9]*)?$'), 1, 10), '%Y%m%d%H'))"
+ " >= " + instant.getEpochSecond()
);
// raw SQL used here since following not supported for mariadb:
// queryCondition = queryCondition.and(toTimestamp(
// regexpReplaceAll(JOURNALDB.LOGFILE.PATH, "((^.*\\/.*-)|(\\.log\\.gz.*))", ""),
Expand All @@ -84,9 +87,12 @@ public Condition condition() {

@Override
public boolean equals(final Object object) {
if (this == object) return true;
if (object == null) return false;
if (object.getClass() != this.getClass()) return false;
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
return false;
final EarliestCondition cast = (EarliestCondition) object;
return this.value.equals(cast.value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This program handles user requests that require archive access.
* Copyright (C) 2024 Suomen Kanuuna Oy
* Teragrep Archive Datasource (pth_06)
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand All @@ -13,7 +13,7 @@
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
* Additional permission under GNU Affero General Public License version 3
Expand Down Expand Up @@ -43,7 +43,6 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.pth_06.planner.walker.conditions;

import com.teragrep.blf_01.Tokenizer;
Expand All @@ -58,6 +57,7 @@
* Creates a query condition from provided dom element
*/
public final class ElementCondition {

private static final Logger LOGGER = LoggerFactory.getLogger(ElementCondition.class);

private final Element element;
Expand All @@ -73,10 +73,14 @@ private void validate(Element element) {
throw new IllegalStateException("Tag name for Element was null");
}
if (!element.hasAttribute("operation")) {
throw new IllegalStateException("Could not find specified or default value for 'operation' attribute from Element");
throw new IllegalStateException(
"Could not find specified or default value for 'operation' attribute from Element"
);
}
if (!element.hasAttribute("value")) {
throw new IllegalStateException("Could not find specified or default value for 'value' attribute from Element");
throw new IllegalStateException(
"Could not find specified or default value for 'value' attribute from Element"
);
}
}

Expand Down Expand Up @@ -112,8 +116,11 @@ public Condition condition() {
}
// value search
if ("indexstatement".equalsIgnoreCase(tag) && "EQUALS".equals(operation) && config.bloomEnabled()) {
IndexStatementCondition indexStatementCondition =
new IndexStatementCondition(value, config, new Tokenizer(32));
IndexStatementCondition indexStatementCondition = new IndexStatementCondition(
value,
config,
new Tokenizer(32)
);
condition = indexStatementCondition.condition();
}
}
Expand All @@ -126,9 +133,12 @@ public Condition condition() {

@Override
public boolean equals(final Object object) {
if (this == object) return true;
if (object == null) return false;
if (object.getClass() != this.getClass()) return false;
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
return false;
final ElementCondition cast = (ElementCondition) object;
boolean equalName = this.element.getTagName().equals(cast.element.getTagName());
boolean equalOperation = this.element.getAttribute("operation").equals(cast.element.getAttribute("operation"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This program handles user requests that require archive access.
* Copyright (C) 2024 Suomen Kanuuna Oy
* Teragrep Archive Datasource (pth_06)
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand All @@ -13,7 +13,7 @@
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
* Additional permission under GNU Affero General Public License version 3
Expand Down Expand Up @@ -43,7 +43,6 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.pth_06.planner.walker.conditions;

import com.teragrep.pth_06.planner.StreamDBClient;
Expand All @@ -52,6 +51,7 @@
import static com.teragrep.pth_06.jooq.generated.streamdb.Streamdb.STREAMDB;

public final class HostCondition implements QueryCondition {

private final String value;
private final String operation;
private final boolean streamQuery;
Expand All @@ -65,14 +65,10 @@ public HostCondition(String value, String operation, boolean streamQuery) {
public Condition condition() {
Condition condition;
if (streamQuery) {
condition = STREAMDB.HOST.NAME.like(
value.replace('*', '%')
);
} else {
condition =
StreamDBClient.GetArchivedObjectsFilterTable.host.like(
value.replace('*', '%').toLowerCase()
);
condition = STREAMDB.HOST.NAME.like(value.replace('*', '%'));
}
else {
condition = StreamDBClient.GetArchivedObjectsFilterTable.host.like(value.replace('*', '%').toLowerCase());
}
if (operation.equalsIgnoreCase("NOT_EQUALS")) {
condition = condition.not();
Expand All @@ -82,12 +78,14 @@ public Condition condition() {

@Override
public boolean equals(final Object object) {
if (this == object) return true;
if (object == null) return false;
if (object.getClass() != this.getClass()) return false;
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
return false;
final HostCondition cast = (HostCondition) object;
return this.streamQuery == cast.streamQuery &&
this.value.equals(cast.value) &&
this.operation.equals(cast.operation);
return this.streamQuery == cast.streamQuery && this.value.equals(cast.value)
&& this.operation.equals(cast.operation);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This program handles user requests that require archive access.
* Copyright (C) 2024 Suomen Kanuuna Oy
* Teragrep Archive Datasource (pth_06)
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand All @@ -13,7 +13,7 @@
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
* Additional permission under GNU Affero General Public License version 3
Expand Down Expand Up @@ -43,7 +43,6 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.pth_06.planner.walker.conditions;

import com.teragrep.pth_06.planner.StreamDBClient;
Expand All @@ -52,6 +51,7 @@
import static com.teragrep.pth_06.jooq.generated.streamdb.Streamdb.STREAMDB;

public final class IndexCondition implements QueryCondition {

private final String value;
private final String operation;
private final boolean streamQuery;
Expand All @@ -65,15 +65,11 @@ public IndexCondition(String value, String operation, boolean streamQuery) {
public Condition condition() {
Condition condition;
if (streamQuery) {
condition =
STREAMDB.STREAM.DIRECTORY.like(
value.replace('*', '%')
);
} else {
condition =
StreamDBClient.GetArchivedObjectsFilterTable.directory.like(
value.replace('*', '%').toLowerCase()
);
condition = STREAMDB.STREAM.DIRECTORY.like(value.replace('*', '%'));
}
else {
condition = StreamDBClient.GetArchivedObjectsFilterTable.directory
.like(value.replace('*', '%').toLowerCase());
}
if (operation.equalsIgnoreCase("NOT_EQUALS")) {
condition = condition.not();
Expand All @@ -83,12 +79,14 @@ public Condition condition() {

@Override
public boolean equals(final Object object) {
if (this == object) return true;
if (object == null) return false;
if (object.getClass() != this.getClass()) return false;
if (this == object)
return true;
if (object == null)
return false;
if (object.getClass() != this.getClass())
return false;
final IndexCondition cast = (IndexCondition) object;
return this.streamQuery == cast.streamQuery &&
this.value.equals(cast.value) &&
this.operation.equals(cast.operation);
return this.streamQuery == cast.streamQuery && this.value.equals(cast.value)
&& this.operation.equals(cast.operation);
}
}
Loading

0 comments on commit 07acaa6

Please sign in to comment.