Skip to content

Commit

Permalink
Merge pull request #152 from digipost/tag-status
Browse files Browse the repository at this point in the history
Method to get list of tags for user, using personal identification number
  • Loading branch information
hermanwh authored Mar 22, 2023
2 parents dc5c993 + c5fbc8b commit f3786f0
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/main/java/no/digipost/api/client/DigipostClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
import no.digipost.api.client.representations.IdentificationResult;
import no.digipost.api.client.representations.Link;
import no.digipost.api.client.representations.Message;
import no.digipost.api.client.representations.PersonalIdentificationNumber;
import no.digipost.api.client.representations.Recipients;
import no.digipost.api.client.representations.accounts.UserAccount;
import no.digipost.api.client.representations.accounts.Tag;
import no.digipost.api.client.representations.accounts.Tags;
import no.digipost.api.client.representations.accounts.UserAccount;
import no.digipost.api.client.representations.accounts.UserInformation;
import no.digipost.api.client.representations.archive.Archive;
import no.digipost.api.client.representations.archive.ArchiveDocument;
Expand Down Expand Up @@ -307,6 +309,10 @@ public void removeTag(Tag tag) {
tagApi.removeTag(tag);
}

public Tags getTags(PersonalIdentificationNumber personalIdentificationNumber) {
return tagApi.getTags(personalIdentificationNumber);
}

public ArchiveApi.ArchivingDocuments archiveDocuments(final Archive archive) {
return archiveSender.createArchive(archive);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@
import no.digipost.api.client.representations.Identification;
import no.digipost.api.client.representations.Link;
import no.digipost.api.client.representations.MayHaveSender;
import no.digipost.api.client.representations.PersonalIdentificationNumber;
import no.digipost.api.client.representations.Recipients;
import no.digipost.api.client.representations.accounts.UserAccount;
import no.digipost.api.client.representations.accounts.Tag;
import no.digipost.api.client.representations.accounts.Tags;
import no.digipost.api.client.representations.accounts.UserAccount;
import no.digipost.api.client.representations.accounts.UserInformation;
import no.digipost.api.client.representations.archive.Archive;
import no.digipost.api.client.representations.archive.ArchiveDocument;
Expand Down Expand Up @@ -486,6 +488,13 @@ public void removeTag(Tag tag) {
throw new DigipostClientException(ErrorCode.GENERAL_ERROR, e);
}
}

@Override
public Tags getTags(PersonalIdentificationNumber personalIdentificationNumber) {
Map<String, String> queryParams = new HashMap<>();
queryParams.put("personal-identification-number", personalIdentificationNumber.asString());
return getEntity(Tags.class, getEntryPoint().getTagsUri().getPath(), queryParams);
}

private static String pathWithQuery(URI uri){
return uri.getPath() + ((uri.getQuery() != null) ? "?" + uri.getQuery() : "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public URI getSenderInformationUri() {

public URI getRemoveTagUri() { return getLinkByRelationName(REMOVE_TAG).getUri(); }

public URI getTagsUri() { return getLinkByRelationName(GET_TAGS).getUri(); }

public URI getCreateOrActivateUserAccountUri() { return getLinkByRelationName(CREATE_OR_ACTIVATE_USER_ACCOUNT).getUri(); }

public String getCertificate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ public enum Relation {
CREATE_OR_ACTIVATE_USER_ACCOUNT,
ADD_TAG,
REMOVE_TAG,
GET_TAGS,

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (C) Posten Norge AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package no.digipost.api.client.representations.accounts;

import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;

@XmlType(name = "tag-type")
@XmlEnum
public enum TagType {
PUBLIC_MAILBOX_TAG;

public String value() {
return name();
}

public static TagType fromValue(String v) {
return valueOf(v);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (C) Posten Norge AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package no.digipost.api.client.representations.accounts;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import java.util.ArrayList;
import java.util.List;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "tags", propOrder = { "tags" })
@XmlRootElement(name = "tags")
public class Tags {

@XmlElement(name = "tag-type")
protected List<TagType> tags = new ArrayList<>();

public Tags() {
}

public Tags(List<TagType> tags) {
this.tags = tags;
}

public List<TagType> getTags() {
return tags;
}
}
4 changes: 4 additions & 0 deletions src/main/java/no/digipost/api/client/tag/TagApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package no.digipost.api.client.tag;

import no.digipost.api.client.representations.PersonalIdentificationNumber;
import no.digipost.api.client.representations.accounts.Tag;
import no.digipost.api.client.representations.accounts.Tags;

/**
* Klasser som implementerer dette interfacet håndterer det å sette og fjerne
Expand All @@ -30,4 +32,6 @@ public interface TagApi {

void removeTag(Tag tag);

Tags getTags(PersonalIdentificationNumber personalIdentificationNumber);

}
33 changes: 33 additions & 0 deletions src/main/resources/xsd/api_v8.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1409,4 +1409,37 @@
</xsd:sequence>
</xsd:complexType>

<xsd:element name="tags" type="tags" />

<xsd:complexType name="tags">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate target="class">
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="tags"/>
</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="tag-type" type="tag-type" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="tag-type">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumClass />
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="PUBLIC_MAILBOX_TAG">
<xsd:annotation>
<xsd:documentation>The account receives public mail through Digipost.</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="PUBLIC_MAILBOX_TAG" />
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

</xsd:schema>

0 comments on commit f3786f0

Please sign in to comment.