Skip to content

Commit

Permalink
Merge pull request #20 from ApolloDev/4.0-upgrade
Browse files Browse the repository at this point in the history
4.0 upgrade
  • Loading branch information
JohnLevander authored Aug 16, 2017
2 parents 0881787 + 94b22e4 commit 458a362
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.text.SimpleDateFormat;
import java.util.*;

import static edu.pitt.apollo.apollolocationservicesdk.utilities.LocationNameUtility.adminTypeOnes;

/**
* Created by mas400 on 7/6/16.
*/
Expand Down Expand Up @@ -52,8 +54,15 @@ public String getStartDateString() {
}

public SpatialGranularityEnum getAdminLevel() {
int adminLevel = 0;
List<LinkedHashMap> encompassingRegions = getProperty(ApolloLocationServiceFeatureConstants.LINEAGE);
return SpatialGranularityEnum.fromValue("admin" + Integer.toString(encompassingRegions.size() + 1));
for(LinkedHashMap encompassingRegion : encompassingRegions) {
if(adminTypeOnes.contains(encompassingRegion.get("locationTypeName").toString()) || adminLevel > 0){
adminLevel++;

}
}
return SpatialGranularityEnum.fromValue("admin" + Integer.toString(adminLevel + 1));
}

public ArrayList getEncompassingRegions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,36 @@
import edu.pitt.apollo.apollolocationservicesdk.interfaces.ApolloLocationServiceInterface;
import edu.pitt.apollo.apollolocationservicesdk.types.ApolloLocationServiceFeature;
import edu.pitt.apollo.types.v4_0_1.SpatialGranularityEnum;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static edu.pitt.apollo.apollolocationservicesdk.connectors.ApolloLocationServiceWebConnector.callURL;

/**
* Created by nem41 on 1/25/17.
*/
public class LocationNameUtility {
public static List<String> adminTypeOnes;

static {
adminTypeOnes = new ArrayList<>();
String locationJSON = "";
try {
locationJSON = callURL("https://betaweb.rods.pitt.edu/ls/api/location-types?superTypeId=3");

JSONArray jsonArray = new JSONArray(locationJSON);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
adminTypeOnes.add(jsonObject.getString("name"));
}
} catch (Exception e) {
}
}

