Search in sources :

Example 1 with ChangeLogs

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);
    }
}
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 ChangeLogs

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;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) ChangeLogs(org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) ObligationList(org.eclipse.sw360.datahandler.thrift.projects.ObligationList) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ChangeLogs

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);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ReferenceDocData(org.eclipse.sw360.datahandler.thrift.changelogs.ReferenceDocData) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with ChangeLogs

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;
}
Also used : ChangeLogs(org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs)

Example 5 with 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);
}
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

ChangeLogs (org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs)9 LinkedHashMap (java.util.LinkedHashMap)3 TException (org.apache.thrift.TException)3 Component (org.eclipse.sw360.datahandler.thrift.components.Component)3 Release (org.eclipse.sw360.datahandler.thrift.components.Release)3 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 JSONArray (com.liferay.portal.kernel.json.JSONArray)2 JSONFactoryUtil.createJSONArray (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray)2 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)2 JSONObject (com.liferay.portal.kernel.json.JSONObject)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 CommonUtils.nullToEmptyString (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)2 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)2 ChangedFields (org.eclipse.sw360.datahandler.thrift.changelogs.ChangedFields)2 ReferenceDocData (org.eclipse.sw360.datahandler.thrift.changelogs.ReferenceDocData)2 User (org.eclipse.sw360.datahandler.thrift.users.User)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1