Skip to content

Commit

Permalink
Merge branch 'refactor' of github.com:TAMULib/ProjectManagementServic…
Browse files Browse the repository at this point in the history
…e into model
  • Loading branch information
wwelling committed Jun 27, 2018
2 parents 6237d00 + fc3c674 commit 56b94eb
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 111 deletions.
10 changes: 0 additions & 10 deletions src/main/java/edu/tamu/app/ProjectInitialization.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
package edu.tamu.app;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import edu.tamu.app.enums.ServiceType;
import edu.tamu.app.model.Project;
import edu.tamu.app.model.RemoteProjectManager;
import edu.tamu.app.model.repo.ProjectRepo;
import edu.tamu.app.model.repo.RemoteProjectManagerRepo;
import edu.tamu.app.service.registry.ManagementBeanRegistry;

@Component
public class ProjectInitialization implements CommandLineRunner {

@Autowired
private ProjectRepo projectRepo;

@Autowired
private ManagementBeanRegistry managementBeanRegistry;

Expand Down
48 changes: 24 additions & 24 deletions src/main/java/edu/tamu/app/controller/ProjectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class ProjectController {
private ManagementBeanRegistry managementBeanRegistry;

@Autowired
private RemoteProjectManagerRepo versionManagementSoftwareRepo;
private RemoteProjectManagerRepo remoteProjectManagerRepo;

@Autowired
private SugarService sugarService;
Expand Down Expand Up @@ -100,58 +100,58 @@ public ApiResponse pushRequest(HttpServletRequest req, @RequestBody FeatureReque
Optional<Project> project = Optional.ofNullable(projectRepo.findOne(request.getProjectId()));
ApiResponse response;
if (project.isPresent()) {
Optional<RemoteProjectManager> versionManagementSoftware = Optional.ofNullable(project.get().getRemoteProjectManager());
if (versionManagementSoftware.isPresent()) {
RemoteProjectManagerBean versionManagementSoftwareBean = (RemoteProjectManagerBean) managementBeanRegistry.getService(versionManagementSoftware.get().getName());
Optional<RemoteProjectManager> remoteProjectManager = Optional.ofNullable(project.get().getRemoteProjectManager());
if (remoteProjectManager.isPresent()) {
RemoteProjectManagerBean remoteProjectManagerBean = (RemoteProjectManagerBean) managementBeanRegistry.getService(remoteProjectManager.get().getName());
request.setScopeId(project.get().getScopeId());
try {
response = new ApiResponse(SUCCESS, versionManagementSoftwareBean.push(request));
response = new ApiResponse(SUCCESS, remoteProjectManagerBean.push(request));
} catch (Exception e) {
response = new ApiResponse(ERROR, "Error pushing request to " + versionManagementSoftware.get().getName() + " for project " + project.get().getName() + "!");
response = new ApiResponse(ERROR, "Error pushing request to " + remoteProjectManager.get().getName() + " for project " + project.get().getName() + "!");
}
} else {
response = new ApiResponse(ERROR, project.get().getName() + " project does not have a version management software!");
response = new ApiResponse(ERROR, project.get().getName() + " project does not have a Remote Project Manager!");
}
} else {
response = new ApiResponse(ERROR, "Project with id " + request.getProjectId() + " not found!");
}
return response;
}

@RequestMapping(value = "/{vmsId}/version-projects", method = RequestMethod.GET)
@RequestMapping(value = "/{remoteProjectManagerId}/remote-projects", method = RequestMethod.GET)
@PreAuthorize("hasRole('MANAGER')")
public ApiResponse getAllVersionProjects(@PathVariable Long vmsId) {
Optional<RemoteProjectManager> vms = Optional.ofNullable(versionManagementSoftwareRepo.findOne(vmsId));
public ApiResponse getAllRemoteProjects(@PathVariable Long remoteProjectManagerId) {
Optional<RemoteProjectManager> remoteProjectManager = Optional.ofNullable(remoteProjectManagerRepo.findOne(remoteProjectManagerId));
ApiResponse response;
if (vms.isPresent()) {
RemoteProjectManagerBean versionManagementSoftwareBean = (RemoteProjectManagerBean) managementBeanRegistry.getService(vms.get().getName());
if (remoteProjectManager.isPresent()) {
RemoteProjectManagerBean remoteProjectManagerBean = (RemoteProjectManagerBean) managementBeanRegistry.getService(remoteProjectManager.get().getName());
try {
response = new ApiResponse(SUCCESS, versionManagementSoftwareBean.getRemoteProjects());
response = new ApiResponse(SUCCESS, remoteProjectManagerBean.getRemoteProjects());
} catch (Exception e) {
response = new ApiResponse(ERROR, "Error fetching version projects from " + vms.get().getName() + "!");
response = new ApiResponse(ERROR, "Error fetching remote projects from " + remoteProjectManager.get().getName() + "!");
}
} else {
response = new ApiResponse(ERROR, "Version Management Software with id " + vmsId + " not found!");
response = new ApiResponse(ERROR, "Remote Project Manager with id " + remoteProjectManagerId + " not found!");
}
return response;
}

@RequestMapping(value = "/{vmsId}/version-projects/{scopeId}", method = RequestMethod.GET)
@RequestMapping(value = "/{remoteProjectManagerId}/remote-projects/{scopeId}", method = RequestMethod.GET)
@PreAuthorize("hasRole('MANAGER')")
public ApiResponse getVersionProjectByScopeId(@PathVariable Long vmsId, @PathVariable String scopeId) {
Optional<RemoteProjectManager> vms = Optional.ofNullable(versionManagementSoftwareRepo.findOne(vmsId));
public ApiResponse getRemoteProjectByScopeId(@PathVariable Long remoteProjectManagerId, @PathVariable String scopeId) {
Optional<RemoteProjectManager> remoteProjectManager = Optional.ofNullable(remoteProjectManagerRepo.findOne(remoteProjectManagerId));
ApiResponse response;
if (vms.isPresent()) {
RemoteProjectManagerBean versionManagementSoftwareBean = (RemoteProjectManagerBean) managementBeanRegistry.getService(vms.get().getName());
if (remoteProjectManager.isPresent()) {
RemoteProjectManagerBean remoteProjectManagerBean = (RemoteProjectManagerBean) managementBeanRegistry.getService(remoteProjectManager.get().getName());
try {
response = new ApiResponse(SUCCESS, versionManagementSoftwareBean.getRemoteProjectByScopeId(scopeId));
response = new ApiResponse(SUCCESS, remoteProjectManagerBean.getRemoteProjectByScopeId(scopeId));
} catch (Exception e) {
response = new ApiResponse(ERROR, "Error fetching version project with scope id " + scopeId + " from " + vms.get().getName() + "!");
response = new ApiResponse(ERROR, "Error fetching remote project with scope id " + scopeId + " from " + remoteProjectManager.get().getName() + "!");
}
} else {
response = new ApiResponse(ERROR, "Version Management Software with id " + vmsId + " not found!");
response = new ApiResponse(ERROR, "Remote Project Manager with id " + remoteProjectManagerId + " not found!");
}
return response;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ public ApiResponse getOne(@PathVariable Long id) {
@WeaverValidation(business = { @WeaverValidation.Business(value = CREATE) })
public ApiResponse createRemoteProjectManager(@WeaverValidatedModel RemoteProjectManager remoteProjectManager) {
logger.info("Model: " + remoteProjectManager.toString());
logger.info("Creating Version Management Software: " + remoteProjectManager.getName());
logger.info("Creating Remote Project Manager: " + remoteProjectManager.getName());
return new ApiResponse(SUCCESS, remoteProjectManagerRepo.create(remoteProjectManager));
}

@RequestMapping(method = RequestMethod.PUT)
@PreAuthorize("hasRole('USER')")
@WeaverValidation(business = { @WeaverValidation.Business(value = UPDATE) })
public ApiResponse updateRemoteProjectManager(@WeaverValidatedModel RemoteProjectManager remoteProjectManager) {
logger.info("Updating Version Management Software: " + remoteProjectManager.getName());
logger.info("Updating Remote Project Manager: " + remoteProjectManager.getName());
return new ApiResponse(SUCCESS, remoteProjectManagerRepo.update(remoteProjectManager));
}

@RequestMapping(method = RequestMethod.DELETE)
@PreAuthorize("hasRole('USER')")
@WeaverValidation(business = { @WeaverValidation.Business(value = DELETE) })
public ApiResponse deleteRemoteProjectManager(@WeaverValidatedModel RemoteProjectManager remoteProjectManager) {
logger.info("Deleting Version Management Software: " + remoteProjectManager.getName());
logger.info("Deleting Remote Project Manager: " + remoteProjectManager.getName());
remoteProjectManagerRepo.delete(remoteProjectManager);
return new ApiResponse(SUCCESS);
}
Expand All @@ -81,4 +81,4 @@ public ApiResponse getTypeScaffolding(@PathVariable String type) {
return new ApiResponse(SUCCESS, serviceType.getScaffold());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import edu.tamu.app.model.response.RemoteProject;
import edu.tamu.app.rest.BasicAuthRestTemplate;
import edu.tamu.app.service.TemplateService;
import edu.tamu.app.utility.JsonNodeUtility;
import edu.tamu.app.utility.VersionOneJsonNodeUtility;

public class VersionOneService implements RemoteProjectManagerBean {

Expand All @@ -31,13 +31,13 @@ public VersionOneService(ManagementService managementService) {
@Override
public List<RemoteProject> getRemoteProjects() {
JsonNode response = restTemplate.getForObject(craftProjectsQueryUrl(), JsonNode.class);
return JsonNodeUtility.getVersionProjects(response.get("Assets"));
return VersionOneJsonNodeUtility.getRemoteProjects(response.get("Assets"));
}

@Override
public RemoteProject getRemoteProjectByScopeId(String scopeId) {
JsonNode asset = restTemplate.getForObject(craftProjectByScopeIdQueryUrl(scopeId), JsonNode.class);
String name = JsonNodeUtility.getVersionProjectName(asset);
String name = VersionOneJsonNodeUtility.getRemoteProjectName(asset);
return new RemoteProject(name, scopeId);
}

Expand Down Expand Up @@ -78,4 +78,4 @@ private String getSettingValue(String key) {
throw new RuntimeException("No setting " + key + " found in settings for service " + managementService.getName());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@

import edu.tamu.app.model.response.RemoteProject;

public class JsonNodeUtility {
public class VersionOneJsonNodeUtility {

public static String getVersionProjectName(JsonNode asset) {
public static String getRemoteProjectName(JsonNode asset) {
return asset.get("Attributes").get("Name").get("value").asText();
}

public static String getVersionProjectScopeId(JsonNode asset) {
public static String getRemoteProjectScopeId(JsonNode asset) {
return asset.get("id").asText().replaceAll("Scope:", "");
}

public static List<RemoteProject> getVersionProjects(JsonNode assets) {
public static List<RemoteProject> getRemoteProjects(JsonNode assets) {
List<RemoteProject> versionProjects = new ArrayList<RemoteProject>();
assets.forEach(asset -> {
String name = getVersionProjectName(asset);
String scopeId = getVersionProjectScopeId(asset);
String name = getRemoteProjectName(asset);
String scopeId = getRemoteProjectScopeId(asset);
versionProjects.add(new RemoteProject(name, scopeId));
});
return versionProjects;
}

}
}

0 comments on commit 56b94eb

Please sign in to comment.