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