1 package org.kuali.student.lum.lu.ui.tools.server.gwt;
2
3 import java.util.Map;
4
5 import org.apache.log4j.Logger;
6 import org.kuali.student.common.ui.client.service.DataSaveResult;
7 import org.kuali.student.common.ui.server.gwt.DataService;
8 import org.kuali.student.common.ui.shared.IdAttributes;
9 import org.kuali.student.core.assembly.data.AssemblyException;
10 import org.kuali.student.core.assembly.data.Data;
11 import org.kuali.student.core.assembly.data.Metadata;
12 import org.kuali.student.core.assembly.dictionary.MetadataServiceImpl;
13 import org.kuali.student.core.assembly.old.Assembler;
14 import org.kuali.student.core.assembly.old.data.SaveResult;
15 import org.kuali.student.core.assembly.transform.MetadataFilter;
16 import org.kuali.student.core.assembly.transform.TransformFilter;
17 import org.kuali.student.core.exceptions.DataValidationErrorException;
18 import org.kuali.student.core.exceptions.DoesNotExistException;
19 import org.kuali.student.core.exceptions.InvalidParameterException;
20 import org.kuali.student.core.exceptions.MissingParameterException;
21 import org.kuali.student.core.exceptions.OperationFailedException;
22 import org.kuali.student.core.rice.authorization.PermissionType;
23
24 public class CluSetDataService implements DataService{
25
26 final static Logger LOG = Logger.getLogger(CluSetDataService.class);
27 private Assembler<Data, Void> assembler;
28 private MetadataServiceImpl metadataService;
29
30 public MetadataServiceImpl getMetadataService() {
31 return metadataService;
32 }
33
34 public void setMetadataService(MetadataServiceImpl metadataService) {
35 this.metadataService = metadataService;
36 }
37
38 public Assembler<Data, Void> getAssembler() {
39 return assembler;
40 }
41
42 public void setAssembler(Assembler<Data, Void> assembler) {
43 this.assembler = assembler;
44 }
45
46 @Override
47 public Data getData(String dataId) throws OperationFailedException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
48 Data result = null;
49 try {
50 result = assembler.get(dataId);
51 } catch (Exception e){
52 throw new OperationFailedException("Failed to retrieve data from id " + dataId, e);
53 }
54 return result;
55 }
56
57 @Override
58 public Metadata getMetadata(String id, Map<String,String> idAttributes) {
59 Metadata metadata = metadataService.getMetadata(id);
60 return metadata;
61 }
62
63 protected String getDefaultMetaDataType() {
64 return null;
65 }
66
67 protected String getDefaultMetaDataState() {
68 return null;
69 }
70
71 @Override
72 public Boolean isAuthorized(PermissionType type, Map<String, String> attributes) {
73 return new Boolean(true);
74 }
75
76 @Override
77 public DataSaveResult saveData(Data data) throws OperationFailedException, DataValidationErrorException {
78 try {
79 SaveResult<Data> saveResult = assembler.save(data);
80 if (saveResult != null) {
81 return new DataSaveResult(saveResult.getValidationResults(), saveResult.getValue());
82 }
83 } catch (Exception e) {
84 LOG.error("Unable to save", e);
85 throw new OperationFailedException("Unable to save");
86 }
87 return null;
88 }
89 }