private static String formatCountry(String countryName) {
String name = countryName.replace(" (the)", "");
Expand All @@ -24,12 +45,19 @@ private static String formatCountry(String countryName) {
}

private static void buildLineage(Set<String> adminLevelOne, Set<String> adminLevelTwo,
ApolloLocationServiceFeature feature, ApolloLocationServiceInterface service) {
ApolloLocationServiceFeature feature, ApolloLocationServiceInterface service, Boolean atAdminLevelOne) {

if (feature == null) {
return;
}

if (adminTypeOnes.contains(feature.getLocationTypeName().toString())) {
atAdminLevelOne = true;
}
if (!adminTypeOnes.contains(feature.getLocationTypeName().toString()) && atAdminLevelOne) {
return;
}

String name = feature.getLocationName();
SpatialGranularityEnum spatialGranularity = feature.getAdminLevel();

Expand All @@ -43,7 +71,8 @@ private static void buildLineage(Set<String> adminLevelOne, Set<String> adminLev

String encompassingCode = feature.getEncompassingRegionCode();
ApolloLocationServiceFeature encompassingFeature = service.getFeatureFromLocationCode(encompassingCode);
buildLineage(adminLevelOne, adminLevelTwo, encompassingFeature, service);
buildLineage(adminLevelOne, adminLevelTwo, encompassingFeature, service, atAdminLevelOne);

}


Expand All @@ -55,7 +84,7 @@ public static String getLocationDescription(List<String> adminLocationList, Apol
ApolloLocationServiceFeature baseFeature = null;
for (String locationCode : adminLocationList) {
baseFeature = apolloLocationService.getFeatureFromLocationCode(locationCode);
buildLineage(adminLevelOne, adminLevelTwo, baseFeature, apolloLocationService);
buildLineage(adminLevelOne, adminLevelTwo, baseFeature, apolloLocationService, false);
// lineageList = apolloLocationSpatialInformationCache.getLineageMap().get(locationCode);
// if (lineageList == null) {
// getApolloLSNameAndPolygonEntry(locationCode, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ $(document)
});

} else if ($(this).attr("id") == 'set-version') {
console.log('in version');
var urn = $(this).attr(
'data-uri');
var formData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ $(document)
});

} else if ($(this).attr("id") == 'set-version') {
console.log('in version');
var urn = $(this).attr(
'data-uri');
var formData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import edu.pitt.apollo.services_common.v4_0_1.Authentication;

import javax.xml.datatype.XMLGregorianCalendar;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
* Created by jdl50 on 8/4/15.
Expand Down Expand Up @@ -92,10 +94,15 @@ public GetLibraryItemURNsResult getLibraryItemURNs(String itemType, Authenticati

@Override
public SetReleaseVersionResult approveRevisionOfLibraryItem(int urn, int revision, String comment, Authentication authentication) throws LibraryServiceException {
String uri = restServiceUri + "/items/" + urn + "/revisions/" + revision + "/approve?comment=" + comment;
try {
String uri = restServiceUri + "items/" + urn + "/revisions/" + revision + "/approve?comment=" + URLEncoder.encode(comment, "UTF-8");

return restServiceUtils.makePostRequestCheckResponseAndGetObject(uri, authentication, "", SetReleaseVersionResult.class);
} catch (RestServiceException ex) {
}
catch (UnsupportedEncodingException e) {
throw new LibraryServiceException(e.getMessage());
}
catch (RestServiceException ex) {
throw new LibraryServiceException(ex.getMessage());
}
}
Expand All @@ -107,7 +114,7 @@ public ModifyGroupOwnershipResult grantGroupAccessToLibraryItem(int urn, String

@Override
public AddReviewerCommentResult addReviewerCommentToLibraryItem(int urn, int revision, String comment, Authentication authentication) throws LibraryServiceException {
String uri = restServiceUri + "/items/" + urn + "/revisions/" + revision + "/comments?comment=" + comment;
String uri = restServiceUri + "items/" + urn + "/revisions/" + revision + "/comments?comment=" + comment;
try {
return restServiceUtils.makePostRequestCheckResponseAndGetObject(uri, authentication, "", AddReviewerCommentResult.class);
} catch (RestServiceException ex) {
Expand All @@ -117,7 +124,7 @@ public AddReviewerCommentResult addReviewerCommentToLibraryItem(int urn, int rev

@Override
public SetLibraryItemAsNotReleasedResult hideLibraryItem(int urn, Authentication authentication) throws LibraryServiceException {
String uri = restServiceUri + "/items/" + urn + "/hide";
String uri = restServiceUri + "items/" + urn + "/hide";
try {
return restServiceUtils.makePostRequestCheckResponseAndGetObject(uri, authentication, "", SetLibraryItemAsNotReleasedResult.class);
} catch (RestServiceException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ String getLibraryItemUrns(
String setLibraryItemReleaseVersion(
@ApiParam(value = "Item URN", required = true) @PathVariable("urn") int urn,
@ApiParam(value = "Revision", required = true) @PathVariable("revision") int revision,
@ApiParam(value = "Comment", required = true) @PathVariable("comment") String comment,
@ApiParam(value = "Comment", required = true) @RequestParam("comment") String comment,
@RequestHeader("Authorization") String authorization) throws UnsupportedSerializationFormatException, SerializationException, UnsupportedAuthorizationTypeException {
return new SetLibraryItemReleaseVersionMethod(SerializationFormat.XML, authorization).setLibraryItemReleaseVersion(urn, revision, comment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,27 @@ public Integer getReleaseVersion(int urn) throws ApolloDatabaseException {
}
}

public Integer getLatestVersion(int urn) throws ApolloDatabaseException {

try (Connection conn = getConnection(false)) {
String sql = "SELECT MAX(version) FROM library_item_containers WHERE urn_id =" + urn;

PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();

int version;
if (rs.next()) {
version = rs.getInt(1);
return version;
} else {
return null;
}

} catch (SQLException ex) {
throw createApolloDatabaseExceptionAndLog(GETTING_RELEASE_VERSION, ex);
}
}

public boolean checkIfVersionIsApproved(int urn, int version) throws ApolloDatabaseException {

try (Connection conn = getConnection(false)) {
Expand All @@ -878,9 +899,13 @@ public GetLibraryItemContainerResult getLibraryItemContainer(int urn, Integer ve

GetLibraryItemContainerResult result = new GetLibraryItemContainerResult();
if (version == null) {
version = getReleaseVersion(urn);
result.setIsLatestApprovedRevision(true);
version = getLatestVersion(urn);
result.setIsApprovedRevision(checkIfVersionIsApproved(urn, version));
result.setIsApprovedRevision(true);

// version = getReleaseVersion(urn);
// result.setIsLatestApprovedRevision(true);
// result.setIsApprovedRevision(true);
} else {
boolean approved = checkIfVersionIsApproved(urn, version);

Expand Down Expand Up @@ -1167,20 +1192,32 @@ public List<LibraryItemContainer> getLibraryItemContainers(String className, boo
public List<LibraryItemContainerAndURN> getCollections(String collectionClassName, boolean includeUnreleasedItems, int role_id) throws ApolloDatabaseException {
List<LibraryItemContainerAndURN> libraryCollections = new ArrayList<>();

String query = "SELECT\n"
+ " distinct urn_id, version, json_representation,\n"
+ " is_latest_release_version AS released\n"
+ " FROM\n"
+ " library_item_containers\n"
+ " INNER JOIN library_item_container_urns "
+ " ON library_item_containers.urn_id = library_item_container_urns.id "
+ " WHERE\n"
+ " json_representation -> 'libraryItem' ->> 'javaClassNameOfMembers' = '" + collectionClassName + "' AND\n"
+ " json_representation -> 'libraryItem' @> '{\"type\":\"LibraryCollection\"}' = 't'\n";
String query = "SELECT\n" +
" library_item_containers.urn_id,\n" +
" library_item_containers.version,\n" +
" library_item_containers.json_representation,\n" +
" library_item_containers.is_latest_release_version AS released\n" +
"FROM\n" +
" library_item_containers,\n" +
" library_item_container_urns";
if (includeUnreleasedItems) {
query += ", (SELECT " +
" urn_id,\n" +
" MAX(version) AS max_version\n" +
" FROM library_item_containers\n" +
" WHERE library_item_containers.urn_id = urn_id\n" +
" GROUP BY urn_id) AS m";
}
query += "\nWHERE\n" +
" library_item_containers.urn_id = library_item_container_urns.id AND\n" +
" library_item_containers.json_representation -> 'libraryItem' ->> 'javaClassNameOfMembers' = '" + collectionClassName + "' AND\n" +
" library_item_containers.json_representation -> 'libraryItem' @> '{\"type\":\"LibraryCollection\"}' = 't'\n";
if (!includeUnreleasedItems) {
query += " AND is_latest_release_version = TRUE";
query += " AND is_latest_release_version = TRUE";
} else {
query += " AND library_item_container_urns.role_id <= " + role_id + "\n";
query += " AND library_item_container_urns.role_id <= " + role_id + " AND\n" +
" m.urn_id = library_item_containers.urn_id AND\n" +
" m.max_version = library_item_containers.version\n";
}

QueryResult result = queryObjects(query);
Expand Down Expand Up @@ -1252,7 +1289,7 @@ public List<LibraryItemDisplayNameAndURN> getMembersOfCollection(int urn, int ve
" INNER JOIN library_item_container_urns \n" +
"\t\tON lic.urn_id = library_item_container_urns.id\n";
if (includeUnreleasedItems) {
query += "\t\tAND library_item_container_urns.role_id <= 2\n";
query += "\t\tAND library_item_container_urns.role_id <= " + role_id+ "\n";
} else {
query += "\t\tAND lic.is_latest_release_version = TRUE\n";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ $(document)
});

} else if ($(this).attr("id") == 'set-version') {
console.log('in version');
var urn = $(this).attr(
'data-uri');
var formData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ $(document)
});

} else if ($(this).attr("id") == 'set-version') {
console.log('in version');
var urn = $(this).attr(
'data-uri');
var formData = {
Expand Down

0 comments on commit 458a362

Please sign in to comment.