Skip to content
Snippets Groups Projects
Commit 85b07d4c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

update of projectId and id fields fixed

parent dab3713e
No related branches found
No related tags found
2 merge requests!115Resolve "admin panel should use API",!114Resolve "admin panel should use API"
...@@ -409,36 +409,39 @@ public class ProjectRestImpl extends BaseRestImpl { ...@@ -409,36 +409,39 @@ public class ProjectRestImpl extends BaseRestImpl {
throw new SecurityException("You cannot update projects"); throw new SecurityException("You cannot update projects");
} }
Set<String> fields = data.keySet(); Set<String> fields = data.keySet();
for (String string : fields) { for (String fieldName : fields) {
if (string.equalsIgnoreCase("version")) { Object value = data.get(fieldName);
project.setVersion((String) data.get(string)); String stringValue = null;
} else if (string.equalsIgnoreCase("id")) { if (value instanceof String) {
stringValue = (String) value;
}
if (fieldName.equalsIgnoreCase("version")) {
project.setVersion((String) value);
} else if (fieldName.equalsIgnoreCase("id")) {
try { try {
int id = Integer.parseInt(string); int id = Integer.parseInt(stringValue);
if (id != project.getId()) { if (id != project.getId()) {
throw new QueryException("Invalid id: " + string); throw new QueryException("Invalid id: " + stringValue);
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new QueryException("Invalid id: " + string); throw new QueryException("Invalid id: " + stringValue);
} }
} else if (string.equalsIgnoreCase("projectId")) { } else if (fieldName.equalsIgnoreCase("projectId")) {
if (!project.getProjectId().equalsIgnoreCase(string)) { if (!project.getProjectId().equalsIgnoreCase(stringValue)) {
throw new QueryException("You cannot modify projectId"); throw new QueryException("You cannot modify projectId");
} }
} else if (string.equalsIgnoreCase("name")) { } else if (fieldName.equalsIgnoreCase("name")) {
project.setName((String) data.get(string)); project.setName((String) value);
} else if (string.equalsIgnoreCase("notifyEmail")) { } else if (fieldName.equalsIgnoreCase("notifyEmail")) {
project.setNotifyEmail((String) data.get(string)); project.setNotifyEmail(stringValue);
} else if (string.equalsIgnoreCase("organism")) { } else if (fieldName.equalsIgnoreCase("organism")) {
Object res = data.get(string); MiriamData organism = updateMiriamData(project.getOrganism(), value);
MiriamData organism = updateMiriamData(project.getOrganism(), res);
project.setOrganism(organism); project.setOrganism(organism);
} else if (string.equalsIgnoreCase("disease")) { } else if (fieldName.equalsIgnoreCase("disease")) {
Object res = data.get(string); MiriamData disease = updateMiriamData(project.getDisease(), value);
MiriamData disease = updateMiriamData(project.getDisease(), res);
project.setDisease(disease); project.setDisease(disease);
} else { } else {
throw new QueryException("Unknown field: " + string); throw new QueryException("Unknown field: " + fieldName);
} }
} }
getProjectService().updateProject(project); getProjectService().updateProject(project);
......
...@@ -174,6 +174,8 @@ public class ProjectRestImplTest extends RestTestFunctions { ...@@ -174,6 +174,8 @@ public class ProjectRestImplTest extends RestTestFunctions {
data.put("name", "test"); data.put("name", "test");
data.put("organism", null); data.put("organism", null);
data.put("disease", disease); data.put("disease", disease);
data.put("projectId", "sample");
data.put("id", "0");
projectRest.updateProject(adminToken.getId(), "sample", data); projectRest.updateProject(adminToken.getId(), "sample", data);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -236,6 +238,7 @@ public class ProjectRestImplTest extends RestTestFunctions { ...@@ -236,6 +238,7 @@ public class ProjectRestImplTest extends RestTestFunctions {
project = new Project(); project = new Project();
model = super.getModelForFile(string, true); model = super.getModelForFile(string, true);
project.addModel(model); project.addModel(model);
project.setProjectId(model.getName());
} }
IModelService mockModelService = Mockito.mock(IModelService.class); IModelService mockModelService = Mockito.mock(IModelService.class);
Mockito.when(mockModelService.getLastModelByProjectId(anyString(), any())).thenReturn(model); Mockito.when(mockModelService.getLastModelByProjectId(anyString(), any())).thenReturn(model);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment