Search in sources :

Example 1 with ChangedFields

use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangedFields 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);
    }
}
Also used : ChangeLogs(org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs) ChangedFields(org.eclipse.sw360.datahandler.thrift.changelogs.ChangedFields) Sets.newHashSet(com.google.common.collect.Sets.newHashSet)

Example 2 with ChangedFields

use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangedFields in project sw360 by eclipse.

the class DatabaseHandlerUtil method recordChangesForNeworDeletedDoc.

/**
 * Record changes for Newly created or Deleted Document.
 */
private static <T extends TBase<T, TFieldIdEnum>> void recordChangesForNeworDeletedDoc(TFieldIdEnum[] fields, Set<ChangedFields> changes, T newOrDeletedDoc, boolean isDeletion) {
    Arrays.stream(fields).forEach(field -> {
        Object newOrDeletedValueObj = newOrDeletedDoc.getFieldValue(field);
        if (newOrDeletedValueObj == null || field.getFieldName().equals("type") || field.getFieldName().equals("id") || field.getFieldName().equals("documentState")) {
            return;
        }
        ChangedFields changedField = new ChangedFields();
        changedField.setFieldName(field.getFieldName());
        if (isDeletion) {
            changedField.setFieldValueOld(convertObjectToJson(newOrDeletedValueObj));
        } else {
            changedField.setFieldValueNew(convertObjectToJson(newOrDeletedValueObj));
        }
        changes.add(changedField);
    });
}
Also used : ChangedFields(org.eclipse.sw360.datahandler.thrift.changelogs.ChangedFields)

Example 3 with ChangedFields

use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangedFields in project sw360 by eclipse.

the class DatabaseHandlerUtil method recordChangesForExistingDoc.

/**
 * Record changes for Existing Document.
 */
private static <T extends TBase> void recordChangesForExistingDoc(TFieldIdEnum[] fields, Set<ChangedFields> changes, T newDoc, T oldDoc) {
    log.info("Record Changes For Existing Doc.");
    Arrays.stream(fields).forEach(field -> {
        Object newProjectValueObj = newDoc.getFieldValue(field);
        Object oldProjectValueObj = oldDoc.getFieldValue((TFieldIdEnum) field);
        if (newProjectValueObj == null && oldProjectValueObj == null) {
            return;
        }
        String oldFieldValue = convertObjectToJson(oldProjectValueObj);
        String newFieldValue = convertObjectToJson(newProjectValueObj);
        if (newProjectValueObj != null && oldProjectValueObj != null) {
            if (DatabaseHandlerUtil.isChanged(oldProjectValueObj, newProjectValueObj)) {
                ChangedFields changedField = new ChangedFields();
                changedField.setFieldName(field.getFieldName());
                changedField.setFieldValueOld(oldFieldValue);
                changedField.setFieldValueNew(newFieldValue);
                changes.add(changedField);
            }
        } else {
            ChangedFields changedField = new ChangedFields();
            changedField.setFieldName(field.getFieldName());
            if (oldProjectValueObj != null) {
                changedField.setFieldValueOld(oldFieldValue);
            }
            if (newProjectValueObj != null) {
                changedField.setFieldValueNew(newProjectValueObj == null ? null : newFieldValue);
            }
            changes.add(changedField);
        }
    });
}
Also used : ChangedFields(org.eclipse.sw360.datahandler.thrift.changelogs.ChangedFields)

Example 4 with ChangedFields

use of org.eclipse.sw360.datahandler.thrift.changelogs.ChangedFields 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);
}
Also used : ChangeLogs(org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs) HashMap(java.util.HashMap) ReferenceDocData(org.eclipse.sw360.datahandler.thrift.changelogs.ReferenceDocData) ChangedFields(org.eclipse.sw360.datahandler.thrift.changelogs.ChangedFields) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

ChangedFields (org.eclipse.sw360.datahandler.thrift.changelogs.ChangedFields)4 ChangeLogs (org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ReferenceDocData (org.eclipse.sw360.datahandler.thrift.changelogs.ReferenceDocData)1 Before (org.junit.Before)1