Skip to content

Commit

Permalink
https://github.com/metadatacenter/cedar-project/issues/1198
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila L. Egyedi committed Nov 8, 2023
1 parent 115aba9 commit 5f9444e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.metadatacenter.model.request.NodeListQueryType;
import org.metadatacenter.model.request.NodeListRequest;
import org.metadatacenter.model.response.FolderServerNodeListResponse;
import org.metadatacenter.proxy.ArtifactProxy;
import org.metadatacenter.rest.assertion.noun.CedarInPlaceParameter;
import org.metadatacenter.rest.assertion.noun.CedarParameter;
import org.metadatacenter.rest.context.CedarRequestContext;
Expand Down Expand Up @@ -285,22 +286,7 @@ protected Response generateStatusResponse(HttpResponse proxyResponse) throws Ced
}

protected Response executeResourceGetByProxyFromArtifactServer(CedarResourceType resourceType, String id, CedarRequestContext context) throws CedarProcessingException {
return executeResourceGetByProxyFromArtifactServer(resourceType, id, Optional.empty(), context);
}

protected Response executeResourceGetByProxyFromArtifactServer(CedarResourceType resourceType, String id, Optional<String> format, CedarRequestContext context) throws CedarProcessingException {
try {
String url = microserviceUrlUtil.getArtifact().getArtifactTypeWithId(resourceType, id, format);
// parameter
HttpResponse proxyResponse = ProxyUtil.proxyGet(url, context);
ProxyUtil.proxyResponseHeaders(proxyResponse, response);
HttpEntity entity = proxyResponse.getEntity();
int statusCode = proxyResponse.getStatusLine().getStatusCode();
String mediaType = entity.getContentType().getValue();
return Response.status(statusCode).type(mediaType).entity(entity.getContent()).build();
} catch (Exception e) {
throw new CedarProcessingException(e);
}
return ArtifactProxy.executeResourceGetByProxyFromArtifactServer(microserviceUrlUtil, response, resourceType, id, Optional.empty(), context);
}

