dasch-swiss / beol

Bernoulli-Euler OnLine
https://beol.dasch.swiss
GNU Affero General Public License v3.0
0 stars 1 forks source link

ark URLs are not resolved with angular templates #164

Closed SepidehAlassi closed 4 years ago

SepidehAlassi commented 4 years ago

I have tried accessing a couple of letter resources of BEOL using ARK URLs, but they do not resolve correctly. The application only shows the letters using the general resource template and does not use the angular templates defined for representing each resource type.

Try: ARK URL: http://ark.dasch.swiss/ark:/72163/1/0801/v5mma7PzTcOD8ZndsBBDVAq

of the resource https://api.dasch.swiss/v2/resources/http:%2F%2Frdfh.ch%2F0801%2Fv5mma7PzTcOD8ZndsBBDVA

Since the general resource template dumps all properties of a resource without any styling, the result looks horrible. It is particularly problematic when it comes to newton:letter and leibniz:letter resources, because the text of the letters is fetched and displayed using the components defined for these resource types.

benjamingeer commented 4 years ago

The DaSCH ARK resolver is currently configured to redirect BEOL ARK URLs using this URL template:

https://github.com/dasch-swiss/ark-resolver-data/blob/master/data/dasch_ark_registry.ini#L124

You can change it to anything you like.

SepidehAlassi commented 4 years ago

@benjamingeer it is not actually as easy as changing it from resource to letter. Based on the type of resource, the BEOL application activates a routing service to load the resource with its specified angular component. https://github.com/dhlab-basel/beol/blob/5c9dea3c5d1e2c95fb55ad18c7935df88ea298e4/src/app/services/beol.service.ts#L674

@kilchenmann what is the easy way to do this?

kilchenmann commented 4 years ago

At the moment I have no idea. But good question! The app knows about the resource class and handles it correctly. I will think about it. Probably @flavens has a good idea...

SepidehAlassi commented 4 years ago

@kilchenmann @flavens I think we would need a new component, like beolARkResolve. It should get resource IRI from ark resolver as a parameter, then should get the type of the resource and routes it to the correct component. what do you think?

kilchenmann commented 4 years ago

@SepidehAlassi this could work...yes

benjamingeer commented 4 years ago

Shouldn't it be a generic component? This will probably be a common use case in other projects, too.

SepidehAlassi commented 4 years ago

@benjamingeer yes, the new component I am suggesting should be generic. It should then route to the respective components based on the resource type. The ark resolver is currently passing the resource_iri as a parameter, can it also pass the resource type? Something like this: KnoraResourceRedirectUrl: http://$host/resource/$resource_iri$resource_type

benjamingeer commented 4 years ago

The ark resolver is currently passing the resource_iri as a parameter, can it also pass the resource type?

It can't, because it doesn't have it. The resource class is not in the ARK URL.

SepidehAlassi commented 4 years ago

@benjamingeer ok, then the generic component should get the resource type from knora API, using its IRI.

benjamingeer commented 4 years ago

then the generic component should get the resource type from knora API, using its IRI.

When you get the resource from the API, you also get its class. I suggest getting the resource first, then deciding how to display it based on its class.

flavens commented 4 years ago

@SepidehAlassi I agree with the idea of a generic component, in the future it could also be implemented in the knora-api lib

SepidehAlassi commented 4 years ago

@flavens yes, the problem is I have a deadline for submitting an article with the ARK URL citations. I need this generic component as fast as possible. I can develop it myself now for BEOL, I will appreciate your support.

kilchenmann commented 4 years ago

I don't think it's generic. The letter view — as used in BEOL — is project specific. The generic view is the one you get now with the ark url.

benjamingeer commented 4 years ago

I don't think it's generic. The letter view — as used in BEOL — is project specific.

But every project will need to map resource classes onto project-specific Angular templates when processing requests from the ARK resolver. It would be nice if each project could just supply a mapping ("use this template with this resource class"). A generic component could do the rest.

SepidehAlassi commented 4 years ago

@kilchenmann The new component will be generic in the sense that it gets resource iri from the ark resolver, gets the resource class and passes the iri and type to routeByResourceType https://github.com/dhlab-basel/beol/blob/5c9dea3c5d1e2c95fb55ad18c7935df88ea298e4/src/app/services/beol.service.ts#L674 if there is a specific component defined for the resource type it will use that. For example if the resource is a letter, it will use the letter template to display it. Otherwise, if a resource does not have a specific component, it will be displayed with the "resource" template.

SepidehAlassi commented 4 years ago

@benjamingeer @kilchenmann Basically the new component I am suggesting will do this mapping that Ben just mentioned.

gfoo commented 4 years ago

in Lumières.Lausanne I have my own route/component (which is not generic):

  1. you have to have a route of the ark server redirection (in my case resources/:iri): { path: 'resources/:iri', component: ResourcesComponent },

  2. then I get the resource's type in the ResourcesComponent (Knora could provide an enpoint to not use possible consuming v2/resources call) and then I route to my dedicated routes (i.e if Type Biography then 'resources/:iri' -> 'fiche/bio/:iri' and so on)

A generic component should accept as config a map describing for a type the corresponding route.

gfoo commented 4 years ago

@SepidehAlassi A quick and dirty way, no error checking, hard coded route/class names etc. You have just to adapt the code to your dedicated knora service ;-)

Routing:

  { path: 'resources/:iri', component: ResourceRouterComponent },

Generic compo:

@Component({
  template: ''
})
export class ResourceRouterComponent implements OnInit {
  constructor(
    private router: Router,
    private route: ActivatedRoute,
    private knoraService: KnoraV2Service
  ) {}

  ngOnInit() {
    this.route.paramMap.subscribe(params => {
      console.log(params);
      if (params.has('iri')) {
        const iri = decodeURIComponent(params.get('iri'));
        console.log(iri);
        const routeMapping = new Map<string, string>();
        routeMapping.set('Person', '/fiches/bio/');
        routeMapping.set('BibliographicNotice', '/fiches/biblio/');

        this.knoraService.getResource(iri).subscribe((res: KResource) => {
          console.log(res);
          const routeKey = res
            ? Array.from(routeMapping.keys()).find(k => res.type.endsWith(k))
            : null;
          console.log(routeKey);

          if (routeKey) {
            this.router.navigate([
              routeMapping.get(routeKey),
              encodeURIComponent(iri)
            ]);
          }
        });
      }
    });
  }
}
SepidehAlassi commented 4 years ago

@flavens @kilchenmann I have created a pull request that does the trick. I have changed the resource template to act as a mapping component and the previous template used to show all properties is now simpleResource. Can you please review it? https://github.com/dhlab-basel/beol/pull/165

@benjamingeer in this way you, there is no need to change the ark resolver config, as the resource component acts as a mapper now.

SepidehAlassi commented 4 years ago

@gfoo thank you for comments. We already had a router for different resource types in BEOL, I just needed to create a simple mapping component.