/** * Creates the responsibility object if it does not already exists, then returns it. * * @return the responsibility party (never {@code null}). */ private DefaultResponsibleParty responsibility() { if (responsibility == null) { responsibility = new DefaultResponsibleParty(); } return responsibility; }
/** * Creates the responsibility object if it does not already exists, then returns it. * * @return the responsibility party (never {@code null}). */ private DefaultResponsibleParty responsibility() { if (responsibility == null) { responsibility = new DefaultResponsibleParty(); } return responsibility; }
/** * Invoked by JAXB at unmarshalling time for storing the result temporarily. * * @param md the unmarshalled metadata. */ public void setElement(final DefaultResponsibility md) { if (md instanceof DefaultResponsibleParty) { metadata = (DefaultResponsibleParty) md; } else if (md != null) { metadata = new DefaultResponsibleParty(md); } } }
/** * Returns a SIS metadata implementation with the values of the given arbitrary implementation. * This method performs the first applicable action in the following choices: * * <ul> * <li>If the given object is {@code null}, then this method returns {@code null}.</li> * <li>Otherwise if the given object is already an instance of * {@code DefaultResponsibleParty}, then it is returned unchanged.</li> * <li>Otherwise a new {@code DefaultResponsibleParty} instance is created using the * {@linkplain #DefaultResponsibleParty(ResponsibleParty) copy constructor} * and returned. Note that this is a <cite>shallow</cite> copy operation, since the other * metadata contained in the given object are not recursively copied.</li> * </ul> * * @param object the object to get as a SIS implementation, or {@code null} if none. * @return a SIS implementation containing the values of the given object (may be the * given object itself), or {@code null} if the argument was null. */ public static DefaultResponsibleParty castOrCopy(final ResponsibleParty object) { if (object == null || object instanceof DefaultResponsibleParty) { return (DefaultResponsibleParty) object; } return new DefaultResponsibleParty(object); }
/** * Returns a SIS metadata implementation with the values of the given arbitrary implementation. * This method performs the first applicable action in the following choices: * * <ul> * <li>If the given object is {@code null}, then this method returns {@code null}.</li> * <li>Otherwise if the given object is already an instance of * {@code DefaultResponsibleParty}, then it is returned unchanged.</li> * <li>Otherwise a new {@code DefaultResponsibleParty} instance is created using the * {@linkplain #DefaultResponsibleParty(ResponsibleParty) copy constructor} * and returned. Note that this is a <cite>shallow</cite> copy operation, since the other * metadata contained in the given object are not recursively copied.</li> * </ul> * * @param object the object to get as a SIS implementation, or {@code null} if none. * @return a SIS implementation containing the values of the given object (may be the * given object itself), or {@code null} if the argument was null. */ public static DefaultResponsibleParty castOrCopy(final ResponsibleParty object) { if (object == null || object instanceof DefaultResponsibleParty) { return (DefaultResponsibleParty) object; } return new DefaultResponsibleParty(object); }
/** * Invoked by JAXB at marshalling time for getting the actual metadata to write * inside the {@code <gmd:CI_Responsibility>} XML element. * This is the value or a copy of the value given in argument to the {@code wrap} method. * * @return the metadata to be marshalled. */ @XmlElementRef @SuppressWarnings("deprecation") public DefaultResponsibility getElement() { if (LEGACY_XML && !(metadata instanceof DefaultResponsibleParty)) { return new DefaultResponsibleParty(metadata); } else { return metadata; } }
/** * Invoked by JAXB at marshalling time for getting the actual metadata to write * inside the {@code <cit:CI_Responsibility>} XML element. * This is the value or a copy of the value given in argument to the {@code wrap} method. * * @return the metadata to be marshalled. */ @XmlElementRef @SuppressWarnings("deprecation") public DefaultResponsibility getElement() { if (FilterByVersion.CURRENT_METADATA.accept()) { if (metadata instanceof ResponsibleParty) { // Need to build new DefaultResponsibility object here — simply casting doesn't work. return new DefaultResponsibility(metadata); } return metadata; } else if (FilterByVersion.LEGACY_METADATA.accept()) { if (metadata instanceof DefaultResponsibleParty) { return metadata; } else { return new DefaultResponsibleParty(metadata); } } else { return null; } }
final DefaultResponsibleParty r = new DefaultResponsibleParty(Role.OWNER); r.setParties(Collections.singleton(party)); c.setCitedResponsibleParties(Collections.singleton(r));
/** * Adds role, name, contact and position information for an individual or organization that is responsible * for the resource. This method can be used as an alternative to {@link #addAuthor(CharSequence)} when the * caller needs to create the responsibly party itself. * * <p>If the given {@code role} is non-null, then this method will ensure that the added party has the given * role. A copy of the given party will be created if needed (the given party will never be modified).</p> * * Storage locations are: * * <ul> * <li>{@code metadata/identificationInfo/citation/citedResponsibleParty}</li> * <li>{@code metadata/identificationInfo/citation/citedResponsibleParty/role}</li> * </ul> * * @param party the individual or organization that is responsible, or {@code null} for no-operation. * @param role the role to set, or {@code null} for leaving it unchanged. */ public final void addCitedResponsibleParty(ResponsibleParty party, final Role role) { if (party != null) { if (role != null && !role.equals(party.getRole())) { party = new DefaultResponsibleParty(party); ((DefaultResponsibility) party).setRole(role); } addIfNotPresent(citation().getCitedResponsibleParties(), party); } }
/** * Adds role, name, contact and position information for an individual or organization that is responsible * for the resource. This method can be used as an alternative to {@link #addAuthor(CharSequence)} when the * caller needs to create the responsibly party itself. * * <p>If the given {@code role} is non-null, then this method will ensure that the added party has the given * role. A copy of the given party will be created if needed (the given party will never be modified).</p> * * Storage locations are: * * <ul> * <li>{@code metadata/identificationInfo/citation/citedResponsibleParty}</li> * <li>{@code metadata/identificationInfo/citation/citedResponsibleParty/role}</li> * </ul> * * @param party the individual or organization that is responsible, or {@code null} for no-operation. * @param role the role to set, or {@code null} for leaving it unchanged. */ public final void addCitedResponsibleParty(ResponsibleParty party, final Role role) { if (party != null) { if (role != null && !role.equals(party.getRole())) { party = new DefaultResponsibleParty(party); ((DefaultResponsibility) party).setRole(role); } addIfNotPresent(citation().getCitedResponsibleParties(), party); } }
/** * Tests hash code computation of an object containing another metadata object. */ @Test @DependsOnMethod("testSimple") public void testNested() { final InternationalString title = new SimpleInternationalString("Some title"); final InternationalString person = new SimpleInternationalString("Illustre inconnu"); final DefaultIndividual party = new DefaultIndividual(person, null, null); final DefaultResponsibleParty resp = new DefaultResponsibleParty(Role.AUTHOR); final DefaultCitation instance = new DefaultCitation(title); resp.getParties().add(party); instance.getCitedResponsibleParties().add(resp); /* * Individual hash code is the sum of all its properties, none of them being a collection. */ int expected = DefaultIndividual.class.hashCode() + person.hashCode(); assertEquals("Individual", Integer.valueOf(expected), hash(party)); /* * The +31 below come from java.util.List contract, since above Individual is a list member. */ expected += ResponsibleParty.class.hashCode() + Role.AUTHOR.hashCode() + 31; assertEquals("Responsibility", Integer.valueOf(expected), hash(resp)); /* * The +31 below come from java.util.List contract, since above Responsibility is a list member. */ expected += Citation.class.hashCode() + title.hashCode() + 31; assertEquals("Citation", Integer.valueOf(expected), hash(instance)); }
final DefaultCitation citation = TreeNodeChildrenTest.metadataWithMultiOccurrences(); AbstractParty party = new DefaultOrganisation("Some organisation", null, null, null); DefaultResponsibleParty responsibility = new DefaultResponsibleParty(Role.DISTRIBUTOR); responsibility.setParties(singleton(party)); assertTrue(citation.getCitedResponsibleParties().add(responsibility)); contact.setAddresses(singleton(address)); party = new DefaultIndividual("Some person of contact", null, contact); responsibility = new DefaultResponsibleParty(Role.POINT_OF_CONTACT); responsibility.setParties(singleton(party)); assertTrue(citation.getCitedResponsibleParties().add(responsibility));
/** * Creates a citation with an arbitrary title, presentation form and other properties. * * @return an arbitrary citation. * * @since 0.7 */ public static DefaultCitation create() { final DefaultCitation citation = new DefaultCitation(); final DefaultInternationalString title = new DefaultInternationalString(); title.add(Locale.JAPANESE, "アンダーカレント"); title.add(Locale.ENGLISH, "Undercurrent"); citation.setTitle(title); citation.setISBN("9782505004509"); citation.setPresentationForms(Arrays.asList( PresentationForm.DOCUMENT_HARDCOPY, PresentationForm.DOCUMENT_DIGITAL)); citation.setAlternateTitles(Collections.singleton( new SimpleInternationalString("Andākarento"))); // Actually a different script of the Japanese title. final DefaultResponsibleParty author = new DefaultResponsibleParty(Role.AUTHOR); author.setParties(Collections.singleton(new DefaultIndividual("Testsuya Toyoda", null, null))); final DefaultResponsibleParty editor = new DefaultResponsibleParty(Role.valueOf("EDITOR")); editor.setParties(Collections.singleton(new DefaultOrganisation("Kōdansha", null, null, null))); editor.setExtents(Collections.singleton(Extents.WORLD)); citation.setCitedResponsibleParties(Arrays.asList(author, editor)); return citation; }
/** * Creates the metadata object to be tested. * * @param legacy {@code true} for using the legacy {@code ResponsibleParty} instead of {@code Responsibility}. * This is sometime needed for comparison purpose with unmarshalled metadata. */ @SuppressWarnings("deprecation") private static DefaultMetadata createMetadata(final boolean legacy) { final DefaultMetadata metadata = new DefaultMetadata(); final DefaultCitation citation = new DefaultCitation("EPSG Geodetic Parameter Dataset"); Collection<ResponsibleParty> r = HardCodedCitations.EPSG.getCitedResponsibleParties(); if (legacy) { r = singleton(new DefaultResponsibleParty(TestUtilities.getSingleton(r))); } citation.setCitedResponsibleParties(r); final DirectReferenceSystem refSys = new DirectReferenceSystem(new ImmutableIdentifier(citation, null, "4326")); metadata.setReferenceSystemInfo(singleton(refSys)); return metadata; }
/** * Tests marshalling with replacement of {@link DefaultResponsibility} by {@link DefaultResponsibleParty}. * * @throws JAXBException if an error occurred during the marshalling. */ @Test public void testLegacyMarshalling() throws JAXBException { final DefaultIndividual party = new DefaultIndividual("An author", null, null); final DefaultResponsibleParty r = new DefaultResponsibleParty(Role.AUTHOR); final DefaultCitation citation = new DefaultCitation(); r.setParties(singleton(party)); citation.setCitedResponsibleParties(singleton(r)); final String xml = marshal(citation, VERSION_2007); assertXmlEquals("<gmd:CI_Citation xmlns:gco=\"" + LegacyNamespaces.GCO + '"' + " xmlns:gmd=\"" + LegacyNamespaces.GMD + "\">\n" + " <gmd:citedResponsibleParty>\n" + " <gmd:CI_ResponsibleParty>\n" + " <gmd:individualName>\n" + " <gco:CharacterString>An author</gco:CharacterString>\n" + " </gmd:individualName>\n" + " <gmd:role>\n" + " <gmd:CI_RoleCode codeList=\"http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#CI_RoleCode\" codeListValue=\"author\">Author</gmd:CI_RoleCode>\n" + " </gmd:role>\n" + " </gmd:CI_ResponsibleParty>\n" + " </gmd:citedResponsibleParty>\n" + "</gmd:CI_Citation>\n", xml, "xmlns:*"); } }
/** * Tests the formatting of a {@link DefaultProcessing} object. */ @Test public void testProcessing() { final DefaultCitation titled = new DefaultCitation("Some specification"); final DefaultCitation coded = new DefaultCitation(); final DefaultCitation untitled = new DefaultCitation(); titled .setPresentationForms(singleton(PresentationForm.DOCUMENT_HARDCOPY)); coded .setPresentationForms(singleton(PresentationForm.IMAGE_HARDCOPY)); untitled.setCitedResponsibleParties(singleton(new DefaultResponsibleParty(Role.AUTHOR))); final DefaultProcessing processing = new DefaultProcessing(); processing.setDocumentations(asList(titled, coded, untitled)); final String text = format.format(processing.asTreeTable()); assertMultilinesEquals( "Processing\n" + " ├─Documentation (1 of 3)…………… Some specification\n" + " │ └─Presentation form……………… Document hardcopy\n" + " ├─Documentation (2 of 3)\n" + " │ └─Presentation form……………… Image hardcopy\n" + " └─Documentation (3 of 3)\n" + " └─Cited responsible party\n" + " └─Role……………………………………… Author\n", text); }
/** * Creates the metadata instance to be used for testing purpose. * This method creates the following metadata * (ignoring identifiers, which will be inferred from the ISBN value): * * {@preformat text * Citation * ├─Title…………………………………………………… Undercurrent * ├─Edition……………………………………………… <nil:unknown> * ├─Cited Responsible Parties * │ └─Individual Name……………… Testsuya Toyoda * └─ISBN……………………………………………………… 9782505004509 * } * * The citation instance is stored in the {@link #citation} field. * The title and author instances are stored in the {@link #title} and {@link #author} fields. * * @return the map view of the citation create by this method. */ private Map<String,Object> createCitation() { title = new SimpleInternationalString("Undercurrent"); author = new DefaultResponsibleParty(); citation = new DefaultCitation(title); author.setParties(singleton(new DefaultIndividual("Testsuya Toyoda", null, null))); citation.setCitedResponsibleParties(singleton(author)); citation.setISBN("9782505004509"); citation.setEdition(NilReason.UNKNOWN.createNilObject(InternationalString.class)); return MetadataStandard.ISO_19115.asValueMap(citation, null, KeyNamePolicy.JAVABEANS_PROPERTY, ValueExistencePolicy.NON_EMPTY); }
/** * Tests XML marshalling for the given metadata version. * * @param file file containing the expected metadata. * @param version the metadata version to marshal. */ private void testMarshalling(final String file, final Version version) throws JAXBException { final DefaultOnlineResource rs = new DefaultOnlineResource(URI.create("https://tools.ietf.org/html/rfc1149")); rs.setName("IP over Avian Carriers"); rs.setDescription(new SimpleInternationalString("High delay, low throughput, and low altitude service.")); rs.setFunction(OnLineFunction.OFFLINE_ACCESS); final DefaultContact contact = new DefaultContact(rs); contact.setContactInstructions(new SimpleInternationalString("Send carrier pigeon.")); contact.getIdentifierMap().putSpecialized(IdentifierSpace.ID, "ip-protocol"); final DefaultCitation c = new DefaultCitation("Fight against poverty"); final DefaultResponsibleParty r1 = new DefaultResponsibleParty(Role.ORIGINATOR); final DefaultResponsibleParty r2 = new DefaultResponsibleParty(Role.valueOf("funder")); r1.setParties(Collections.singleton(new DefaultIndividual("Maid Marian", null, contact))); r2.setParties(Collections.singleton(new DefaultIndividual("Robin Hood", null, contact))); c.setCitedResponsibleParties(Arrays.asList(r1, r2)); c.getDates().add(new DefaultCitationDate(TestUtilities.date("2015-10-17 00:00:00"), DateType.valueOf("adopted"))); c.getPresentationForms().add(PresentationForm.valueOf("physicalObject")); /* * Check that XML file built by the marshaller is the same as the example file. */ assertMarshalEqualsFile(file, c, version, "xmlns:*", "xsi:schemaLocation"); }
if (party == null) party = isOrganisation(keys) ? new DefaultOrganisation() : new DefaultIndividual(); if (contact != null) party.setContactInfo(singleton(contact)); responsibility = new DefaultResponsibleParty(role); ((DefaultResponsibleParty) responsibility).setParties(singleton(party));
if (party == null) party = isOrganisation(keys) ? new DefaultOrganisation() : new DefaultIndividual(); if (contact != null) party.setContactInfo(singleton(contact)); responsibility = new DefaultResponsibleParty(role); ((DefaultResponsibleParty) responsibility).setParties(singleton(party));