Skip to content

Commit

Permalink
add exposure information to repositiory meta model #517
Browse files Browse the repository at this point in the history
accordingly presentation model will only show exposed repositories
  • Loading branch information
remmeier committed Jun 13, 2019
1 parent 613b9f0 commit a2ce744
Show file tree
Hide file tree
Showing 6 changed files with 642 additions and 617 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package io.crnk.meta.internal.resource;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Callable;

import io.crnk.core.engine.information.repository.RepositoryAction;
import io.crnk.core.engine.information.repository.ResourceRepositoryInformation;
import io.crnk.core.engine.information.resource.ResourceField;
Expand Down Expand Up @@ -30,14 +38,6 @@
import io.crnk.meta.model.resource.MetaResourceRepository;
import io.crnk.meta.provider.MetaPartitionContext;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Callable;

public class ResourceMetaParitition extends TypedMetaPartitionBase {


Expand Down Expand Up @@ -88,7 +88,8 @@ private String computeId(MetaType element) {
String id = getId(entry.getResourceInformation().getResourceType());
if (isMeta) {
return id + "$meta";
} else {
}
else {
return id + "$links";
}
}
Expand Down Expand Up @@ -142,9 +143,11 @@ public void discoverElements() {
ResourceRepositoryInformation repositoryInformation = entry.getRepositoryInformation();
ResourceRepositoryAdapter resourceRepository = entry.getResourceRepository();
if (repositoryInformation != null) {
MetaResourceRepository repository = discoverRepository(repositoryInformation, metaResource,
MetaResourceRepository metaRepository = discoverRepository(repositoryInformation, metaResource,
resourceRepository);
context.addElement(repository);
context.addElement(metaRepository);

metaResource.setRepository(metaRepository);
}
}
}
Expand Down Expand Up @@ -214,7 +217,8 @@ protected String getId(String resourceType) {
RegistryEntry entry = resourceRegistry.getEntry(resourceType);
if (idPrefix != null) {
return idPrefix + resourceType.replace('/', '.');
} else {
}
else {
Class<?> resourceClass = entry.getResourceInformation().getResourceClass();
return resourceClass.getName();
}
Expand All @@ -226,18 +230,20 @@ private String getName(ResourceInformation information) {
for (int i = 0; i < resourceType.length(); i++) {
if (i == 0 || resourceType.charAt(i - 1) == '/') {
name.append(Character.toUpperCase(resourceType.charAt(i)));
} else if (resourceType.charAt(i) != '/') {
}
else if (resourceType.charAt(i) != '/') {
name.append(resourceType.charAt(i));
}
}
return name.toString();
}

private MetaResourceRepository discoverRepository(ResourceRepositoryInformation repositoryInformation,
MetaResource metaResource, ResourceRepositoryAdapter resourceRepository) {
MetaResource metaResource, ResourceRepositoryAdapter resourceRepository) {

MetaResourceRepository meta = new MetaResourceRepository();
meta.setResourceType(metaResource);
meta.setExposed(repositoryInformation.isExposed());
meta.setName(metaResource.getName() + "$repository");
meta.setId(metaResource.getId() + "$repository");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.crnk.meta.model.resource;

import io.crnk.core.resource.annotations.JsonApiRelation;
import io.crnk.core.resource.annotations.JsonApiResource;

/**
Expand All @@ -8,23 +9,34 @@
@JsonApiResource(type = "meta/resource")
public class MetaResource extends MetaResourceBase { // NOSONAR ignore exception hierarchy

private String resourceType;
private String resourceType;

private String resourcePath;
private String resourcePath;

public String getResourceType() {
return resourceType;
}
@JsonApiRelation
private MetaResourceRepository repository;

public void setResourceType(String resourceType) {
this.resourceType = resourceType;
}
public String getResourceType() {
return resourceType;
}

public String getResourcePath() {
return resourcePath;
}
public void setResourceType(String resourceType) {
this.resourceType = resourceType;
}

public void setResourcePath(String resourcePath) {
this.resourcePath = resourcePath;
}
public String getResourcePath() {
return resourcePath;
}

public void setResourcePath(String resourcePath) {
this.resourcePath = resourcePath;
}

public MetaResourceRepository getRepository() {
return repository;
}

public void setRepository(MetaResourceRepository repository) {
this.repository = repository;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ public class MetaResourceRepository extends MetaElement {
@JsonApiRelation(serialize = SerializeType.LAZY)
private MetaDataObject listLinksType;

private boolean exposed;

public boolean isExposed() {
return exposed;
}

public void setExposed(boolean exposed) {
this.exposed = exposed;
}

public MetaResource getResourceType() {
return resourceType;
}
Expand Down
Loading

0 comments on commit a2ce744

Please sign in to comment.