protected String getSchemaArtifactFromArtifactServer(CedarResourceType resourceType, CedarSchemaArtifactId id, CedarRequestContext context) throws CedarProcessingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public Response getAllCategories(@QueryParam(QP_LIMIT) Optional<Integer> limitPa
.offset(offsetParam);
pagedQuery.validate();

Integer limit = pagedQuery.getLimit();
Integer offset = pagedQuery.getOffset();
int limit = pagedQuery.getLimit();
int offset = pagedQuery.getOffset();

CategoryServiceSession categorySession = CedarDataServices.getCategoryServiceSession(c);
List<FolderServerCategory> categories = categorySession.getAllCategories(limit, offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
import org.metadatacenter.rest.assertion.noun.CedarRequestBody;
import org.metadatacenter.rest.context.CedarRequestContext;
import org.metadatacenter.rest.context.CedarRequestContextFactory;
import org.metadatacenter.server.search.util.GenerateEmptyRulesIndexTask;
import org.metadatacenter.server.search.util.GenerateEmptySearchIndexTask;
import org.metadatacenter.server.search.util.LoadValueSetsOntologyTask;
import org.metadatacenter.server.search.util.RegenerateRulesIndexTask;
import org.metadatacenter.server.search.util.RegenerateSearchIndexTask;
import org.metadatacenter.server.search.util.*;
import org.metadatacenter.server.security.model.auth.CedarPermission;
import org.metadatacenter.server.service.UserService;
import org.metadatacenter.util.http.CedarResponse;
Expand Down Expand Up @@ -65,8 +61,7 @@ public Response loadValueSetsOntology() throws CedarException {
executor.submit(() -> {
LoadValueSetsOntologyTask task = new LoadValueSetsOntologyTask(cedarConfig);
try {
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig,
userService);
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig, userService);

task.loadValueSetsOntology(cedarAdminRequestContext);

Expand Down Expand Up @@ -111,8 +106,7 @@ public Response regenerateSearchIndex() throws CedarException {
// task won't be able to load the CADSR-VS.owl file and will throw a warning.
LoadValueSetsOntologyTask loadOntologyTask = new LoadValueSetsOntologyTask(cedarConfig);
try {
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig,
userService);
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig, userService);
loadOntologyTask.loadValueSetsOntology(cedarAdminRequestContext);
ValueSetsImportStatusManager.getInstance().setImportStatus(ValueSetsImportStatusManager.ImportStatus.COMPLETE);
} catch (CedarProcessingException e) {
Expand All @@ -123,8 +117,7 @@ public Response regenerateSearchIndex() throws CedarException {
// 2. REGENERATE SEARCH INDEX
RegenerateSearchIndexTask regenerateIndexTask = new RegenerateSearchIndexTask(cedarConfig);
try {
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig,
userService);
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig, userService);
regenerateIndexTask.regenerateSearchIndex(force, cedarAdminRequestContext);
} catch (CedarProcessingException e) {
log.error("Error in index regeneration executor", e);
Expand All @@ -146,8 +139,7 @@ public Response generateEmptySearchIndex() throws CedarException {
executor.submit(() -> {
GenerateEmptySearchIndexTask task = new GenerateEmptySearchIndexTask(cedarConfig);
try {
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig,
userService);
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig, userService);
task.generateEmptySearchIndex(cedarAdminRequestContext);
} catch (CedarProcessingException e) {
//TODO: handle this, log it separately
Expand All @@ -173,8 +165,7 @@ public Response regenerateRulesIndex() throws CedarException {
executor.submit(() -> {
RegenerateRulesIndexTask task = new RegenerateRulesIndexTask(cedarConfig);
try {
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig,
userService);
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig, userService);
task.regenerateRulesIndex(force, cedarAdminRequestContext);
} catch (CedarProcessingException e) {
//TODO: handle this, log it separately
Expand All @@ -197,8 +188,7 @@ public Response generateEmptyRulesIndex() throws CedarException {
executor.submit(() -> {
GenerateEmptyRulesIndexTask task = new GenerateEmptyRulesIndexTask(cedarConfig);
try {
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig,
userService);
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig, userService);
task.generateEmptyRulesIndex(cedarAdminRequestContext);
} catch (CedarProcessingException e) {
//TODO: handle this, log it separately
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ public Response publishArtifact() throws CedarException {
folderSession.setLatestVersion(aid);
folderSession.unsetLatestDraftVersion(aid);
folderSession.setLatestPublishedVersion(aid);
if (folderServerResourceOld instanceof FolderServerSchemaArtifactCurrentUserReport) {
FolderServerSchemaArtifactCurrentUserReport schemaArtifact = (FolderServerSchemaArtifactCurrentUserReport) folderServerResourceOld;
if (folderServerResourceOld instanceof FolderServerSchemaArtifactCurrentUserReport schemaArtifact) {
if (schemaArtifact.getPreviousVersion() != null) {
folderSession.unsetLatestPublishedVersion(schemaArtifact.getPreviousVersion());
}
Expand Down Expand Up @@ -304,8 +303,7 @@ public Response createDraftArtifact() throws CedarException {

FolderServerArtifact brandNewResource = GraphDbObjectBuilder.forResourceType(artifactType, newId, sourceResource.getName(),
sourceResource.getDescription(), sourceResource.getIdentifier(), newVersion, status);
if (brandNewResource instanceof FolderServerSchemaArtifact) {
FolderServerSchemaArtifact schemaArtifact = (FolderServerSchemaArtifact) brandNewResource;
if (brandNewResource instanceof FolderServerSchemaArtifact schemaArtifact) {
schemaArtifact.setPreviousVersion(aid);
schemaArtifact.setLatestVersion(true);
schemaArtifact.setLatestDraftVersion(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.metadatacenter.id.CedarFolderId;
import org.metadatacenter.model.CedarResourceType;
import org.metadatacenter.model.folderserver.basic.FolderServerFolder;
import org.metadatacenter.model.folderserver.extract.FolderServerArtifactExtract;
import org.metadatacenter.model.folderserver.extract.FolderServerResourceExtract;
import org.metadatacenter.model.request.NodeListQueryType;
import org.metadatacenter.model.request.NodeListRequest;
Expand All @@ -24,10 +23,7 @@
import org.metadatacenter.server.FolderServiceSession;
import org.metadatacenter.server.ResourcePermissionServiceSession;
import org.metadatacenter.server.cache.user.ProvenanceNameUtil;
import org.metadatacenter.server.security.model.user.ResourcePublicationStatusFilter;
import org.metadatacenter.server.security.model.user.ResourceVersionFilter;
import org.metadatacenter.util.NodeListUtil;
import org.metadatacenter.util.TrustedByUtil;
import org.metadatacenter.util.http.CedarResponse;
import org.metadatacenter.util.http.LinkHeaderUtil;
import org.metadatacenter.util.http.PagedSortedTypedQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.metadatacenter.exception.CedarException;
import org.metadatacenter.id.CedarTemplateInstanceId;
import org.metadatacenter.model.CedarResourceType;
import org.metadatacenter.proxy.ArtifactProxy;
import org.metadatacenter.rest.context.CedarRequestContext;
import org.metadatacenter.server.security.model.auth.CedarPermission;

Expand Down Expand Up @@ -45,7 +46,7 @@ public Response findTemplateInstance(@PathParam(PP_ID) String id, @QueryParam(QP
CedarTemplateInstanceId tiid = CedarTemplateInstanceId.build(id);

userMustHaveReadAccessToArtifact(c, tiid);
return executeResourceGetByProxyFromArtifactServer(CedarResourceType.INSTANCE, id, format, c);
return ArtifactProxy.executeResourceGetByProxyFromArtifactServer(microserviceUrlUtil, response, CedarResourceType.INSTANCE, id, format, c);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ rootLogger.appenderRef.console.ref = console

logger.netty.name = io.netty.util.internal
logger.netty.level = warn

logger.elasticsearch.name = org.elasticsearch.transport
logger.elasticsearch.level = warn

0 comments on commit 5f9444e

Please sign in to comment.