Skip to content

Commit

Permalink
export/import should work, tests needed
Browse files Browse the repository at this point in the history
  • Loading branch information
DLindenbauer committed Jan 21, 2017
1 parent 9252d8d commit 00ea74e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public UploadHardwareBackupServlet(UserManager userManager, LoginUriProvider log
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
super.doGet(request, response);
pageBuilderService.assembler().resources().requireWebResource("org.catrobat.jira.adminhelper:upload-hardware-resources");
renderer.render("upload.vm", response.getWriter());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public boolean ImportDevices(JsonDeviceList deviceList)
hd = hardwareModelService.add(json_hardware.getName(),json_hardware.getTypeOfDevice(),
json_hardware.getVersion(), json_hardware.getPrice(),json_hardware.getProducer(),
json_hardware.getOperatingSystem(),json_hardware.getArticleNumber());
System.out.println("after new model creation id is:");
System.out.println(hd.getID());
hardware_model_mapping.put(d.getHardwareModelId(), hd.getID());
}
Expand All @@ -68,15 +67,13 @@ public boolean ImportDevices(JsonDeviceList deviceList)
Lending temp = lendingService.lendOut(current_device,lending.getLentOutBy(), lending.getLentOutIssuer(),
lending.getPurpose(), lending.getComment(), lending.getBegin());
if(lending.getEnd() != null) {
System.out.println("device has been lent out and returned");
lendingService.bringBack(temp, lending.getPurpose(), lending.getComment(), lending.getEnd());
}
}

for(JsonDeviceComment comment : comments)
{
if(comment.getDate() != null) {
System.out.println("device has a date");
if(comment.getDate() != null) {;
deviceCommentService.addDeviceComment(current_device, comment.getAuthor(), comment.getComment(),
comment.getDate());
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/atlassian-plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
<context>general</context>
</web-resource>


<web-resource name="Upload Resources" key="upload-hardware-resources">
<resource type="download" name="upload.js" location="js/upload.js"/>
<context>admin</context>
</web-resource>


<servlet key="create-user-servlet" class="org.catrobat.jira.adminhelper.CreateUserServlet">
<url-pattern>/admin_helper/create_user</url-pattern>
</servlet>
Expand Down
29 changes: 29 additions & 0 deletions src/main/resources/js/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Created by dominik on 21.01.17.
*/
AJS.toInit(function () {
var file = undefined;

AJS.$('#upload-field').change(function () {
file = AJS.$("#upload-field").value;
});

AJS.$("#post-inputs").click(function () {
console.log("about to post inputs");
if(file === undefined) {
AJS.messages.error({
title: "Error !",
body: "Select a Hardware Backup Zip-File to proceed!"
})
}
else {
if(!file.contains(".zip")){
AJS.messages.error({
title: "Error !",
body: "The Datatype of the Backup must be .zip!"
})
}
AJS.$("#upload-form").submit();
}
})
});
6 changes: 3 additions & 3 deletions src/main/resources/upload.vm
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
<li>device.JSON</li>
</ul> <br>
<p>If the given Backup does not include the files described above, the backup wil be rejected.</p>
<form class="aui" method="POST" enctype="multipart/form-data">
<form class="aui" method="POST" enctype="multipart/form-data" id="upload-form">
<fieldset>
<div class="field-group">
<input class="upfile" type="file" name="upload_field"/>
<input class="upfile" type="file" name="upload_field" id="upload-field"/>
</div>
<div class="field-group">
<input type="submit" value="Submit" class="aui-button aui-button-primary">
<input type="button" value="Submit" class="aui-button aui-button-primary" id="post-inputs">
</div>
</fieldset>
</form>
Expand Down

0 comments on commit 00ea74e

Please sign in to comment.