|
|
@@ -1,5 +1,6 @@
|
|
|
package com.uas.report.axis.repository;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
import java.io.StringReader;
|
|
|
@@ -16,36 +17,69 @@ import java.util.Map.Entry;
|
|
|
import javax.activation.DataHandler;
|
|
|
import javax.activation.DataSource;
|
|
|
|
|
|
+import org.apache.axis.AxisFault;
|
|
|
import org.apache.axis.Message;
|
|
|
import org.apache.axis.MessageContext;
|
|
|
+import org.apache.axis.attachments.AttachmentPart;
|
|
|
import org.apache.axis.attachments.Attachments;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.InitializingBean;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.MessageSourceResolvable;
|
|
|
+import org.springframework.context.NoSuchMessageException;
|
|
|
+import org.springframework.context.support.DefaultMessageSourceResolvable;
|
|
|
+import org.springframework.context.support.ReloadableResourceBundleMessageSource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.validation.DefaultMessageCodesResolver;
|
|
|
+import org.springframework.validation.MessageCodesResolver;
|
|
|
|
|
|
+import com.uas.report.SpecialProperties;
|
|
|
import com.uas.report.axis.Argument;
|
|
|
-import com.uas.report.axis.FileHelper;
|
|
|
-import com.uas.report.axis.FileResource;
|
|
|
-import com.uas.report.axis.Folder;
|
|
|
import com.uas.report.axis.ListItem;
|
|
|
import com.uas.report.axis.OperationResult;
|
|
|
import com.uas.report.axis.Request;
|
|
|
import com.uas.report.axis.Resource;
|
|
|
import com.uas.report.axis.ResourceDescriptor;
|
|
|
+import com.uas.report.axis.BasicResourceHandler;
|
|
|
+import com.uas.report.axis.ResourceHandlerRegistry;
|
|
|
import com.uas.report.axis.ResultAttachments;
|
|
|
+import com.uas.report.axis.ValidationError;
|
|
|
+import com.uas.report.axis.ValidationErrors;
|
|
|
+import com.uas.report.axis.WSException;
|
|
|
+import com.uas.report.axis.WSValidationException;
|
|
|
import com.uas.report.axis.util.Marshaller;
|
|
|
import com.uas.report.axis.util.Unmarshaller;
|
|
|
|
|
|
@Service
|
|
|
-public class RepositoryManagementServiceImpl implements RepositoryManagementService {
|
|
|
+public class RepositoryManagementServiceImpl implements RepositoryManagementService, InitializingBean {
|
|
|
|
|
|
private static final String VERSION = "2.0.1";
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SpecialProperties specialProperties;
|
|
|
+
|
|
|
private Locale locale = null; // Default locale....
|
|
|
|
|
|
+ private ResourceHandlerRegistry resourceHandlerRegistry;
|
|
|
+
|
|
|
+ private BasicResourceHandler basicResourceHandler = new BasicResourceHandler();
|
|
|
+
|
|
|
+ private ReloadableResourceBundleMessageSource messageSource;
|
|
|
+
|
|
|
+ private String attachmentsPath = specialProperties.getLocalBaseDir() + "/tmp/jasperserver/axis_attachments";
|
|
|
+
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
+ @Override
|
|
|
+ public void afterPropertiesSet() throws Exception {
|
|
|
+ resourceHandlerRegistry = new ResourceHandlerRegistry();
|
|
|
+ messageSource = new ReloadableResourceBundleMessageSource();
|
|
|
+ messageSource.setUseCodeAsDefaultMessage(true);
|
|
|
+ messageSource.setFallbackToSystemLocale(false);
|
|
|
+ messageSource.setBasenames("bundlePathsListCe");
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public String list(String requestXmlString) {
|
|
|
OperationResult operationResult = new OperationResult();
|
|
|
@@ -137,7 +171,7 @@ public class RepositoryManagementServiceImpl implements RepositoryManagementServ
|
|
|
}
|
|
|
} else if (request.getResourceDescriptor().getWsType().equals(ResourceDescriptor.TYPE_FOLDER)) {
|
|
|
logger.debug("List folders");
|
|
|
- list = listResources(request.getResourceDescriptor().getUriString());
|
|
|
+ list = basicResourceHandler.listResourceDescriptors(request.getResourceDescriptor().getUriString());
|
|
|
} else if (request.getResourceDescriptor().getWsType().equals(ResourceDescriptor.TYPE_REPORTUNIT)) {
|
|
|
/*
|
|
|
* logger.debug("List report units"); list =
|
|
|
@@ -199,22 +233,26 @@ public class RepositoryManagementServiceImpl implements RepositoryManagementServ
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-// if (params.size() > 0 && specialOptions.containsKey(Argument.RU_REF_URI)) {
|
|
|
-// ResourceDescriptor reportDescriptior = createResourceDescriptor(
|
|
|
-// (String) specialOptions.get(Argument.RU_REF_URI));
|
|
|
-// specialOptions.put(Argument.PARAMS_ARG, buildParameterMap(params, reportDescriptior));
|
|
|
-// }
|
|
|
+ // if (params.size() > 0 &&
|
|
|
+ // specialOptions.containsKey(Argument.RU_REF_URI)) {
|
|
|
+ // ResourceDescriptor reportDescriptior = createResourceDescriptor(
|
|
|
+ // (String) specialOptions.get(Argument.RU_REF_URI));
|
|
|
+ // specialOptions.put(Argument.PARAMS_ARG, buildParameterMap(params,
|
|
|
+ // reportDescriptior));
|
|
|
+ // }
|
|
|
|
|
|
String resourceURI = request.getResourceDescriptor().getUriString();
|
|
|
- Resource resource = FileHelper.locateResource(resourceURI);
|
|
|
+ Resource resource = basicResourceHandler.locateResource(resourceURI);
|
|
|
if (resource == null) {
|
|
|
logger.warn("Get: null resourceDescriptor for " + resourceURI);
|
|
|
operationResult.setReturnCode(2);
|
|
|
-// operationResult
|
|
|
-// .setMessage(messageSource.getMessage("webservices.error.resourceNotFound", null, getLocale()));
|
|
|
+ // operationResult
|
|
|
+ // .setMessage(messageSource.getMessage("webservices.error.resourceNotFound",
|
|
|
+ // null, getLocale()));
|
|
|
} else {
|
|
|
-// ResourceDescriptor rd = createResourceDescriptor(resource, processDescriptorOptions(specialOptions));
|
|
|
- ResourceDescriptor rd = createResourceDescriptor(resource);
|
|
|
+ // ResourceDescriptor rd = createResourceDescriptor(resource,
|
|
|
+ // processDescriptorOptions(specialOptions));
|
|
|
+ ResourceDescriptor rd = basicResourceHandler.toResourceDescriptor(resource);
|
|
|
|
|
|
logger.debug("Get: " + resourceURI + ", wsType: " + rd.getWsType() + ", resourceType: "
|
|
|
+ rd.getResourceType());
|
|
|
@@ -223,13 +261,16 @@ public class RepositoryManagementServiceImpl implements RepositoryManagementServ
|
|
|
ResultAttachments attachments = new ResultAttachments();
|
|
|
attachments
|
|
|
.setEncapsulationDime(getArgumentValue("USE_DIME_ATTACHMENTS", request.getArguments()) != null);
|
|
|
-// ResourceHandler handler = getHandlerRegistry().getHandler(rd.getWsType());
|
|
|
-// handler.getAttachments(resource, specialOptions, rd, attachments, this);
|
|
|
-// if (operationResult.getReturnCode() != 0) {
|
|
|
-// addExceptionToAllAuditEvents(new Exception(operationResult.getMessage()));
|
|
|
-// }
|
|
|
-//
|
|
|
-// return marshalResponse(operationResult, attachments);
|
|
|
+ // ResourceHandler handler =
|
|
|
+ // getHandlerRegistry().getHandler(rd.getWsType());
|
|
|
+ // handler.getAttachments(resource, specialOptions, rd,
|
|
|
+ // attachments, this);
|
|
|
+ // if (operationResult.getReturnCode() != 0) {
|
|
|
+ // addExceptionToAllAuditEvents(new
|
|
|
+ // Exception(operationResult.getMessage()));
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // return marshalResponse(operationResult, attachments);
|
|
|
return marshalResponse(operationResult);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -246,8 +287,53 @@ public class RepositoryManagementServiceImpl implements RepositoryManagementServ
|
|
|
|
|
|
@Override
|
|
|
public String put(String requestXmlString) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- return null;
|
|
|
+ OperationResult operationResult = new OperationResult();
|
|
|
+ operationResult.setVersion(VERSION);
|
|
|
+ try {
|
|
|
+ StringReader xmlStringReader = new StringReader(requestXmlString);
|
|
|
+ Request request = (Request) Unmarshaller.unmarshal(xmlStringReader);
|
|
|
+ // createAuditEvent(request.getOperationName(),
|
|
|
+ // request.getResourceDescriptor().getWsType(),
|
|
|
+ // request.getResourceDescriptor().isNew());
|
|
|
+ setLocale(request.getLocale());
|
|
|
+
|
|
|
+ ResourceDescriptor newDescriptor = request.getResourceDescriptor();
|
|
|
+
|
|
|
+ logger.debug("Put: for " + newDescriptor.getUriString());
|
|
|
+
|
|
|
+ if (newDescriptor.getUriString() == null || newDescriptor.getUriString().length() == 0) {
|
|
|
+ throw new WSException(WSException.GENERAL_REQUEST_ERROR,
|
|
|
+ messageSource.getMessage("webservices.error.noUriGiven", null, getLocale()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (newDescriptor.getWsType() == null || newDescriptor.getWsType().length() == 0) {
|
|
|
+ throw new WSException(WSException.GENERAL_REQUEST_ERROR,
|
|
|
+ messageSource.getMessage("webservices.error.noTypeGiven", null, getLocale()));
|
|
|
+ }
|
|
|
+
|
|
|
+ String wsType = newDescriptor.getWsType();
|
|
|
+ BasicResourceHandler handler = resourceHandlerRegistry.getHandler(wsType);
|
|
|
+ operationResult.getResourceDescriptors().add(handler.put(request));
|
|
|
+
|
|
|
+ } catch (WSValidationException e) {
|
|
|
+ logger.error("caught validation exception: " + e.getMessage(), e);
|
|
|
+
|
|
|
+ operationResult.setReturnCode(e.getErrorCode());
|
|
|
+ operationResult.setMessage(getValidationErrorMessage(e.getObjectName(), e.getErrors()));
|
|
|
+ } catch (WSException e) {
|
|
|
+ operationResult.setReturnCode(e.getErrorCode());
|
|
|
+ operationResult.setMessage(e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ // e.printStackTrace();
|
|
|
+ logger.error("caught exception: " + e.getMessage(), e);
|
|
|
+
|
|
|
+ operationResult.setReturnCode(1);
|
|
|
+ operationResult.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+ logger.debug("Marshalling response");
|
|
|
+
|
|
|
+ return marshalResponse(operationResult);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -274,6 +360,49 @@ public class RepositoryManagementServiceImpl implements RepositoryManagementServ
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Function to get attachments from an Axis message
|
|
|
+ * @throws WSException
|
|
|
+ * @throws NoSuchMessageException
|
|
|
+ * @throws AxisFault
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public AttachmentPart[] getMessageAttachments() throws NoSuchMessageException, WSException, AxisFault {
|
|
|
+ try {
|
|
|
+ MessageContext msgContext = MessageContext.getCurrentContext();
|
|
|
+ File file = new File(attachmentsPath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdirs();
|
|
|
+ }
|
|
|
+ msgContext.setProperty(MessageContext.ATTACHMENTS_DIR, attachmentsPath);
|
|
|
+ Message reqMsg = msgContext.getRequestMessage();
|
|
|
+ Attachments messageAttachments = reqMsg.getAttachmentsImpl();
|
|
|
+ if (null == messageAttachments) {
|
|
|
+ logger.error("no attachment support");
|
|
|
+ return new AttachmentPart[0];
|
|
|
+ }
|
|
|
+ int attachmentCount = messageAttachments.getAttachmentCount();
|
|
|
+ AttachmentPart attachments[] = new AttachmentPart[attachmentCount];
|
|
|
+
|
|
|
+ Iterator<?> it = messageAttachments.getAttachments().iterator();
|
|
|
+ int count = 0;
|
|
|
+ while (it.hasNext()) {
|
|
|
+ AttachmentPart part = (AttachmentPart) it.next();
|
|
|
+ attachments[count++] = part;
|
|
|
+ }
|
|
|
+ return attachments;
|
|
|
+ } catch (AxisFault e) {
|
|
|
+ if (e.getFaultString().startsWith("java.io.IOException")) {
|
|
|
+// throw new JSExceptionWrapper(new WSException(WSException.GENERAL_ERROR,
|
|
|
+// messageSource.getMessage("webservices.error.attachments.folder", null, getLocale())));
|
|
|
+ throw new WSException(WSException.GENERAL_ERROR,
|
|
|
+ messageSource.getMessage("webservices.error.attachments.folder", null, getLocale()));
|
|
|
+ }
|
|
|
+// throw new JSExceptionWrapper(e);
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public Locale getLocale() {
|
|
|
return locale;
|
|
|
}
|
|
|
@@ -394,82 +523,35 @@ public class RepositoryManagementServiceImpl implements RepositoryManagementServ
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Return a list of ResourceDescriptor(s)
|
|
|
- * @throws IOException
|
|
|
- * @throws FileNotFoundException
|
|
|
- *
|
|
|
- * @throws WSException
|
|
|
- */
|
|
|
- public List<ResourceDescriptor> listResources(String uri) throws FileNotFoundException, IOException {
|
|
|
- logger.debug("list for uri: " + uri);
|
|
|
-
|
|
|
- List<ResourceDescriptor> returnedMaps = new ArrayList<>();
|
|
|
-
|
|
|
- List<Resource> resources = FileHelper.listResource(uri);
|
|
|
- if(CollectionUtils.isEmpty(resources)){
|
|
|
- return returnedMaps;
|
|
|
- }
|
|
|
- for(Resource resource :resources){
|
|
|
- returnedMaps.add(createResourceDescriptor(resource));
|
|
|
+ protected String getValidationErrorMessage(String objectName, ValidationErrors errors) {
|
|
|
+ StringBuffer message = new StringBuffer();
|
|
|
+ List<ValidationError> errorList = errors.getErrors();
|
|
|
+ message.append(getMessage("webservices.error.validation.errors.prefix",
|
|
|
+ new Object[] { new Integer(errorList.size()) }));
|
|
|
+ message.append("\n");
|
|
|
+ for (Iterator<ValidationError> it = errorList.iterator(); it.hasNext();) {
|
|
|
+ ValidationError error = (ValidationError) it.next();
|
|
|
+ message.append(getValidationErrorMessage(objectName, error));
|
|
|
+ message.append("\n");
|
|
|
}
|
|
|
-
|
|
|
- /*
|
|
|
- * // This filters with object level security. // Will only get folders
|
|
|
- * the user has access to
|
|
|
- *
|
|
|
- * List<Resource> folders = getRepository().getSubFolders(null, uri);
|
|
|
- * filterFolderList(folders);
|
|
|
- *
|
|
|
- * if (folders == null) return returnedMaps;
|
|
|
- *
|
|
|
- * for (int i = 0; i < folders.size(); ++i) { Resource folderRes =
|
|
|
- * folders.get(i);
|
|
|
- * returnedMaps.add(createResourceDescriptor(folderRes)); }
|
|
|
- *
|
|
|
- * // create a criteria for finding things with a common parent folder.
|
|
|
- * FilterCriteria filterCriteria = new FilterCriteria();
|
|
|
- * filterCriteria.addFilterElement(FilterCriteria.
|
|
|
- * createParentFolderFilter(uri));
|
|
|
- *
|
|
|
- * // This filters with object level security // Will only get resources
|
|
|
- * the user has access to
|
|
|
- *
|
|
|
- * List units = getRepository().loadClientResources(filterCriteria);
|
|
|
- *
|
|
|
- * if (units == null) return returnedMaps;
|
|
|
- *
|
|
|
- * for (Iterator it = units.iterator(); units != null && it.hasNext();)
|
|
|
- * { Resource fileRes = (Resource) it.next(); try {
|
|
|
- * returnedMaps.add(createResourceDescriptor(fileRes)); } catch
|
|
|
- * (Exception ex) { logger.error(ex); } }
|
|
|
- */
|
|
|
-
|
|
|
- return returnedMaps;
|
|
|
+ return message.toString();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * the same as createResourceDescriptor( resource, false)
|
|
|
- */
|
|
|
- public ResourceDescriptor createResourceDescriptor(Resource resource) {
|
|
|
- ResourceDescriptor descriptor = new ResourceDescriptor();
|
|
|
- if(resource instanceof Folder){
|
|
|
- descriptor.setWsType(ResourceDescriptor.TYPE_FOLDER);
|
|
|
- descriptor.setHasData(false);
|
|
|
- }else if(resource instanceof FileResource){
|
|
|
- FileResource fileResource=(FileResource)resource;
|
|
|
- descriptor.setWsType(fileResource.getFileType());
|
|
|
- descriptor.setHasData(fileResource.hasData());
|
|
|
+ protected Object getValidationErrorMessage(String objectName, ValidationError error) {
|
|
|
+ MessageCodesResolver codesResolver = new DefaultMessageCodesResolver();
|
|
|
+ String[] codes;
|
|
|
+ if (error.getField() == null) {
|
|
|
+ codes = codesResolver.resolveMessageCodes(error.getErrorCode(), objectName);
|
|
|
+ } else {
|
|
|
+ codes = codesResolver.resolveMessageCodes(error.getErrorCode(), objectName, error.getField(), null);
|
|
|
}
|
|
|
- descriptor.setUriString(resource.getURIString());
|
|
|
- descriptor.setDescription(resource.getDescription());
|
|
|
- descriptor.setLabel(resource.getLabel());
|
|
|
- descriptor.setName(resource.getName());
|
|
|
- descriptor.setResourceType(resource.getResourceType());
|
|
|
- descriptor.setParentFolder(resource.getParentFolder());
|
|
|
- descriptor.setVersion(resource.getVersion());
|
|
|
- descriptor.setCreationDate(resource.getCreationDate());
|
|
|
- return descriptor;
|
|
|
+ MessageSourceResolvable messageResolvable = new DefaultMessageSourceResolvable(codes, error.getErrorArguments(),
|
|
|
+ error.getDefaultMessage());
|
|
|
+ String message = messageSource.getMessage(messageResolvable, getLocale());
|
|
|
+ return message;
|
|
|
}
|
|
|
|
|
|
+ public String getMessage(String messageCode, Object[] args) {
|
|
|
+ return messageSource.getMessage(messageCode, args, getLocale());
|
|
|
+ }
|
|
|
}
|