particip-app / issues

Issues - feature requests, bugs, and questions around the pARTicip App
0 stars 0 forks source link

Material Archive: Deeplink #36

Closed ukeller closed 8 years ago

ukeller commented 8 years ago

Aktuell folgende Implementierung:

Wenn für ein Kunstwerk Materialannotated vorhanden ist wird dieses unter dem Titel "Material" dargestellt. Sonst werden die Materialien aus der Zuordnungstabelle artwork_material_mm als Liste von Links dargestellt, dabei wird, falls vorhanden, der Link zu Wikipedia genommen, sonst ein Link ins Materialarchiv erstellt.

Beispiellink Materialarchiv: http://materialarchiv.ch/detail/1544

ukeller commented 8 years ago

@MichaelRoethlin Kannst du das Verhalten bestätigen?

MichaelRoethlin commented 8 years ago

@ukeller Genau! Gerne hier die vollständige Logik der Materialtextermittlung, wie wir sie in iOS haben:

   /**
     Get list of materials, nicely formatted as HTML list

     - returns: String The materials list as formatted HTML list
     */
    func getMaterialsAsHTMLListWithLinks () -> String {
        var materialArr = [String]()
        var retVal = ""
        var duplicateCheckString = ""

        if self.material_ref!.count == 0 {
            // Just signal that no official material has been assigned, this is not strictly an error
            XCGLogger.defaultInstance().verbose("-- Strange: no material assigned")
        } else {
            for curMaterial in self.material_ref! {
                if let tMaterial : Material = curMaterial as? Material {
                    var linkList = [String]()
                    let title : String = tMaterial.title!

                    if title != "-" {
                        duplicateCheckString += title
                        if let wikipedia = tMaterial.wikipedia {
                            if (wikipedia.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) {
                                linkList.append("<a href='\(wikipedia)'>wikipedia.org</a>")
                            }
                        }

                        if let materialarchiveid = tMaterial.materialarchiveid {
                            if materialarchiveid != 0 {
                                linkList.append("<a href='http://materialarchiv.ch/detail/\(materialarchiveid)'>materialarchiv.ch</a>")
                            }
                        }
                        var materialListEntry = title
                        if linkList.count > 0 {
                            materialListEntry += " (" + linkList.joinWithSeparator(", ") + ")"
                            materialArr.append(materialListEntry)
                        }
                    }
                }
            }
        }

        let manTitle : String = self.materialannotated!

        // only append entry if not contained in (structured) materials list above
        if (manTitle != "-") && (manTitle.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) && (duplicateCheckString.uppercaseString.rangeOfString(manTitle.uppercaseString) == nil) {
            materialArr.append("\(self.materialannotated!)")
        }

        if materialArr.count > 0 {
            retVal = "<ul><li>" + materialArr.joinWithSeparator("</li><li>") + "</li></ul>"
        } else {
            XCGLogger.defaultInstance().warning("No material found for artwork uid \(self.uid!) '\(self.title!)'")
        }
        return retVal
    }
ukeller commented 8 years ago

Im IOS code: Ist materialannotated = "annotated" und material_ref = [{title: "contains annotated already", materialarchiveid: 0, wikipedia: "-"}] dann kommt ein leerer Wert zurück. Es gibt zwei Möglichkeiten:

Soll ein Material-Item mit fehlenden Links aufgelistet werden? 1) JA:

                    ...
                        var materialListEntry = title
                        if linkList.count > 0 {
                            materialListEntry += " (" + linkList.joinWithSeparator(", ") + ")"
                            //materialArr.append(materialListEntry)
                        }
                        materialArr.append(materialListEntry)
                    ...

2) NEIN:

                    ...
                    if title != "-" {
                        //duplicateCheckString += title
                        ...
                        ...
                        var materialListEntry = title
                        if linkList.count > 0 {
                            materialListEntry += " (" + linkList.joinWithSeparator(", ") + ")"
                            materialArr.append(materialListEntry)
                            duplicateCheckString += title
                        }
                    ...

Meine aktuellen Testfälle, beim mir Variante 1) JA

  @Test
    public void testGetMaterialsFormatted() {
        ArtDetail dm = spy(new ArtDetail());
        Material m0 = new Material();
        Material m1 = new Material();

        // if everything is empty formated should be empty
        doReturn(emptyList()).when(dm).getMaterials();
        doReturn("").when(dm).getMaterialAnnotated();
        assertEquals("",dm.getMaterialsFormatted());

        // if annotated is present display it
        doReturn(emptyList()).when(dm).getMaterials();
        doReturn("annotated").when(dm).getMaterialAnnotated();
        assertEquals("<ul><li>annotated</li></ul>",dm.getMaterialsFormatted());

        // if annotated is present it is not displayed if it is part of the generated list
        m0.setTitle("material without links");
        m0.setWikipedia("");
        m0.setMaterialArchiveid(0);
        doReturn(singletonList(m0)).when(dm).getMaterials();
        doReturn("annotated").when(dm).getMaterialAnnotated();
        assertEquals("<ul><li>material without links</li><li>annotated</li></ul>",dm.getMaterialsFormatted());

        // annotated not matching list, 1 material without links 1 material with both links
        m0.setTitle("material without links");
        m0.setWikipedia("");
        m0.setMaterialArchiveid(0);
        m1.setTitle("material with links");
        m1.setWikipedia("https://de.wikipedia.org/wiki/Berner_Fachhochschule");
        m1.setMaterialArchiveid(1234);
        doReturn(asList(m0,m1)).when(dm).getMaterials();
        doReturn("annotated").when(dm).getMaterialAnnotated();
        assertEquals("<ul>" +
                "<li>material without links</li>" +
                "<li>material with links (<a href=\"https://de.wikipedia.org/wiki/Berner_Fachhochschule\">wikipedia.org</a>, <a href=\"http://materialarchiv.ch/detail/1234\">materialarchiv.ch</a>)</li>" +
                "<li>annotated</li>" +
                "</ul>",dm.getMaterialsFormatted());

        // if annotated is present it is not displayed if it is part of the generated list
        m0.setTitle("contains annotated already");
        m0.setWikipedia("");
        m0.setMaterialArchiveid(0);
        doReturn(singletonList(m0)).when(dm).getMaterials();
        doReturn("annotated").when(dm).getMaterialAnnotated();
        assertEquals("<ul><li>contains annotated already</li></ul>",dm.getMaterialsFormatted());
    }