Fix widget marker images processing; suppress image processing errors
This commit is contained in:
parent
0f4061e34a
commit
f732631fd1
@ -26,6 +26,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.Base64Utils;
|
import org.springframework.util.Base64Utils;
|
||||||
import org.thingsboard.common.util.JacksonUtil;
|
import org.thingsboard.common.util.JacksonUtil;
|
||||||
import org.thingsboard.server.common.data.Dashboard;
|
import org.thingsboard.server.common.data.Dashboard;
|
||||||
@ -261,6 +263,7 @@ public class BaseImageService extends BaseResourceService implements ImageServic
|
|||||||
return resourceInfoDao.findByTenantIdAndEtag(tenantId, ResourceType.IMAGE, etag);
|
return resourceInfoDao.findByTenantIdAndEtag(tenantId, ResourceType.IMAGE, etag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)// we don't want transaction to rollback in case of an image processing failure
|
||||||
@Override
|
@Override
|
||||||
public boolean replaceBase64WithImageUrl(HasImage entity, String type) {
|
public boolean replaceBase64WithImageUrl(HasImage entity, String type) {
|
||||||
String imageName = "\"" + entity.getName() + "\" ";
|
String imageName = "\"" + entity.getName() + "\" ";
|
||||||
@ -274,6 +277,7 @@ public class BaseImageService extends BaseResourceService implements ImageServic
|
|||||||
return result.isUpdated();
|
return result.isUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)// we don't want transaction to rollback in case of an image processing failure
|
||||||
@Override
|
@Override
|
||||||
public boolean replaceBase64WithImageUrl(WidgetTypeDetails entity) {
|
public boolean replaceBase64WithImageUrl(WidgetTypeDetails entity) {
|
||||||
String prefix = "\"" + entity.getName() + "\" ";
|
String prefix = "\"" + entity.getName() + "\" ";
|
||||||
@ -298,6 +302,7 @@ public class BaseImageService extends BaseResourceService implements ImageServic
|
|||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)// we don't want transaction to rollback in case of an image processing failure
|
||||||
@Override
|
@Override
|
||||||
public boolean replaceBase64WithImageUrl(Dashboard entity) {
|
public boolean replaceBase64WithImageUrl(Dashboard entity) {
|
||||||
String prefix = "\"" + entity.getTitle() + "\" dashboard";
|
String prefix = "\"" + entity.getTitle() + "\" dashboard";
|
||||||
@ -437,7 +442,12 @@ public class BaseImageService extends BaseResourceService implements ImageServic
|
|||||||
image.setFileName(fileName);
|
image.setFileName(fileName);
|
||||||
image.setDescriptor(JacksonUtil.newObjectNode().put("mediaType", mdMediaType));
|
image.setDescriptor(JacksonUtil.newObjectNode().put("mediaType", mdMediaType));
|
||||||
image.setData(imageData);
|
image.setData(imageData);
|
||||||
|
try {
|
||||||
imageInfo = saveImage(image);
|
imageInfo = saveImage(image);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("[{}][{}] Failed to replace Base64 with image url: {}", tenantId, name, StringUtils.abbreviate(data, 50), e);
|
||||||
|
return UpdateResult.of(false, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return UpdateResult.of(true, DataConstants.TB_IMAGE_PREFIX + imageInfo.getLink());
|
return UpdateResult.of(true, DataConstants.TB_IMAGE_PREFIX + imageInfo.getLink());
|
||||||
}
|
}
|
||||||
@ -468,12 +478,15 @@ public class BaseImageService extends BaseResourceService implements ImageServic
|
|||||||
}
|
}
|
||||||
} else if (node.isArray()) {
|
} else if (node.isArray()) {
|
||||||
ArrayNode childArray = (ArrayNode) node;
|
ArrayNode childArray = (ArrayNode) node;
|
||||||
int i = 0;
|
for (int i = 0; i < childArray.size(); i++) {
|
||||||
for (JsonNode element : childArray) {
|
JsonNode element = childArray.get(i);
|
||||||
if (element.isObject()) {
|
if (element.isObject()) {
|
||||||
tasks.add(new JsonNodeProcessingTask(currentPath + " " + i, element));
|
tasks.add(new JsonNodeProcessingTask(currentPath + " " + i, element));
|
||||||
|
} else if (element.isTextual()) {
|
||||||
|
UpdateResult result = base64ToImageUrl(tenantId, currentPath + "." + i, element.asText(), true);
|
||||||
|
childArray.set(i, result.getValue());
|
||||||
|
updated |= result.isUpdated();
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -503,6 +516,9 @@ public class BaseImageService extends BaseResourceService implements ImageServic
|
|||||||
while (!tasks.isEmpty()) {
|
while (!tasks.isEmpty()) {
|
||||||
JsonNodeProcessingTask task = tasks.poll();
|
JsonNodeProcessingTask task = tasks.poll();
|
||||||
JsonNode node = task.getNode();
|
JsonNode node = task.getNode();
|
||||||
|
if (node == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
String currentPath = StringUtils.isBlank(task.getPath()) ? "" : (task.getPath() + ".");
|
String currentPath = StringUtils.isBlank(task.getPath()) ? "" : (task.getPath() + ".");
|
||||||
if (node.isObject()) {
|
if (node.isObject()) {
|
||||||
ObjectNode on = (ObjectNode) node;
|
ObjectNode on = (ObjectNode) node;
|
||||||
@ -517,12 +533,13 @@ public class BaseImageService extends BaseResourceService implements ImageServic
|
|||||||
}
|
}
|
||||||
} else if (node.isArray()) {
|
} else if (node.isArray()) {
|
||||||
ArrayNode childArray = (ArrayNode) node;
|
ArrayNode childArray = (ArrayNode) node;
|
||||||
int i = 0;
|
for (int i = 0; i < childArray.size(); i++) {
|
||||||
for (JsonNode element : childArray) {
|
JsonNode element = childArray.get(i);
|
||||||
if (element.isObject()) {
|
if (element.isObject()) {
|
||||||
tasks.add(new JsonNodeProcessingTask(currentPath + "." + i, element));
|
tasks.add(new JsonNodeProcessingTask(currentPath + "." + i, element));
|
||||||
|
} else if (element.isTextual()) {
|
||||||
|
childArray.set(i, inlineImage(tenantId, currentPath + "." + i, element.asText()));
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user