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

update of projectId and id fields fixed

parent ff19edd8
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 {
throw new SecurityException("You cannot update projects");
}
Set<String> fields = data.keySet();
for (String string : fields) {
if (string.equalsIgnoreCase("version")) {
project.setVersion((String) data.get(string));
} else if (string.equalsIgnoreCase("id")) {
for (String fieldName : fields) {
Object value = data.get(fieldName);
String stringValue = null;
if (value instanceof String) {
stringValue = (String) value;
}
if (fieldName.equalsIgnoreCase("version")) {
project.setVersion((String) value);
} else if (fieldName.equalsIgnoreCase("id")) {
try {
int id = Integer.parseInt(string);
int id = Integer.parseInt(stringValue);
if (id != project.getId()) {
throw new QueryException("Invalid id: " + string);
throw new QueryException("Invalid id: " + stringValue);
}
} catch (NumberFormatException e) {
throw new QueryException("Invalid id: " + string);
throw new QueryException("Invalid id: " + stringValue);
}
} else if (string.equalsIgnoreCase("projectId")) {
if (!project.getProjectId().equalsIgnoreCase(string)) {
} else if (fieldName.equalsIgnoreCase("projectId")) {
if (!project.getProjectId().equalsIgnoreCase(stringValue)) {
throw new QueryException("You cannot modify projectId");
}
} else if (string.equalsIgnoreCase("name")) {
project.setName((String) data.get(string));
} else if (string.equalsIgnoreCase("notifyEmail")) {
project.setNotifyEmail((String) data.get(string));
} else if (string.equalsIgnoreCase("organism")) {
Object res = data.get(string);
MiriamData organism = updateMiriamData(project.getOrganism(), res);
} else if (fieldName.equalsIgnoreCase("name")) {
project.setName((String) value);
} else if (fieldName.equalsIgnoreCase("notifyEmail")) {
project.setNotifyEmail(stringValue);
} else if (fieldName.equalsIgnoreCase("organism")) {
MiriamData organism = updateMiriamData(project.getOrganism(), value);
project.setOrganism(organism);
} else if (string.equalsIgnoreCase("disease")) {
Object res = data.get(string);
MiriamData disease = updateMiriamData(project.getDisease(), res);
} else if (fieldName.equalsIgnoreCase("disease")) {
MiriamData disease = updateMiriamData(project.getDisease(), value);
project.setDisease(disease);
} else {
throw new QueryException("Unknown field: " + string);
throw new QueryException("Unknown field: " + fieldName);
}
}
getProjectService().updateProject(project);
......
......@@ -174,6 +174,8 @@ public class ProjectRestImplTest extends RestTestFunctions {
data.put("name", "test");
data.put("organism", null);
data.put("disease", disease);
data.put("projectId", "sample");
data.put("id", "0");
projectRest.updateProject(adminToken.getId(), "sample", data);
} catch (Exception e) {
e.printStackTrace();
......@@ -236,6 +238,7 @@ public class ProjectRestImplTest extends RestTestFunctions {
project = new Project();
model = super.getModelForFile(string, true);
project.addModel(model);
project.setProjectId(model.getName());
}
IModelService mockModelService = Mockito.mock(IModelService.class);
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