Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#38 evict implementation #39

Merged
merged 2 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/v0.6.0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
* Create formatDate which handles date format
* Create formatTime which handles time format
* Add IT test for owned helpers
* GET `/system/evict` REST endpoint added
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
*/
package hu.icellmobilsoft.dookug.api.url;

import hu.icellmobilsoft.coffee.dto.url.BaseServicePath;

/**
* Document generation service REST url path storage
*
* @author laszlo.padar
* @since 0.1.0
*/
public class DocumentGeneratePath extends BaseServicePath implements IServicePath {
public class DocumentGeneratePath extends ServicePath implements IServicePath {

/**
* {@value #DOCUMENT}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*-
* #%L
* DookuG
* %%
* Copyright (C) 2023 - 2024 i-Cell Mobilsoft Zrt.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package hu.icellmobilsoft.dookug.api.url;

import hu.icellmobilsoft.coffee.dto.url.BaseServicePath;

/**
* Project specific rest services path container
*
* @author tamas.cserhati
* @since 0.6.0
*/
public class ServicePath extends BaseServicePath {

/**
* {@value #TEST}
*/
public static final String TEST = "/test";

/**
* {@value #EVICT}
*/
public static final String EVICT = "/evict";

/**
* {@value #SYSTEM_EVICT}
*/
public static final String SYSTEM_EVICT = SYSTEM + EVICT;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*-
* #%L
* DookuG
* %%
* Copyright (C) 2023 - 2024 i-Cell Mobilsoft Zrt.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package hu.icellmobilsoft.dookug.common.system.rest.cache;

import java.util.ArrayList;
import java.util.List;

import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Model;
import javax.inject.Inject;

import org.apache.deltaspike.core.util.ProxyUtils;

import hu.icellmobilsoft.coffee.configuration.ApplicationConfiguration;
import hu.icellmobilsoft.coffee.tool.utils.date.DateUtil;
import hu.icellmobilsoft.dookug.common.core.evictable.Evictable;
import hu.icellmobilsoft.dookug.common.system.rest.action.BaseAction;
import hu.icellmobilsoft.dookug.schemas.common._1_0.config.evict.EvictResponse;

/**
* {@link Evictable} szolgáltatások igény szerint törölhetik az állapotaikat Az action iterál végig ezeken a szolgáltatásokon
*
* @author tamas.cserhati
* @since 0.6.0
*/
@Model
public class EvictAction extends BaseAction {

@Inject
private ApplicationConfiguration applicationConfiguration;

@Any
@Inject
private Instance<Evictable> evictables;

/**
* Evict művelet Az {@link Evictable} interface implementációkon iterál végig Az ismert keret szintű szolgáltatásoknál explicit hívja meg az
* ürítés funkcíót
*
* @return {@link EvictResponse} dto, az {@link Evictable}-t implementáló osztályok neveinek listája, az ismert keret szintű szolgáltatások
* neveivel kiegészítve
*/
public EvictResponse evict() {
EvictResponse response = new EvictResponse();
response.setEvictionStart(DateUtil.nowUTC());

List<String> evicted = new ArrayList<>();

applicationConfiguration.clear();
evicted.add(getName(applicationConfiguration));

if (!evictables.isUnsatisfied()) {
evictables.forEach(evictable -> {
evictable.evict();
evicted.add(getName(evictable));
});
}

response.setEvictionEnd(DateUtil.nowUTC());
response.withEvicted(evicted);
handleSuccessResultType(response);
return response;
}

private String getName(Object evictable) {
return ProxyUtils.getUnproxiedClass(evictable.getClass()).getName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import org.eclipse.microprofile.openapi.annotations.Operation;

import hu.icellmobilsoft.coffee.dto.exception.BaseException;
import hu.icellmobilsoft.dookug.api.url.DocumentGeneratePath;
import hu.icellmobilsoft.dookug.api.url.IServicePath;
import hu.icellmobilsoft.dookug.schemas.common._1_0.config.evict.EvictResponse;

/**
* REST endpoint for system service functions.
Expand All @@ -54,4 +56,13 @@ public interface ISystemRest {
@Path(IServicePath.VERSION_INFO)
@Produces(MediaType.TEXT_PLAIN)
public String versionInfo(@Context HttpServletRequest servletRequest) throws BaseException;

@GET
@Operation(summary = "Belső állapotok törlése",
description = "a hu.icellmobilsoft.taxi.common.core.evictable.Evictable interface implementációkon iterál végig. "
+ "Az ismert keret szintű szolgáltatásoknál explicit hívja meg az ürítés funkcíót")
@Path(DocumentGeneratePath.SYSTEM_EVICT)
@Produces(value = { MediaType.TEXT_XML, MediaType.APPLICATION_XML })
EvictResponse getEvict() throws BaseException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import hu.icellmobilsoft.coffee.cdi.logger.AppLogger;
import hu.icellmobilsoft.coffee.cdi.logger.ThisLogger;
import hu.icellmobilsoft.coffee.dto.exception.BaseException;
import hu.icellmobilsoft.dookug.common.system.rest.cache.EvictAction;
import hu.icellmobilsoft.dookug.schemas.common._1_0.config.evict.EvictResponse;

/**
* Default system REST operations
Expand All @@ -44,6 +46,9 @@ public class SystemRest extends BaseRestService implements ISystemRest {
@ThisLogger
private AppLogger log;

@Inject
private EvictAction evictAction;

@Override
public String versionInfo(HttpServletRequest servletRequest) throws BaseException {
try {
Expand All @@ -62,4 +67,9 @@ public String versionInfo(HttpServletRequest servletRequest) throws BaseExceptio
throw baseExceptionWithLogging(e);
}
}

@Override
public EvictResponse getEvict() throws BaseException {
return wrapNoParam(evictAction::evict, "evict");
}
}
Loading