use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs in project sw360 by eclipse.
the class ComponentDatabaseHandler method updateComponentDependentFieldsForRelease.
private void updateComponentDependentFieldsForRelease(Component component, List<ChangeLogs> referenceDocLogList, String userEdited) {
String name = component.getName();
for (Release release : releaseRepository.getReleasesFromComponentId(component.getId())) {
ChangeLogs changeLog = DatabaseHandlerUtil.initChangeLogsObj(release, userEdited, component.getId(), Operation.UPDATE, Operation.COMPONENT_UPDATE);
Set<ChangedFields> changes = new HashSet<ChangedFields>();
ChangedFields nameFields = new ChangedFields();
nameFields.setFieldName("name");
nameFields.setFieldValueOld(DatabaseHandlerUtil.convertObjectToJson(release.getName()));
nameFields.setFieldValueNew(DatabaseHandlerUtil.convertObjectToJson(name));
changes.add(nameFields);
changeLog.setChanges(changes);
release.setName(name);
releaseRepository.update(release);
referenceDocLogList.add(changeLog);
}
}
use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs in project sw360 by eclipse.
the class DatabaseHandlerUtil method initChangeLogsObj.
/**
* Register basic informations for the Document.
*/
public static <T extends TBase<T, ? extends TFieldIdEnum>> ChangeLogs initChangeLogsObj(T newDocVersion, String userEdited, String parentDocId, Operation operation, Operation parentOperation) {
ChangeLogs changeLog = new ChangeLogs();
changeLog.setUserEdited(userEdited);
changeLog.setOperation(operation);
changeLog.setChangeTimestamp(DatabaseHandlerUtil.getTimeStamp());
changeLog.setParentDocId(parentDocId);
Map<String, String> info = new LinkedHashMap<String, String>();
if (newDocVersion instanceof Project) {
Project newProjVer = (Project) newDocVersion;
changeLog.setDocumentId(newProjVer.getId());
changeLog.setDocumentType(newProjVer.getType());
changeLog.setDbName(DatabaseSettings.COUCH_DB_DATABASE);
} else if (newDocVersion instanceof ObligationList) {
ObligationList newProjVer = (ObligationList) newDocVersion;
changeLog.setDocumentId(newProjVer.getId());
changeLog.setDocumentType(newProjVer.getType());
changeLog.setDbName(DatabaseSettings.COUCH_DB_DATABASE);
} else if (newDocVersion instanceof AttachmentContent) {
AttachmentContent newAttachmentContentVer = (AttachmentContent) newDocVersion;
changeLog.setDocumentId(newAttachmentContentVer.getId());
changeLog.setDocumentType(newAttachmentContentVer.getType());
changeLog.setDbName(DatabaseSettings.COUCH_DB_ATTACHMENTS);
info.put(AttachmentContent._Fields.FILENAME.name(), newAttachmentContentVer.getFilename());
info.put(AttachmentContent._Fields.CONTENT_TYPE.name(), newAttachmentContentVer.getContentType());
} else if (newDocVersion instanceof Component) {
Component newProjVer = (Component) newDocVersion;
changeLog.setDocumentId(newProjVer.getId());
changeLog.setDocumentType(newProjVer.getType());
changeLog.setDbName(DatabaseSettings.COUCH_DB_DATABASE);
} else if (newDocVersion instanceof Release) {
Release newProjVer = (Release) newDocVersion;
changeLog.setDocumentId(newProjVer.getId());
changeLog.setDocumentType(newProjVer.getType());
changeLog.setDbName(DatabaseSettings.COUCH_DB_DATABASE);
} else if (newDocVersion instanceof ModerationRequest) {
ModerationRequest newProjVer = (ModerationRequest) newDocVersion;
changeLog.setDocumentId(newProjVer.getId());
changeLog.setDocumentType(newProjVer.getType());
changeLog.setDbName(DatabaseSettings.COUCH_DB_DATABASE);
}
log.info("Initialize ChangeLogs for Document Id : " + changeLog.getDocumentId());
if (parentOperation != null)
info.put("PARENT_OPERATION", parentOperation.name());
if (!info.isEmpty())
changeLog.setInfo(info);
return changeLog;
}
use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs in project sw360 by eclipse.
the class DatabaseHandlerUtil method referenceDocChanges.
/**
* Register Reference Doc changes ad part of Parent Doc update
*/
private static <T extends TBase> void referenceDocChanges(T oldDocVersion, T newDocVersion, String userEdited, List<ChangeLogs> referenceDocLogList, AttachmentConnector attachmentConnector, ChangeLogs changeLogParent) {
if (newDocVersion instanceof Project || newDocVersion instanceof Component || newDocVersion instanceof Release) {
getChangeLogsForAttachments(oldDocVersion, newDocVersion, userEdited, referenceDocLogList, attachmentConnector);
}
Set<ReferenceDocData> referenceDocDataSet = new HashSet<ReferenceDocData>();
referenceDocLogList.stream().forEach(refLog -> {
ReferenceDocData refDocData = new ReferenceDocData();
refDocData.setDbName(refLog.getDbName());
refDocData.setRefDocId(refLog.getDocumentId());
refDocData.setRefDocOperation(refLog.getOperation());
refDocData.setRefDocType(refLog.getDocumentType());
referenceDocDataSet.add(refDocData);
});
changeLogParent.setReferenceDoc(referenceDocDataSet);
}
use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs in project sw360 by eclipse.
the class ChangeLogsDatabaseHandler method getChangeLogsById.
public ChangeLogs getChangeLogsById(String id) throws SW360Exception {
ChangeLogs changeLogs = changeLogsRepository.get(id);
assertNotNull(changeLogs);
removeNullToEmtpyChanges(changeLogs);
changeLogs.setChangeTimestamp(changeLogs.changeTimestamp.split(" ")[0]);
return changeLogs;
}
use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs in project sw360 by eclipse.
the class ChangeLogSpecTest method before.
@Before
public void before() throws TException, IOException {
ChangeLogs changeLog = new ChangeLogs();
changeLog.setId("1234");
changeLog.setDocumentId("4567");
changeLog.setUserEdited("admin@sw360.org");
changeLog.setChangeTimestamp("2021-01-08");
changeLog.setOperation(Operation.UPDATE);
changeLog.setDocumentType("project");
HashSet<ChangedFields> changes = new HashSet<ChangedFields>();
ChangedFields changedFields = new ChangedFields();
changedFields.setFieldName("version");
changedFields.setFieldValueOld("\"2\"");
changedFields.setFieldValueNew("\"25\"");
ChangedFields changedFields1 = new ChangedFields();
changedFields1.setFieldName("name");
changedFields1.setFieldValueOld("\"TestProj\"");
changedFields1.setFieldValueNew("\"TestProject\"");
changes.add(changedFields);
changes.add(changedFields1);
HashSet<ReferenceDocData> referenceDoc = new HashSet<ReferenceDocData>();
ReferenceDocData referenceDocData = new ReferenceDocData();
referenceDocData.setRefDocId("98765");
referenceDocData.setRefDocOperation(Operation.CREATE);
referenceDocData.setRefDocType("attachment");
referenceDoc.add(referenceDocData);
changeLog.setReferenceDoc(referenceDoc);
changeLog.setChanges(changes);
ChangeLogs changeLog2 = new ChangeLogs();
changeLog2.setId("2345");
changeLog2.setDocumentId("56789");
changeLog2.setUserEdited("admin@sw360.org");
changeLog2.setChangeTimestamp("2021-01-08");
changeLog2.setOperation(Operation.CREATE);
changeLog2.setDocumentType("attachment");
changeLog2.setParentDocId("4567");
HashMap<String, String> info = new HashMap<String, String>();
info.put("FILENAME", "abc.xml");
info.put("CONTENT_TYPE", "application/rdf+xml");
info.put("PARENT_OPERATION", "PROJECT_UPDATE");
changeLog2.setInfo(info);
List<ChangeLogs> changeLogs = new ArrayList<ChangeLogs>();
changeLogs.add(changeLog);
changeLogs.add(changeLog2);
given(this.changeLogServiceMock.getChangeLogsByDocumentId(anyObject(), anyObject())).willReturn(changeLogs);
}
Aggregations