Skip to content

Commit

Permalink
[OPENMEETINGS-2758] some Sonar issues are addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
solomax committed May 3, 2023
1 parent 4313f51 commit 33cee76
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.apache.openmeetings.web.util.GroupLogoResourceReference.getUrl;

import java.io.File;
import java.nio.file.Files;
import java.util.Optional;

import org.apache.openmeetings.core.converter.ImageConverter;
Expand Down Expand Up @@ -82,8 +83,8 @@ protected void processImage(StoredFile sf, File f) throws Exception {
protected void deleteImage() throws Exception {
Long groupId = GroupForm.this.getModelObject().getId();
File flogo = new File(getGroupLogoDir(), String.format("logo%s.png", groupId));
if (groupId != null && flogo.exists()) {
flogo.delete();
if (groupId != null) {
Files.deleteIfExists(flogo.toPath());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.apache.openmeetings.web.common.confirmation.ConfirmationHelper.newOkCancelConfirm;

import java.io.File;
import java.nio.file.Files;
import java.util.Optional;

import org.apache.openmeetings.util.StoredFile;
Expand Down Expand Up @@ -139,33 +140,39 @@ private void update(Optional<AjaxRequestTarget> target) {
target.ifPresent(t -> t.add(profile, form));
}

public void process(Optional<AjaxRequestTarget> target) {
if (delayed && Boolean.TRUE.equals(deleted.getModelObject())) {
private void processImage(FileUpload fu) {
if (fu != null) {
try {
deleteImage();
} catch (Exception e) {
log.error(ERROR, e);
}
} else {
FileUpload fu = fileUploadField.getFileUpload();
if (fu != null) {
File temp = null;
try {
temp = fu.writeToTempFile();
StoredFile sf = new StoredFile(fu.getClientFileName(), temp);
if (sf.isImage()) {
processImage(sf, temp);
}
} catch (Exception e) {
log.error(ERROR, e);
} finally {
if (temp != null && temp.exists()) {
log.debug("Temp file was deleted ? {}", temp.delete());
if (temp != null) {
log.debug("Temp file was deleted ? {}", Files.deleteIfExists(temp.toPath()));
}
fu.closeStreams();
fu.delete();
}
} catch (Exception e) {
log.error(ERROR, e);
}
}
}

public void process(Optional<AjaxRequestTarget> target) {
if (delayed && Boolean.TRUE.equals(deleted.getModelObject())) {
try {
deleteImage();
} catch (Exception e) {
log.error(ERROR, e);
}
} else {
FileUpload fu = fileUploadField.getFileUpload();
processImage(fu);
}
update(target);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const NetTest = (function() {
_initTests();
$('.nettest button[data-start="true"]').click()
}
function __repeat(options) {
function __cleanOptions(options) {
if (isNaN(options.attempts)) {
options.attempts = 0;
}
Expand All @@ -34,23 +34,29 @@ const NetTest = (function() {
options.results = [];
options.lresults = [];
}
}
function __stepsDone(options) {
if (--options.astep > 0) {
options.step = options.measures;
options.results.push(options.lresults);
options.lresults = [];
__repeat(options);
} else {
if (options.attempts > 0) {
options.results.push(options.lresults);
} else {
options.results = options.lresults;
}
options.onend(options.results);
}
}
function __repeat(options) {
__cleanOptions(options);
if (options.step < 0) {
return; //might happen in case of error
}
if (options.step === 0) {
if (--options.astep > 0) {
options.step = options.measures;
options.results.push(options.lresults);
options.lresults = [];
__repeat(options);
} else {
if (options.attempts > 0) {
options.results.push(options.lresults);
} else {
options.results = options.lresults;
}
options.onend(options.results);
}
__stepsDone(options);
} else {
options.action(options.params, res => {
if (res.ok) {
Expand Down

0 comments on commit 33cee76

Please sign in to comment.