Skip to content

Commit

Permalink
[kbss-cvut/termit-ui#553] Add language to File.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Nov 7, 2024
1 parent 7833816 commit 4d9c4e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
31 changes: 15 additions & 16 deletions src/main/java/cz/cvut/kbss/termit/model/resource/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import cz.cvut.kbss.jopa.model.annotations.FetchType;
import cz.cvut.kbss.jopa.model.annotations.Inferred;
import cz.cvut.kbss.jopa.model.annotations.OWLAnnotationProperty;
import cz.cvut.kbss.jopa.model.annotations.OWLClass;
import cz.cvut.kbss.jopa.model.annotations.OWLObjectProperty;
import cz.cvut.kbss.jopa.model.annotations.Types;
import cz.cvut.kbss.jopa.vocabulary.DC;
import cz.cvut.kbss.jsonld.annotation.JsonLdAttributeOrder;
import cz.cvut.kbss.termit.exception.TermItException;
import cz.cvut.kbss.termit.model.util.SupportsStorage;
import cz.cvut.kbss.termit.service.IdentifierResolver;
import cz.cvut.kbss.termit.util.Vocabulary;

import java.lang.reflect.Field;
import java.util.Objects;
import java.util.Set;

Expand All @@ -43,6 +43,9 @@ public class File extends Resource implements SupportsStorage {
@OWLObjectProperty(iri = Vocabulary.s_p_je_casti_dokumentu, fetch = FetchType.EAGER)
private Document document;

@OWLAnnotationProperty(iri = DC.Terms.LANGUAGE, simpleLiteral = true)
private String language;

@Types
private Set<String> types;

Expand All @@ -54,6 +57,14 @@ public void setDocument(Document document) {
this.document = document;
}

public String getLanguage() {
return language;
}

public void setLanguage(String language) {
this.language = language;
}

public Set<String> getTypes() {
return types;
}
Expand All @@ -73,15 +84,11 @@ public boolean equals(Object o) {
return Objects.equals(getUri(), file.getUri());
}

@Override
public int hashCode() {
return Objects.hash(getUri());
}

@Override
public String toString() {
return "File{" +
super.toString() + (document != null ? "document=<" + document.getUri() + ">" : "") + '}';
super.toString() + (language != null ? "@" + language : "") +
(document != null ? "document=<" + document.getUri() + ">" : "") + '}';
}

/**
Expand Down Expand Up @@ -109,12 +116,4 @@ public String getDirectoryName() {
return IdentifierResolver.normalizeToAscii(labelPart) + '_' + getUri().hashCode();
}
}

public static Field getDocumentField() {
try {
return File.class.getDeclaredField("document");
} catch (NoSuchFieldException e) {
throw new TermItException("Fatal error! Unable to retrieve \"document\" field.", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ void termDescriptorCreatesDescriptorWithExactMatchesContextSetToDefaultToAllowEx
}

@Test
void fileDescriptorContainsAlsoDescriptorForDocument() {
void fileDescriptorContainsAlsoDescriptorForDocument() throws Exception {
final File file = Generator.generateFileWithId("test.html");
final Document doc = Generator.generateDocumentWithId();
doc.addFile(file);
file.setDocument(doc);
doc.setVocabulary(Generator.generateUri());
final Descriptor result = sut.fileDescriptor(doc.getVocabulary());
final FieldSpecification<?, ?> docFieldSpec = mock(FieldSpecification.class);
when(docFieldSpec.getJavaField()).thenReturn(File.getDocumentField());
when(docFieldSpec.getJavaField()).thenReturn(File.class.getDeclaredField("document"));
final Descriptor docDescriptor = result.getAttributeDescriptor(docFieldSpec);
assertNotNull(docDescriptor);
}
Expand Down

0 comments on commit 4d9c4e8

Please sign in to comment.