-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wikibase API: Return revision id after making an edit. (#796)
* Wikibase API: Return revision id after making an edit. Closes #795 * Use Optional on getRevisionId * Use OptionalLong
- Loading branch information
Showing
11 changed files
with
401 additions
and
45 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
wdtk-wikibaseapi/src/main/java/org/wikidata/wdtk/wikibaseapi/EditingResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.wikidata.wdtk.wikibaseapi; | ||
|
||
/*- | ||
* #%L | ||
* Wikidata Toolkit Wikibase API | ||
* %% | ||
* Copyright (C) 2014 - 2023 Wikidata Toolkit Developers | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
|
||
import java.util.Objects; | ||
import java.util.OptionalLong; | ||
|
||
/** | ||
* Holds information about a successful edit made via {@link WikibaseDataEditor}. | ||
* The state of the entity after edit is not provided here because it is not possible | ||
* for WDTK to determine it reliably from the response of the server. Indeed, it is | ||
* possible that the data in the entity after the edit differs from the data in the | ||
* entity before the edit plus the changes of the edit itself, because it can be that | ||
* another edit touched independent parts of the entity. This can happen even if the base | ||
* revision id is provided. | ||
*/ | ||
public class EditingResult { | ||
|
||
private final long revisionId; | ||
|
||
public EditingResult(long revisionId) { | ||
super(); | ||
this.revisionId = revisionId; | ||
} | ||
|
||
/** | ||
* The identifier of the revision of the last edit made by the editing action, | ||
* if any edit was made. | ||
*/ | ||
public OptionalLong getLastRevisionId() { | ||
return revisionId == 0 ? OptionalLong.empty() : OptionalLong.of(revisionId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(revisionId); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (obj == null) return false; | ||
if (getClass() != obj.getClass()) return false; | ||
EditingResult other = (EditingResult) obj; | ||
return revisionId == other.revisionId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "EditingResult [revisionId=" + revisionId + "]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
wdtk-wikibaseapi/src/test/java/org/wikidata/wdtk/wikibaseapi/EditingResultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.wikidata.wdtk.wikibaseapi; | ||
|
||
/*- | ||
* #%L | ||
* Wikidata Toolkit Wikibase API | ||
* %% | ||
* Copyright (C) 2014 - 2023 Wikidata Toolkit Developers | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.OptionalLong; | ||
|
||
import org.junit.Test; | ||
|
||
public class EditingResultTest { | ||
|
||
@Test | ||
public void testGetRevisionId() { | ||
EditingResult SUT = new EditingResult(1234L); | ||
|
||
assertEquals(SUT.getLastRevisionId(), OptionalLong.of(1234L)); | ||
} | ||
|
||
@Test | ||
public void testNoRevisionId() { | ||
EditingResult SUT = new EditingResult(0L); | ||
|
||
assertEquals(SUT.getLastRevisionId(), OptionalLong.empty()); | ||
} | ||
} |
Oops, something went wrong.